Search in sources :

Example 16 with Executable

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

the class AnnotationSubstitutionProcessor method handleDeletedClass.

private void handleDeletedClass(Class<?> originalClass, Delete deleteAnnotation) {
    if (NativeImageOptions.ReportUnsupportedElementsAtRuntime.getValue()) {
        /*
             * We register all methods and fields as deleted. That still allows usage of the type in
             * type checks.
             */
        for (Executable m : originalClass.getDeclaredMethods()) {
            ResolvedJavaMethod method = metaAccess.lookupJavaMethod(m);
            registerAsDeleted(null, method, deleteAnnotation);
        }
        for (Executable m : originalClass.getDeclaredConstructors()) {
            ResolvedJavaMethod method = metaAccess.lookupJavaMethod(m);
            registerAsDeleted(null, method, deleteAnnotation);
        }
        for (Field f : originalClass.getDeclaredFields()) {
            ResolvedJavaField field = metaAccess.lookupJavaField(f);
            registerAsDeleted(null, field, deleteAnnotation);
        }
    } else {
        deleteAnnotations.put(metaAccess.lookupJavaType(originalClass), deleteAnnotation);
    }
}
Also used : ResolvedJavaField(jdk.vm.ci.meta.ResolvedJavaField) Field(java.lang.reflect.Field) AnalysisField(com.oracle.graal.pointsto.meta.AnalysisField) Executable(java.lang.reflect.Executable) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) ResolvedJavaField(jdk.vm.ci.meta.ResolvedJavaField)

Example 17 with Executable

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

the class JNIFunctions method FromReflectedMethod.

/*
     * jmethodID FromReflectedMethod(JNIEnv *env, jobject method);
     */
@CEntryPoint
@CEntryPointOptions(prologue = JNIEnvironmentEnterPrologue.class, exceptionHandler = JNIExceptionHandlerReturnNullWord.class, publishAs = Publish.NotPublished, include = CEntryPointOptions.NotIncludedAutomatically.class)
static JNIMethodId FromReflectedMethod(JNIEnvironment env, JNIObjectHandle methodHandle) {
    JNIMethodId methodId = Word.nullPointer();
    if (JNIAccessFeature.singleton().haveJavaRuntimeReflectionSupport()) {
        Executable method = JNIObjectHandles.getObject(methodHandle);
        if (method != null) {
            boolean isStatic = Modifier.isStatic(method.getModifiers());
            JNIAccessibleMethodDescriptor descriptor = JNIAccessibleMethodDescriptor.of(method);
            methodId = JNIReflectionDictionary.singleton().getMethodID(method.getDeclaringClass(), descriptor, isStatic);
        }
    }
    return methodId;
}
Also used : JNIAccessibleMethodDescriptor(com.oracle.svm.jni.access.JNIAccessibleMethodDescriptor) Executable(java.lang.reflect.Executable) JNIMethodId(com.oracle.svm.jni.nativeapi.JNIMethodId) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) CEntryPointOptions(com.oracle.svm.core.c.function.CEntryPointOptions)

Example 18 with Executable

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

the class ReflectionConfigurationParser method parseMethod.

private void parseMethod(Map<String, Object> data, Class<?> clazz) {
    String methodName = null;
    Class<?>[] methodParameterTypes = null;
    for (Map.Entry<String, Object> entry : data.entrySet()) {
        String propertyName = entry.getKey();
        if (propertyName.equals("name")) {
            methodName = asString(entry.getValue(), "name");
        } else if (propertyName.equals("parameterTypes")) {
            methodParameterTypes = parseTypes(asList(entry.getValue(), "Attribute 'parameterTypes' must be a list of type names"));
        } else {
            throw new JSONParserException("Unknown attribute '" + propertyName + "' (supported attributes: 'name', 'parameterTypes') in definition of method for class '" + clazz.getTypeName() + "'");
        }
    }
    if (methodName == null) {
        throw new JSONParserException("Missing attribute 'name' in definition of method for class '" + clazz.getTypeName() + "'");
    }
    if (methodParameterTypes != null) {
        try {
            Executable method;
            if (CONSTRUCTOR_NAME.equals(methodName)) {
                method = clazz.getDeclaredConstructor(methodParameterTypes);
            } else {
                method = clazz.getDeclaredMethod(methodName, methodParameterTypes);
            }
            registry.register(method);
        } catch (NoSuchMethodException e) {
            String parameterTypeNames = Stream.of(methodParameterTypes).map(Class::getSimpleName).collect(Collectors.joining(", "));
            throw new JSONParserException("Method " + clazz.getTypeName() + "." + methodName + "(" + parameterTypeNames + ") not found");
        }
    } else {
        boolean found = false;
        boolean isConstructor = CONSTRUCTOR_NAME.equals(methodName);
        Executable[] methods = isConstructor ? clazz.getDeclaredConstructors() : clazz.getDeclaredMethods();
        for (Executable method : methods) {
            if (isConstructor || method.getName().equals(methodName)) {
                registry.register(method);
                found = true;
            }
        }
        if (!found) {
            throw new JSONParserException("Method " + clazz.getTypeName() + "." + methodName + " not found");
        }
    }
}
Also used : JSONParserException(com.oracle.svm.hosted.json.JSONParserException) Executable(java.lang.reflect.Executable) Map(java.util.Map)

Example 19 with Executable

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

the class GraalCompilerTest method invoke.

protected Object invoke(ResolvedJavaMethod javaMethod, Object receiver, Object... args) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException {
    Executable method = lookupMethod(javaMethod);
    Assert.assertTrue(method != null);
    if (!method.isAccessible()) {
        method.setAccessible(true);
    }
    if (method instanceof Method) {
        return ((Method) method).invoke(receiver, applyArgSuppliers(args));
    }
    assert receiver == null : "no receiver for constructor invokes";
    return ((Constructor<?>) method).newInstance(applyArgSuppliers(args));
}
Also used : Constructor(java.lang.reflect.Constructor) Method(java.lang.reflect.Method) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) Executable(java.lang.reflect.Executable)

Example 20 with Executable

use of java.lang.reflect.Executable in project openj9 by eclipse.

the class TypeAnnotatedTestClassTest method testMethodAnnotations.

@Test
public void testMethodAnnotations() {
    Class<?> c = typeAnnotatedClass;
    initializeReturnTypeAnnotations();
    initializeReceiverTypeAnnotations();
    initializeExceptionTypeAnnotations();
    initializeParameterTypeAnnotations();
    Executable[] executables = c.getDeclaredMethods();
    for (Executable e : executables) {
        String execName = e.getName();
        if (verbose) {
            logger.debug("checking method " + execName);
        }
        checkAnnotations(e.getAnnotatedReturnType(), ANNOTATION_NAME, ANNOTATION_ARG_NAME, returnTypeAnnotations.get(execName));
        AnnotatedType annotatedReceiverType = e.getAnnotatedReceiverType();
        checkAnnotations(annotatedReceiverType, ANNOTATION_NAME, ANNOTATION_ARG_NAME, receiverTypeAnnotations.get(execName));
        checkAnnotations(e.getAnnotatedExceptionTypes(), ANNOTATION_NAME, ANNOTATION_ARG_NAME, exceptionTypeAnnotations.get(execName));
        checkAnnotations(e.getAnnotatedParameterTypes(), ANNOTATION_NAME, ANNOTATION_ARG_NAME, parameterTypeAnnotations.get(execName));
    }
}
Also used : AnnotatedType(java.lang.reflect.AnnotatedType) Executable(java.lang.reflect.Executable) Test(org.testng.annotations.Test)

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