當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。