use of com.oracle.truffle.api.instrumentation.GenerateWrapper in project graal by oracle.
the class InstrumentableProcessor method processLegacyInstrumentable.
/*
* TO BE REMOVED WITH DEPRECATIONS
*/
@SuppressWarnings("deprecation")
private void processLegacyInstrumentable(RoundEnvironment roundEnv, ProcessorContext context) {
for (Element element : roundEnv.getElementsAnnotatedWith(com.oracle.truffle.api.instrumentation.Instrumentable.class)) {
if (!element.getKind().isClass() && !element.getKind().isInterface()) {
continue;
}
try {
if (element.getKind() != ElementKind.CLASS) {
emitError(element, String.format("Only classes can be annotated with %s.", com.oracle.truffle.api.instrumentation.Instrumentable.class.getSimpleName()));
continue;
}
AnnotationMirror generateWrapperMirror = ElementUtils.findAnnotationMirror(element.getAnnotationMirrors(), context.getType(GenerateWrapper.class));
if (generateWrapperMirror != null) {
continue;
}
TypeMirror instrumentableType = context.getType(com.oracle.truffle.api.instrumentation.Instrumentable.class);
AnnotationMirror instrumentable = ElementUtils.findAnnotationMirror(element.getAnnotationMirrors(), instrumentableType);
if (instrumentable == null) {
continue;
} else {
final boolean generateWrapper;
TypeMirror factoryType = ElementUtils.getAnnotationValue(TypeMirror.class, instrumentable, "factory");
if (factoryType == null || factoryType.getKind() == TypeKind.ERROR) {
// factory type is erroneous or null (can mean error in javac)
// generate it
generateWrapper = true;
} else {
TypeElement type = context.getEnvironment().getElementUtils().getTypeElement("com.oracle.truffle.api.instrumentation.test.TestErrorFactory");
if (type != null && ElementUtils.typeEquals(factoryType, type.asType())) {
generateWrapper = true;
} else {
// factory is user defined or already generated
generateWrapper = false;
}
}
if (!generateWrapper) {
continue;
}
}
CodeTypeElement unit = generateWrapperAndFactory(context, element);
if (unit == null) {
continue;
}
DeclaredType overrideType = (DeclaredType) context.getType(Override.class);
DeclaredType unusedType = (DeclaredType) context.getType(SuppressWarnings.class);
unit.accept(new GenerateOverrideVisitor(overrideType), null);
unit.accept(new FixWarningsVisitor(context.getEnvironment(), unusedType, overrideType), null);
unit.accept(new CodeWriter(context.getEnvironment(), element), null);
} catch (Throwable e) {
// never throw annotation processor exceptions to the compiler
// it might screw up its state.
handleThrowable(e, element);
}
}
}
Aggregations