Search in sources :

Example 11 with Executable

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

the class FieldDescriptor method loadFile.

private void loadFile(Reader reader) throws IOException {
    Set<Class<?>> annotatedClasses = new HashSet<>(imageClassLoader.findAnnotatedClasses(TargetClass.class));
    JSONParser parser = new JSONParser(reader);
    @SuppressWarnings("unchecked") List<Object> allDescriptors = (List<Object>) parser.parse();
    for (Object classDescriptorData : allDescriptors) {
        if (classDescriptorData == null) {
            /* Empty or trailing array elements are parsed to null. */
            continue;
        }
        ClassDescriptor classDescriptor = new ClassDescriptor(classDescriptorData);
        Class<?> annotatedClass = imageClassLoader.findClassByName(classDescriptor.annotatedClass());
        if (annotatedClasses.contains(annotatedClass)) {
            throw UserError.abort("target class already registered using explicit @TargetClass annotation: " + annotatedClass);
        } else if (classDescriptors.containsKey(annotatedClass)) {
            throw UserError.abort("target class already registered using substitution file: " + annotatedClass);
        }
        classDescriptors.put(annotatedClass, classDescriptor);
        for (Object methodDescriptorData : classDescriptor.methods()) {
            if (methodDescriptorData == null) {
                /* Empty or trailing array elements are parsed to null. */
                continue;
            }
            MethodDescriptor methodDescriptor = new MethodDescriptor(methodDescriptorData);
            Executable annotatedMethod;
            if (methodDescriptor.parameterTypes() != null) {
                annotatedMethod = findMethod(annotatedClass, methodDescriptor.annotatedName(), methodDescriptor.parameterTypes());
            } else {
                annotatedMethod = findMethod(annotatedClass, methodDescriptor.annotatedName(), true);
            }
            methodDescriptors.put(annotatedMethod, methodDescriptor);
        }
        for (Object fieldDescriptorData : classDescriptor.fields()) {
            FieldDescriptor fieldDescriptor = new FieldDescriptor(fieldDescriptorData);
            Field annotatedField = findField(annotatedClass, fieldDescriptor.annotatedName());
            fieldDescriptors.put(annotatedField, fieldDescriptor);
        }
    }
}
Also used : Field(java.lang.reflect.Field) TargetClass(com.oracle.svm.core.annotate.TargetClass) JSONParser(com.oracle.svm.hosted.json.JSONParser) List(java.util.List) TargetClass(com.oracle.svm.core.annotate.TargetClass) Executable(java.lang.reflect.Executable) HashSet(java.util.HashSet)

Example 12 with Executable

use of java.lang.reflect.Executable in project tutorials by eugenp.

the class MethodParameterFactory method createMethodParameter.

public static MethodParameter createMethodParameter(Parameter parameter) {
    Assert.notNull(parameter, "Parameter must not be null");
    Executable executable = parameter.getDeclaringExecutable();
    if (executable instanceof Method) {
        return new MethodParameter((Method) executable, getIndex(parameter));
    }
    return new MethodParameter((Constructor<?>) executable, getIndex(parameter));
}
Also used : Method(java.lang.reflect.Method) Executable(java.lang.reflect.Executable) MethodParameter(org.springframework.core.MethodParameter) SynthesizingMethodParameter(org.springframework.core.annotation.SynthesizingMethodParameter)

Example 13 with Executable

use of java.lang.reflect.Executable in project kalang by kasonyang.

the class JvmClassNode method getDeclaredMethodNodes.

@Override
public MethodNode[] getDeclaredMethodNodes() {
    if (!this.methodsInitialized) {
        this.methodsInitialized = true;
        List<Executable> methods = new LinkedList();
        methods.addAll(Arrays.asList(clazz.getDeclaredMethods()));
        methods.addAll(Arrays.asList(clazz.getDeclaredConstructors()));
        for (Executable m : methods) {
            NullableKind nullable = getNullable(m.getAnnotations());
            Type mType;
            String mName;
            int mModifier;
            if (m instanceof Method) {
                mType = getType(((Method) m).getGenericReturnType(), getGenericTypeMap(), ((Method) m).getReturnType(), nullable);
                mName = m.getName();
                mModifier = m.getModifiers();
            } else if (m instanceof Constructor) {
                mName = "<init>";
                // getType(clz);
                mType = Types.VOID_TYPE;
                // | Modifier.STATIC;
                mModifier = m.getModifiers();
            } else {
                throw Exceptions.unexceptedValue(m);
            }
            MethodNode methodNode = createMethodNode(mType, mName, mModifier);
            for (Parameter p : m.getParameters()) {
                NullableKind pnullable = getNullable(p.getAnnotations());
                methodNode.createParameter(getType(p.getParameterizedType(), getGenericTypeMap(), p.getType(), pnullable), p.getName());
            }
            for (Class e : m.getExceptionTypes()) {
                methodNode.addExceptionType(getType(e, getGenericTypeMap(), e, NullableKind.NONNULL));
            }
        }
    }
    return super.getDeclaredMethodNodes();
}
Also used : GenericArrayType(java.lang.reflect.GenericArrayType) Type(kalang.core.Type) ObjectType(kalang.core.ObjectType) GenericType(kalang.core.GenericType) WildcardType(kalang.core.WildcardType) ClassType(kalang.core.ClassType) MethodNode(kalang.ast.MethodNode) NullableKind(kalang.core.NullableKind) Constructor(java.lang.reflect.Constructor) Parameter(java.lang.reflect.Parameter) Method(java.lang.reflect.Method) Executable(java.lang.reflect.Executable) LinkedList(java.util.LinkedList)

Example 14 with Executable

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

the class TypeAnnotatedTestClassTest method testMethodTypeBoundAnnotations.

@Test
public void testMethodTypeBoundAnnotations() {
    initializeMethodTypeBoundAnnotations();
    initializeMethodGenericAnnotations();
    for (Executable e : typeAnnotatedClass.getDeclaredMethods()) {
        for (@SuppressWarnings("rawtypes") TypeVariable tv : e.getTypeParameters()) {
            checkAnnotations(tv, ANNOTATION_NAME, ANNOTATION_ARG_NAME, methodGenericAnnotations.get(tv.getName()));
            for (AnnotatedType b : tv.getAnnotatedBounds()) {
                checkAnnotations(b, ANNOTATION_NAME, ANNOTATION_ARG_NAME, methodTypeBoundAnnotations.get(b.getType().getTypeName()));
            }
        }
    }
}
Also used : AnnotatedType(java.lang.reflect.AnnotatedType) TypeVariable(java.lang.reflect.TypeVariable) Executable(java.lang.reflect.Executable) Test(org.testng.annotations.Test)

Example 15 with Executable

use of java.lang.reflect.Executable in project guice by google.

the class AbstractGlueGenerator method generateTrampoline.

/**
 * Generate trampoline that takes an index, along with a context object and array of argument
 * objects, and invokes the appropriate constructor/method returning the result as an object.
 */
protected final void generateTrampoline(ClassWriter cw, Collection<Executable> members) {
    MethodVisitor mv = cw.visitMethod(PUBLIC | STATIC, TRAMPOLINE_NAME, TRAMPOLINE_DESCRIPTOR, null, null);
    mv.visitCode();
    Label[] labels = new Label[members.size()];
    Arrays.setAll(labels, i -> new Label());
    Label defaultLabel = new Label();
    mv.visitVarInsn(ILOAD, 0);
    mv.visitTableSwitchInsn(0, labels.length - 1, defaultLabel, labels);
    int labelIndex = 0;
    for (Executable member : members) {
        mv.visitLabel(labels[labelIndex++]);
        mv.visitFrame(F_SAME, 0, null, 0, null);
        if (member instanceof Constructor<?>) {
            generateConstructorInvoker(mv, (Constructor<?>) member);
        } else {
            generateMethodInvoker(mv, (Method) member);
        }
        mv.visitInsn(ARETURN);
    }
    mv.visitLabel(defaultLabel);
    mv.visitFrame(F_SAME, 0, null, 0, null);
    mv.visitInsn(ACONST_NULL);
    mv.visitInsn(ARETURN);
    mv.visitMaxs(0, 0);
    mv.visitEnd();
}
Also used : Constructor(java.lang.reflect.Constructor) Label(org.objectweb.asm.Label) Executable(java.lang.reflect.Executable) MethodVisitor(org.objectweb.asm.MethodVisitor)

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