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