Search in sources :

Example 6 with Executable

use of java.lang.reflect.Executable in project junit5 by junit-team.

the class ExecutableInvoker method resolveParameter.

private Object resolveParameter(ParameterContext parameterContext, Executable executable, ExtensionContext extensionContext, ExtensionRegistry extensionRegistry) {
    try {
        // @formatter:off
        List<ParameterResolver> matchingResolvers = extensionRegistry.stream(ParameterResolver.class).filter(resolver -> resolver.supportsParameter(parameterContext, extensionContext)).collect(toList());
        if (matchingResolvers.isEmpty()) {
            throw new ParameterResolutionException(String.format("No ParameterResolver registered for parameter [%s] in executable [%s].", parameterContext.getParameter(), executable.toGenericString()));
        }
        if (matchingResolvers.size() > 1) {
            // @formatter:off
            String resolverNames = matchingResolvers.stream().map(resolver -> resolver.getClass().getName()).collect(joining(", "));
            // @formatter:on
            throw new ParameterResolutionException(String.format("Discovered multiple competing ParameterResolvers for parameter [%s] in executable [%s]: %s", parameterContext.getParameter(), executable.toGenericString(), resolverNames));
        }
        ParameterResolver resolver = matchingResolvers.get(0);
        Object value = resolver.resolveParameter(parameterContext, extensionContext);
        validateResolvedType(parameterContext.getParameter(), value, executable, resolver);
        logger.trace(() -> String.format("ParameterResolver [%s] resolved a value of type [%s] for parameter [%s] in executable [%s].", resolver.getClass().getName(), (value != null ? value.getClass().getName() : null), parameterContext.getParameter(), executable.toGenericString()));
        return value;
    } catch (ParameterResolutionException ex) {
        throw ex;
    } catch (Throwable ex) {
        throw new ParameterResolutionException(String.format("Failed to resolve parameter [%s] in executable [%s]", parameterContext.getParameter(), executable.toGenericString()), ex);
    }
}
Also used : ParameterResolver(org.junit.jupiter.api.extension.ParameterResolver) Preconditions(org.junit.platform.commons.util.Preconditions) ReflectionUtils.isAssignableTo(org.junit.platform.commons.util.ReflectionUtils.isAssignableTo) Logger(org.junit.platform.commons.logging.Logger) ParameterResolutionException(org.junit.jupiter.api.extension.ParameterResolutionException) API(org.apiguardian.api.API) ExtensionContext(org.junit.jupiter.api.extension.ExtensionContext) INTERNAL(org.apiguardian.api.API.Status.INTERNAL) Constructor(java.lang.reflect.Constructor) ReflectionUtils(org.junit.platform.commons.util.ReflectionUtils) Collectors.joining(java.util.stream.Collectors.joining) LoggerFactory(org.junit.platform.commons.logging.LoggerFactory) ParameterContext(org.junit.jupiter.api.extension.ParameterContext) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) ExtensionRegistry(org.junit.jupiter.engine.extension.ExtensionRegistry) Parameter(java.lang.reflect.Parameter) Executable(java.lang.reflect.Executable) Optional(java.util.Optional) Method(java.lang.reflect.Method) ParameterResolver(org.junit.jupiter.api.extension.ParameterResolver) ParameterResolutionException(org.junit.jupiter.api.extension.ParameterResolutionException)

Example 7 with Executable

use of java.lang.reflect.Executable in project SilverKing by Morgan-Stanley.

the class JNIUtil method getReferencedClasses.

public static <E extends Executable> Set<Class> getReferencedClasses(E[] ea) {
    Set<Class> s;
    s = new HashSet<>();
    for (Executable e : ea) {
        s.addAll(getReferencedClasses(e));
    }
    return s;
}
Also used : Executable(java.lang.reflect.Executable)

Example 8 with Executable

use of java.lang.reflect.Executable in project SilverKing by Morgan-Stanley.

the class JNIUtil method main.

public static void main(String[] args) {
    // System.out.println(CollectionUtil.toString(getReferencedClasses(GetOptions.class)));
    for (Executable e : GetOptions.class.getDeclaredMethods()) {
        System.out.println(e);
    }
    System.out.println();
    System.out.println();
    for (Executable e : GetOptions.class.getMethods()) {
        System.out.println(e);
    }
}
Also used : Executable(java.lang.reflect.Executable)

Example 9 with Executable

use of java.lang.reflect.Executable in project graal by oracle.

the class JNIFunctions method ToReflectedMethod.

/*
     * jobject ToReflectedMethod(JNIEnv *env, jclass cls, jmethodID methodID, jboolean isStatic);
     */
@CEntryPoint
@CEntryPointOptions(prologue = JNIEnvironmentEnterPrologue.class, exceptionHandler = JNIExceptionHandlerReturnNullHandle.class, publishAs = Publish.NotPublished, include = CEntryPointOptions.NotIncludedAutomatically.class)
static JNIObjectHandle ToReflectedMethod(JNIEnvironment env, JNIObjectHandle classHandle, JNIMethodId methodId, boolean isStatic) {
    Executable result = null;
    if (JNIAccessFeature.singleton().haveJavaRuntimeReflectionSupport()) {
        JNIAccessibleMethod jniMethod = JNIReflectionDictionary.getMethodByID(methodId);
        JNIAccessibleMethodDescriptor descriptor = JNIReflectionDictionary.getMethodDescriptor(jniMethod);
        if (descriptor != null) {
            Class<?> clazz = jniMethod.getDeclaringClass().getClassObject();
            if (descriptor.isConstructor()) {
                for (Constructor<?> ctor : clazz.getDeclaredConstructors()) {
                    if (descriptor.equals(JNIAccessibleMethodDescriptor.of(ctor))) {
                        result = ctor;
                        break;
                    }
                }
            } else {
                for (Method method : clazz.getDeclaredMethods()) {
                    if (descriptor.getName().equals(method.getName())) {
                        if (descriptor.equals(JNIAccessibleMethodDescriptor.of(method))) {
                            result = method;
                            break;
                        }
                    }
                }
            }
        }
    }
    return JNIThreadLocalHandles.get().create(result);
}
Also used : JNIAccessibleMethodDescriptor(com.oracle.svm.jni.access.JNIAccessibleMethodDescriptor) JNIAccessibleMethod(com.oracle.svm.jni.access.JNIAccessibleMethod) JNIAccessibleMethod(com.oracle.svm.jni.access.JNIAccessibleMethod) Method(java.lang.reflect.Method) JNINativeMethod(com.oracle.svm.jni.nativeapi.JNINativeMethod) Executable(java.lang.reflect.Executable) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) CEntryPointOptions(com.oracle.svm.core.c.function.CEntryPointOptions)

Example 10 with Executable

use of java.lang.reflect.Executable in project graal by oracle.

the class JNIAccessFeature method duringAnalysis.

@Override
public void duringAnalysis(DuringAnalysisAccess a) {
    DuringAnalysisAccessImpl access = (DuringAnalysisAccessImpl) a;
    if (!wereElementsAdded()) {
        return;
    }
    for (Class<?> clazz : newClasses) {
        addClass(clazz, access);
    }
    newClasses.clear();
    for (Executable method : newMethods) {
        addMethod(method, access);
    }
    newMethods.clear();
    for (Field field : newFields) {
        addField(field, access);
    }
    newFields.clear();
    JNIReflectionDictionary.singleton().addLinkages(newLinkages);
    newLinkages.clear();
    access.requireAnalysisIteration();
}
Also used : ResolvedJavaField(jdk.vm.ci.meta.ResolvedJavaField) Field(java.lang.reflect.Field) AnalysisField(com.oracle.graal.pointsto.meta.AnalysisField) DuringAnalysisAccessImpl(com.oracle.svm.hosted.FeatureImpl.DuringAnalysisAccessImpl) Executable(java.lang.reflect.Executable)

Aggregations

Executable (java.lang.reflect.Executable)39 Method (java.lang.reflect.Method)14 Constructor (java.lang.reflect.Constructor)9 Parameter (java.lang.reflect.Parameter)8 Field (java.lang.reflect.Field)6 Member (java.lang.reflect.Member)5 Annotation (java.lang.annotation.Annotation)4 List (java.util.List)4 AnalysisField (com.oracle.graal.pointsto.meta.AnalysisField)2 CEntryPointOptions (com.oracle.svm.core.c.function.CEntryPointOptions)2 JNIAccessibleMethodDescriptor (com.oracle.svm.jni.access.JNIAccessibleMethodDescriptor)2 AnnotatedType (java.lang.reflect.AnnotatedType)2 TypeVariable (java.lang.reflect.TypeVariable)2 Arrays (java.util.Arrays)2 HashSet (java.util.HashSet)2 Nullable (javax.annotation.Nullable)2 AnnotatedParameter (javax.enterprise.inject.spi.AnnotatedParameter)2 Named (javax.inject.Named)2 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2