当前位置: 首页>>代码示例>>Java>>正文


Java Executable类代码示例

本文整理汇总了Java中java.lang.reflect.Executable的典型用法代码示例。如果您正苦于以下问题:Java Executable类的具体用法?Java Executable怎么用?Java Executable使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Executable类属于java.lang.reflect包,在下文中一共展示了Executable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: generateRandomDescriptor

import java.lang.reflect.Executable; //导入依赖的package包/类
/**
 * Generates random method descriptor
 *
 * @param executable executable used to generate descriptor
 * @return MethodDescriptor instance
 */
public MethodDescriptor generateRandomDescriptor(Executable executable) {
    Combination<PatternType> patterns =
            Utils.getRandomElement(PATTERNS_LIST);
    Combination<Separator> separators =
            Utils.getRandomElement(SEPARATORS_LIST);
    // Create simple mutators for signature generation
    List<Function<String, String>> signMutators = new ArrayList<>();
    signMutators.add(input -> input);
    signMutators.add(input -> "");
    Combination<Function<String, String>> mutators = new Combination<>(
            Utils.getRandomElement(ELEMENT_MUTATORS),
            Utils.getRandomElement(ELEMENT_MUTATORS),
            // use only this type of mutators
            Utils.getRandomElement(signMutators));
    return makeMethodDescriptor(executable, patterns,
            separators, mutators);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:24,代码来源:MethodGenerator.java

示例2: waitBackgroundCompilation

import java.lang.reflect.Executable; //导入依赖的package包/类
/**
 * Waits for completion of background compilation of the given executable.
 *
 * @param executable Executable
 */
public static final void waitBackgroundCompilation(Executable executable) {
    if (!BACKGROUND_COMPILATION) {
        return;
    }
    final Object obj = new Object();
    for (int i = 0; i < 100
            && WHITE_BOX.isMethodQueuedForCompilation(executable); ++i) {
        synchronized (obj) {
            try {
                obj.wait(100);
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            }
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:CompilerWhiteBoxTest.java

示例3: ClassVisitorForLabels

import java.lang.reflect.Executable; //导入依赖的package包/类
public ClassVisitorForLabels(ClassWriter cw, Map<Label, Integer> lines,
                             Executable target) {
    super(Opcodes.ASM5, cw);
    this.lineNumbers = lines;

    StringBuilder builder = new StringBuilder("(");
    for (Parameter parameter : target.getParameters()) {
        builder.append(Utils.toJVMTypeSignature(parameter.getType()));
    }
    builder.append(")");
    if (target instanceof Constructor) {
        targetName = "<init>";
        builder.append("V");
    } else {
        targetName = target.getName();
        builder.append(Utils.toJVMTypeSignature(
                ((Method) target).getReturnType()));
    }
    targetDesc = builder.toString();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:CTVMUtilities.java

示例4: getParameterNames

import java.lang.reflect.Executable; //导入依赖的package包/类
private static List<String> getParameterNames(Executable executable)
{
    requireNonNull(executable, "executable is null");

    if (executable.getParameterCount() == 0) {
        return emptyList();
    }

    // first try to get the parameter names from the ThriftField annotations
    List<Optional<String>> parameterNamesFromThriftField = Arrays.stream(executable.getParameters())
            .map(ReflectionHelper::getThriftFieldParameterName)
            .collect(toImmutableList());
    if (parameterNamesFromThriftField.stream().allMatch(Optional::isPresent)) {
        return parameterNamesFromThriftField.stream()
                .map(Optional::get)
                .collect(toImmutableList());
    }

    // otherwise get the parameter names from the class, but use any ThriftField annotations as overrides
    List<String> parameterNamesFromClass = ParameterNames.getParameterNames(executable);
    ImmutableList.Builder<String> parameterNames = ImmutableList.builder();
    for (int i = 0; i < parameterNamesFromThriftField.size(); i++) {
        parameterNames.add(parameterNamesFromThriftField.get(i).orElse(parameterNamesFromClass.get(i)));
    }
    return parameterNames.build();
}
 
开发者ID:airlift,项目名称:drift,代码行数:27,代码来源:ReflectionHelper.java

示例5: assertPublicThrows

import java.lang.reflect.Executable; //导入依赖的package包/类
public static void assertPublicThrows(Executable method, Class<?>... exceptions) {
    Members.assertPublic(method);

    for(Class<?> ex : method.getExceptionTypes()) {
        if(!RuntimeException.class.isAssignableFrom(ex)) {
            boolean found = false;
            for(Class<?> allowed : exceptions) {
                if(allowed.isAssignableFrom(ex)) {
                    found = true;
                    break;
                }
            }
            if(!found) {
                Members.error(method, "throws unhandled exception " + ex.getName());
            }
        }
    }
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:19,代码来源:Methods.java

示例6: checkIntrinsicForCompilationLevel

import java.lang.reflect.Executable; //导入依赖的package包/类
protected void checkIntrinsicForCompilationLevel(Executable method, int compLevel) throws Exception {
    boolean intrinsicEnabled = Boolean.valueOf(getVMOption("UseCRC32Intrinsics"));
    boolean intrinsicAvailable = WHITE_BOX.isIntrinsicAvailable(method,
                                                                compLevel);

    String intrinsicEnabledMessage = intrinsicEnabled ? "enabled" : "disabled";
    String intrinsicAvailableMessage = intrinsicAvailable ? "available" : "not available";

    if (intrinsicEnabled == intrinsicAvailable) {
        System.out.println("Expected result: intrinsic for java.util.zip.CRC32.update() is " +
                           intrinsicEnabledMessage + " and intrinsic is " + intrinsicAvailableMessage +
                           " at compilation level " + compLevel);
    } else {
        throw new RuntimeException("Unexpected result: intrinsic for java.util.zip.CRC32.update() is " +
                                   intrinsicEnabledMessage + " but intrinsic is " + intrinsicAvailableMessage +
                                   " at compilation level " + compLevel);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:IntrinsicAvailableTest.java

示例7: lookupMethod

import java.lang.reflect.Executable; //导入依赖的package包/类
private static Method lookupMethod(String name) {
    Method method = null;

    Method[] methods = Executable.class.getDeclaredMethods();
    for(Method tmp : methods) {
        if (tmp.getName().equals(name)) {
            method = tmp;
            break;
        }
    }

    if (method == null) {
        throw new InjectorException("Required method (Executable." + name + ") does not exists");
    }

    method.setAccessible(true);

    return method;
}
 
开发者ID:siy,项目名称:booter-injector,代码行数:20,代码来源:LambdaFactory.java

示例8: test

import java.lang.reflect.Executable; //导入依赖的package包/类
@Override
public void test() {
    Scenario.Builder builder = Scenario.getBuilder();
    // Add some commands with JCMD
    for (int i = 0; i < AMOUNT; i++) {
        Executable exec = Utils.getRandomElement(METHODS).first;
        MethodDescriptor md = getValidMethodDescriptor(exec);
        CompileCommand compileCommand = new JcmdCommand(Command.COMPILEONLY,
                md, null, Scenario.Type.JCMD, Scenario.JcmdType.ADD);
        compileCommand.print();
        builder.add(compileCommand);
    }
    // Remove half of them
    for (int i = 0; i < AMOUNT / 2; i++) {
        /* remove jcmd command doesn't need method, compiler etc.
           command will be ignored */
        builder.add(new JcmdCommand(Command.NONEXISTENT, null, null,
                Scenario.Type.JCMD, Scenario.JcmdType.REMOVE));
    }
    Scenario scenario = builder.build();
    scenario.execute();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:AddAndRemoveTest.java

示例9: toJava

import java.lang.reflect.Executable; //导入依赖的package包/类
private Executable toJava() {
    if (toJavaCache != null) {
        return toJavaCache;
    }
    try {
        Class<?>[] parameterTypes = signatureToTypes();
        Class<?> returnType = ((HotSpotResolvedJavaType) getSignature().getReturnType(holder).resolve(holder)).mirror();

        Executable result;
        if (isConstructor()) {
            result = holder.mirror().getDeclaredConstructor(parameterTypes);
        } else {
            // Do not use Method.getDeclaredMethod() as it can return a bridge method
            // when this.isBridge() is false and vice versa.
            result = searchMethods(holder.mirror().getDeclaredMethods(), getName(), returnType, parameterTypes);
        }
        toJavaCache = result;
        return result;
    } catch (NoSuchMethodException | NoClassDefFoundError e) {
        return null;
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:HotSpotResolvedJavaMethodImpl.java

示例10: test

import java.lang.reflect.Executable; //导入依赖的package包/类
@Override
public void test() {
    Scenario.Builder builder = Scenario.getBuilder();
    // Add some commands with directives file
    for (int i = 0; i < AMOUNT; i++) {
        Executable exec = Utils.getRandomElement(METHODS).first;
        MethodDescriptor methodDescriptor = getValidMethodDescriptor(exec);
        Command command = cmdGen.generateCommand();
        if (command == Command.NONEXISTENT) {
            // skip invalid command
            command = Command.COMPILEONLY;
        }
        CompileCommand compileCommand = new CompileCommand(command,
                methodDescriptor, cmdGen.generateCompiler(),
                Scenario.Type.DIRECTIVE);
        compileCommand.print();
        builder.add(compileCommand);
    }
    // print all directives
    builder.add(new JcmdCommand(Command.NONEXISTENT, null, null,
            Scenario.Type.JCMD, Scenario.JcmdType.PRINT));
    Scenario scenario = builder.build();
    scenario.execute();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:25,代码来源:PrintDirectivesTest.java

示例11: generateRandomTest

import java.lang.reflect.Executable; //导入依赖的package包/类
/**
 * Generates a test containing multiple random commands
 *
 * @param validOnly shows that all commands should be valid
 * @return test instance to run
 */
public static AbstractTestBase generateRandomTest(boolean validOnly) {
    CommandGenerator cmdGen = new CommandGenerator();
    List<Command> commands = cmdGen.generateCommands();
    List<CompileCommand> testCases = new ArrayList<>();
    for (Command cmd : commands) {
        if (validOnly && cmd == Command.NONEXISTENT) {
            // replace with a valid command
            cmd = Command.EXCLUDE;
        }
        Executable exec = Utils.getRandomElement(METHODS).first;
        MethodDescriptor md;
        if (validOnly) {
            md = AbstractTestBase.getValidMethodDescriptor(exec);
        } else {
            md = AbstractTestBase.METHOD_GEN.generateRandomDescriptor(exec);
        }
        CompileCommand cc = cmdGen.generateCompileCommand(cmd, md, null);
        testCases.add(cc);
    }
    return new MultiCommand(testCases);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:28,代码来源:MultiCommand.java

示例12: test

import java.lang.reflect.Executable; //导入依赖的package包/类
@Override
public void test() {
    Scenario.Builder builder = Scenario.getBuilder();
    // Add some commands with JCMD
    for (int i = 0; i < AMOUNT; i++) {
        Executable exec = Utils.getRandomElement(METHODS).first;
        MethodDescriptor methodDescriptor = getValidMethodDescriptor(exec);
        CompileCommand compileCommand = new JcmdCommand(
                cmdGen.generateCommand(), methodDescriptor,
                cmdGen.generateCompiler(), Scenario.Type.JCMD,
                Scenario.JcmdType.ADD);
        compileCommand.print();
        builder.add(compileCommand);
    }
    // clear the stack
    builder.add(new JcmdCommand(Command.NONEXISTENT, null, null,
            Scenario.Type.JCMD, Scenario.JcmdType.CLEAR));
    // print all directives after the clear
    builder.add(new JcmdCommand(Command.NONEXISTENT, null, null,
            Scenario.Type.JCMD, Scenario.JcmdType.PRINT));
    Scenario scenario = builder.build();
    scenario.execute();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:24,代码来源:ClearDirectivesStackTest.java

示例13: createTestCases

import java.lang.reflect.Executable; //导入依赖的package包/类
private static Map<Executable, int[]> createTestCases() {
    Map<Executable, int[]> testCases = new HashMap<>();

    try {
        Class<?> aClass = DummyClass.class;
        Method aMethod = aClass.getDeclaredMethod("dummyInstanceFunction");
        int[] bci = new int[] {0, 2, 3, 6, 7, 8, 11, 13, 15, 16, 17, 18};
        testCases.put(aMethod, bci);

        aMethod = aClass.getDeclaredMethod("dummyEmptyFunction");
        bci = new int[] {0};
        testCases.put(aMethod, bci);

        aMethod = aClass.getDeclaredMethod("nativeFunction");
        bci = new int[] {0};
        testCases.put(aMethod, bci);

        TestCase.getAllExecutables()
                .forEach(c -> testCases.put(c, new int[] {0}));
    } catch (NoSuchMethodException e) {
        throw new Error("TEST BUG : test method not found", e);
    }
    return testCases;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:25,代码来源:GetStackTraceElementTest.java

示例14: decodeMap

import java.lang.reflect.Executable; //导入依赖的package包/类
private Map<Executable, State> decodeMap(List<String> lines) {
    if (lines == null || lines.size() == 0) {
        throw new Error("TESTBUG: unexpected lines list");
    }
    Map<Executable, State> stateMap = new HashMap<>();
    int startIndex = 0;
    ListIterator<String> iterator = lines.listIterator();
    while (iterator.hasNext()) {
        int index = iterator.nextIndex();
        String next = iterator.next();
        switch (next) {
            case "{" :
                startIndex = index;
                break;
            case "}" :
                // method name goes after {
                Executable executable = METHODS_NAMES.get(lines.get(
                        ++startIndex));
                // state description starts after method
                State state = State.fromString(lines.subList(++startIndex,
                        index).toArray(new String[index - startIndex]));
                stateMap.put(executable, state);
                break;
        }
    }
    return stateMap;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:28,代码来源:BaseAction.java

示例15: getExecutable

import java.lang.reflect.Executable; //导入依赖的package包/类
@Override
public Executable getExecutable() {
    try {
        return getClass().getDeclaredMethod("execMathMethod");
    } catch (NoSuchMethodException e) {
        throw new RuntimeException("Test bug, no such method: " + e);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:9,代码来源:MathIntrinsic.java


注:本文中的java.lang.reflect.Executable类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。