use of com.oracle.svm.core.annotate.TargetElement in project graal by oracle.
the class AnnotationSubstitutionProcessor method findOriginalMethod.
private ResolvedJavaMethod findOriginalMethod(Executable annotatedMethod, Class<?> originalClass) {
TargetElement targetElementAnnotation = lookupAnnotation(annotatedMethod, TargetElement.class);
String originalName = "";
boolean optional = false;
if (targetElementAnnotation != null) {
originalName = targetElementAnnotation.name();
optional = targetElementAnnotation.optional();
}
if (originalName.length() == 0) {
originalName = annotatedMethod.getName();
}
try {
if (annotatedMethod instanceof Method && !originalName.equals(TargetElement.CONSTRUCTOR_NAME)) {
Class<?>[] originalParams = interceptParameterTypes(annotatedMethod.getParameterTypes());
Method originalMethod = originalClass.getDeclaredMethod(originalName, originalParams);
guarantee(Modifier.isStatic(annotatedMethod.getModifiers()) == Modifier.isStatic(originalMethod.getModifiers()), "Static modifier mismatch: %s, %s", annotatedMethod, originalMethod);
return metaAccess.lookupJavaMethod(originalMethod);
} else {
guarantee(!Modifier.isStatic(annotatedMethod.getModifiers()), "Constructor Alias method %s must not be static", annotatedMethod);
Class<?>[] originalParams = interceptParameterTypes(annotatedMethod.getParameterTypes());
Constructor<?> originalMethod = originalClass.getDeclaredConstructor(originalParams);
return metaAccess.lookupJavaMethod(originalMethod);
}
} catch (NoSuchMethodException ex) {
guarantee(optional, "could not find non-optional target method: %s", annotatedMethod);
return null;
}
}
use of com.oracle.svm.core.annotate.TargetElement in project graal by oracle.
the class AnnotationSubstitutionProcessor method findOriginalField.
private ResolvedJavaField findOriginalField(Field annotatedField, Class<?> originalClass, boolean forceOptional) {
TargetElement targetElementAnnotation = lookupAnnotation(annotatedField, TargetElement.class);
String originalName = "";
boolean optional = false;
if (targetElementAnnotation != null) {
originalName = targetElementAnnotation.name();
optional = targetElementAnnotation.optional();
}
if (originalName.length() == 0) {
originalName = annotatedField.getName();
}
try {
Field originalField = originalClass.getDeclaredField(originalName);
guarantee(getTargetClass(annotatedField.getType()).equals(originalField.getType()), "Type mismatch:%n %s %s%n %s %s", annotatedField.getType(), annotatedField, originalField.getType(), originalField);
return metaAccess.lookupJavaField(originalField);
} catch (NoSuchFieldException ex) {
/*
* Some fields are hidden from reflection. Try to find the field via the
* ResolvedJavaType.
*/
for (ResolvedJavaField f : metaAccess.lookupJavaType(originalClass).getInstanceFields(true)) {
if (f.getName().equals(originalName)) {
return f;
}
}
guarantee(optional || forceOptional, "could not find non-optional target field: %s", annotatedField);
return null;
}
}
Aggregations