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);
}
}
}
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));
}
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();
}
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()));
}
}
}
}
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();
}
Aggregations