Search in sources :

Example 1 with GenerateWrapper

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);
        }
    }
}
Also used : TypeElement(javax.lang.model.element.TypeElement) CodeTypeElement(com.oracle.truffle.dsl.processor.java.model.CodeTypeElement) PackageElement(javax.lang.model.element.PackageElement) VariableElement(javax.lang.model.element.VariableElement) TypeElement(javax.lang.model.element.TypeElement) CodeVariableElement(com.oracle.truffle.dsl.processor.java.model.CodeVariableElement) CodeExecutableElement(com.oracle.truffle.dsl.processor.java.model.CodeExecutableElement) CodeTypeElement(com.oracle.truffle.dsl.processor.java.model.CodeTypeElement) ExecutableElement(javax.lang.model.element.ExecutableElement) Element(javax.lang.model.element.Element) GenerateWrapper(com.oracle.truffle.api.instrumentation.GenerateWrapper) FixWarningsVisitor(com.oracle.truffle.dsl.processor.java.transform.FixWarningsVisitor) CodeAnnotationMirror(com.oracle.truffle.dsl.processor.java.model.CodeAnnotationMirror) AnnotationMirror(javax.lang.model.element.AnnotationMirror) CodeTypeMirror(com.oracle.truffle.dsl.processor.java.model.CodeTypeMirror) TypeMirror(javax.lang.model.type.TypeMirror) CodeTypeElement(com.oracle.truffle.dsl.processor.java.model.CodeTypeElement) GenerateOverrideVisitor(com.oracle.truffle.dsl.processor.java.transform.GenerateOverrideVisitor) DeclaredType(javax.lang.model.type.DeclaredType)

Aggregations

GenerateWrapper (com.oracle.truffle.api.instrumentation.GenerateWrapper)1 CodeAnnotationMirror (com.oracle.truffle.dsl.processor.java.model.CodeAnnotationMirror)1 CodeExecutableElement (com.oracle.truffle.dsl.processor.java.model.CodeExecutableElement)1 CodeTypeElement (com.oracle.truffle.dsl.processor.java.model.CodeTypeElement)1 CodeTypeMirror (com.oracle.truffle.dsl.processor.java.model.CodeTypeMirror)1 CodeVariableElement (com.oracle.truffle.dsl.processor.java.model.CodeVariableElement)1 FixWarningsVisitor (com.oracle.truffle.dsl.processor.java.transform.FixWarningsVisitor)1 GenerateOverrideVisitor (com.oracle.truffle.dsl.processor.java.transform.GenerateOverrideVisitor)1 AnnotationMirror (javax.lang.model.element.AnnotationMirror)1 Element (javax.lang.model.element.Element)1 ExecutableElement (javax.lang.model.element.ExecutableElement)1 PackageElement (javax.lang.model.element.PackageElement)1 TypeElement (javax.lang.model.element.TypeElement)1 VariableElement (javax.lang.model.element.VariableElement)1 DeclaredType (javax.lang.model.type.DeclaredType)1 TypeMirror (javax.lang.model.type.TypeMirror)1