use of com.oracle.svm.core.annotate.RecomputeFieldValue in project graal by oracle.
the class AnnotationSubstitutionProcessor method fieldValueRecomputation.
private ResolvedJavaField fieldValueRecomputation(Class<?> originalClass, ResolvedJavaField original, ResolvedJavaField annotated, Field annotatedField) {
RecomputeFieldValue recomputeAnnotation = lookupAnnotation(annotatedField, RecomputeFieldValue.class);
InjectAccessors injectAccessorsAnnotation = lookupAnnotation(annotatedField, InjectAccessors.class);
int numAnnotations = (recomputeAnnotation != null ? 1 : 0) + (injectAccessorsAnnotation != null ? 1 : 0);
guarantee(numAnnotations <= 1, "Only one of @RecomputeFieldValue or @InjectAccessors can be used: %s", annotatedField);
if (injectAccessorsAnnotation != null) {
return new AnnotatedField(original, injectAccessorsAnnotation);
}
if (recomputeAnnotation == null && !original.isFinal()) {
return original;
}
RecomputeFieldValue.Kind kind = RecomputeFieldValue.Kind.None;
Class<?> targetClass = originalClass;
String targetName = "";
boolean isFinal = false;
if (recomputeAnnotation != null) {
kind = recomputeAnnotation.kind();
targetName = recomputeAnnotation.name();
isFinal = recomputeAnnotation.isFinal();
guarantee(!isFinal || ComputedValueField.isFinalValid(kind), "@%s with %s can never be final during analysis: unset isFinal in the annotation on %s", RecomputeFieldValue.class.getSimpleName(), kind, annotated);
if (recomputeAnnotation.declClass() != RecomputeFieldValue.class) {
guarantee(recomputeAnnotation.declClassName().isEmpty(), "Both class and class name specified");
targetClass = recomputeAnnotation.declClass();
} else if (!recomputeAnnotation.declClassName().isEmpty()) {
targetClass = imageClassLoader.findClassByName(recomputeAnnotation.declClassName());
}
}
return new ComputedValueField(original, annotated, kind, targetClass, targetName, isFinal);
}
Aggregations