Search in sources :

Example 86 with AnnotationMirror

use of javax.lang.model.element.AnnotationMirror in project graal by oracle.

the class LayoutParser method parse.

public void parse(TypeElement layoutElement) {
    if (layoutElement.getKind() != ElementKind.INTERFACE) {
        processor.reportError(layoutElement, "@Layout should only be applied to interfaces");
    }
    parseName(layoutElement);
    if (!layoutElement.getInterfaces().isEmpty()) {
        if (layoutElement.getInterfaces().size() > 1) {
            processor.reportError(layoutElement, "@Layout interfaces can have at most one super-interface");
        }
        final DeclaredType superInterface = (DeclaredType) layoutElement.getInterfaces().get(0);
        parseSuperLayout((TypeElement) superInterface.asElement());
    }
    for (AnnotationMirror annotationMirror : layoutElement.getAnnotationMirrors()) {
        if (isSameType(annotationMirror.getAnnotationType(), Layout.class)) {
            objectTypeSuperclass = ElementUtils.getAnnotationValue(TypeMirror.class, annotationMirror, "objectTypeSuperclass");
            if (ElementUtils.getAnnotationValue(Boolean.class, annotationMirror, "implicitCastIntToLong")) {
                implicitCasts.add(ImplicitCast.IntToLong);
            }
            if (ElementUtils.getAnnotationValue(Boolean.class, annotationMirror, "implicitCastIntToDouble")) {
                implicitCasts.add(ImplicitCast.IntToDouble);
            }
        }
    }
    if (superLayout != null && !implicitCasts.isEmpty()) {
        processor.reportError(layoutElement, "@Layout implicit casts need to be specified in the base layout");
    }
    for (Element element : layoutElement.getEnclosedElements()) {
        if (element.getKind() == ElementKind.FIELD) {
            final String simpleName = element.getSimpleName().toString();
            if (simpleName.endsWith("_IDENTIFIER")) {
                parseIdentifier((VariableElement) element);
            } else {
                processor.reportError(element, "@Layout interface fields should only be identifier fields, ending with _IDENTIFIER");
            }
        }
    }
    for (Element element : layoutElement.getEnclosedElements()) {
        if (element.getKind() == ElementKind.METHOD) {
            final String simpleName = element.getSimpleName().toString();
            if (simpleName.equals("create" + name + "Shape")) {
                parseShapeConstructor((ExecutableElement) element);
            }
        }
    }
    for (Element element : layoutElement.getEnclosedElements()) {
        if (element.getKind() == ElementKind.METHOD) {
            final String simpleName = element.getSimpleName().toString();
            if (simpleName.equals("create" + name + "Shape")) {
            // Handled above
            } else if (simpleName.equals("create" + name)) {
                parseConstructor((ExecutableElement) element);
            } else if (simpleName.equals("build")) {
                parseBuilder((ExecutableElement) element);
            } else if (simpleName.equals("is" + name)) {
                parseGuard((ExecutableElement) element);
            } else if (simpleName.startsWith("getAndSet")) {
                parseGetAndSet((ExecutableElement) element);
            } else if (simpleName.startsWith("compareAndSet")) {
                parseCompareAndSet((ExecutableElement) element);
            } else if (simpleName.startsWith("get")) {
                parseGetter((ExecutableElement) element);
            } else if (simpleName.startsWith("set")) {
                parseSetter((ExecutableElement) element);
            } else {
                processor.reportError(element, "Unknown method prefix in @Layout interface - wouldn't know how to implement this method");
            }
        }
    }
    for (Element element : layoutElement.getEnclosedElements()) {
        if (element.getKind() != ElementKind.FIELD && element.getKind() != ElementKind.METHOD) {
            processor.reportError(element, "@Layout interfaces can only contain fields and methods");
        }
    }
}
Also used : AnnotationMirror(javax.lang.model.element.AnnotationMirror) TypeMirror(javax.lang.model.type.TypeMirror) ExecutableElement(javax.lang.model.element.ExecutableElement) VariableElement(javax.lang.model.element.VariableElement) Element(javax.lang.model.element.Element) TypeElement(javax.lang.model.element.TypeElement) ExecutableElement(javax.lang.model.element.ExecutableElement) DeclaredType(javax.lang.model.type.DeclaredType)

Example 87 with AnnotationMirror

use of javax.lang.model.element.AnnotationMirror in project graal by oracle.

the class VerifierAnnotationProcessor method findAnnotationMirror.

public static AnnotationMirror findAnnotationMirror(ProcessingEnvironment processingEnv, List<? extends AnnotationMirror> mirrors, Class<?> annotationClass) {
    TypeElement expectedAnnotationType = processingEnv.getElementUtils().getTypeElement(annotationClass.getCanonicalName());
    for (AnnotationMirror mirror : mirrors) {
        DeclaredType annotationType = mirror.getAnnotationType();
        TypeElement actualAnnotationType = (TypeElement) annotationType.asElement();
        if (actualAnnotationType.equals(expectedAnnotationType)) {
            return mirror;
        }
    }
    return null;
}
Also used : AnnotationMirror(javax.lang.model.element.AnnotationMirror) TypeElement(javax.lang.model.element.TypeElement) DeclaredType(javax.lang.model.type.DeclaredType)

Example 88 with AnnotationMirror

use of javax.lang.model.element.AnnotationMirror in project ballerina by ballerina-lang.

the class ClassIndexProcessor method process.

@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    try {
        for (Element element : roundEnv.getRootElements()) {
            if (!(element instanceof TypeElement)) {
                continue;
            }
            final PackageElement packageElement = getPackage(element);
            element.accept(new ElementScanner6<Void, Void>() {

                @Override
                public Void visitType(TypeElement typeElement, Void o) {
                    try {
                        for (AnnotationMirror mirror : typeElement.getAnnotationMirrors()) {
                            final TypeElement annotationElement = (TypeElement) mirror.getAnnotationType().asElement();
                            storeAnnotation(annotationElement, typeElement);
                        }
                        indexSupertypes(typeElement, typeElement);
                        if (packageElement != null) {
                            storeClassFromPackage(packageElement, typeElement);
                        }
                    } catch (IOException e) {
                        messager.printMessage(Diagnostic.Kind.ERROR, "[ClassIndexProcessor] " + e.getMessage());
                    }
                    return super.visitType(typeElement, o);
                }
            }, null);
        }
        if (!roundEnv.processingOver()) {
            return false;
        }
        writeIndexFiles(ClassIndex.SUBCLASS_INDEX_PREFIX, subclassMap);
        writeIndexFiles(ClassIndex.ANNOTATED_INDEX_PREFIX, annotatedMap);
        for (Map.Entry<String, Set<String>> entry : packageMap.entrySet()) {
            writeSimpleNameIndexFile(entry.getValue(), entry.getKey().replace(".", "/") + "/" + ClassIndex.PACKAGE_INDEX_NAME);
        }
    } catch (IOException e) {
        messager.printMessage(Diagnostic.Kind.ERROR, "[ClassIndexProcessor] Can't write index file: " + e.getMessage());
    } catch (Throwable e) {
        log.error(e.getMessage(), e);
        messager.printMessage(Diagnostic.Kind.ERROR, "[ClassIndexProcessor] Internal error: " + e.getMessage());
    }
    return false;
}
Also used : TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) Set(java.util.Set) TypeElement(javax.lang.model.element.TypeElement) PackageElement(javax.lang.model.element.PackageElement) TypeElement(javax.lang.model.element.TypeElement) Element(javax.lang.model.element.Element) IOException(java.io.IOException) AnnotationMirror(javax.lang.model.element.AnnotationMirror) PackageElement(javax.lang.model.element.PackageElement) HashMap(java.util.HashMap) Map(java.util.Map)

Example 89 with AnnotationMirror

use of javax.lang.model.element.AnnotationMirror in project graal by oracle.

the class MatchProcessor method processMatchableNode.

/**
 * Build up the type table to be used during parsing of the MatchRule.
 */
private void processMatchableNode(Element element) {
    if (!processedMatchableNode.contains(element)) {
        try {
            processedMatchableNode.add(element);
            AnnotationMirror mirror = findAnnotationMirror(element, matchableNodesTypeMirror);
            if (mirror == null) {
                mirror = findAnnotationMirror(element, matchableNodeTypeMirror);
            }
            if (mirror == null) {
                return;
            }
            TypeElement topDeclaringType = topDeclaringType(element);
            List<AnnotationMirror> mirrors = null;
            if (typeUtils().isSameType(mirror.getAnnotationType(), matchableNodesTypeMirror)) {
                // Unpack the mirrors for a repeatable annotation
                mirrors = getAnnotationValueList(AnnotationMirror.class, mirror, "value");
            }
            int i = 0;
            for (MatchableNode matchableNode : element.getAnnotationsByType(MatchableNode.class)) {
                processMatchableNode(element, topDeclaringType, matchableNode, mirrors != null ? mirrors.get(i++) : mirror);
            }
        } catch (Throwable t) {
            reportExceptionThrow(element, t);
        }
    }
}
Also used : MatchableNode(org.graalvm.compiler.core.match.MatchableNode) AnnotationMirror(javax.lang.model.element.AnnotationMirror) TypeElement(javax.lang.model.element.TypeElement)

Example 90 with AnnotationMirror

use of javax.lang.model.element.AnnotationMirror in project glide by bumptech.

the class GlideGenerator method addReturnAnnotations.

private Builder addReturnAnnotations(Builder builder, ExecutableElement methodToOverride) {
    String visibleForTestingTypeQualifiedName = processingEnv.getElementUtils().getTypeElement(VISIBLE_FOR_TESTING_QUALIFIED_NAME).toString();
    for (AnnotationMirror mirror : methodToOverride.getAnnotationMirrors()) {
        builder.addAnnotation(AnnotationSpec.get(mirror));
        // Suppress a lint warning if we're overriding a VisibleForTesting method.
        // See #1977.
        String annotationQualifiedName = mirror.getAnnotationType().toString();
        if (annotationQualifiedName.equals(visibleForTestingTypeQualifiedName)) {
            builder.addAnnotation(AnnotationSpec.builder(ClassName.get(SUPPRESS_LINT_PACKAGE_NAME, SUPPRESS_LINT_CLASS_NAME)).addMember("value", "$S", "VisibleForTests").build());
        }
    }
    return builder;
}
Also used : AnnotationMirror(javax.lang.model.element.AnnotationMirror)

Aggregations

AnnotationMirror (javax.lang.model.element.AnnotationMirror)665 TypeElement (javax.lang.model.element.TypeElement)159 ExecutableElement (javax.lang.model.element.ExecutableElement)112 TypeMirror (javax.lang.model.type.TypeMirror)99 ArrayList (java.util.ArrayList)92 AnnotatedTypeMirror (org.checkerframework.framework.type.AnnotatedTypeMirror)90 Element (javax.lang.model.element.Element)87 VariableElement (javax.lang.model.element.VariableElement)79 AnnotationValue (javax.lang.model.element.AnnotationValue)73 DeclaredType (javax.lang.model.type.DeclaredType)58 List (java.util.List)52 CFValue (org.checkerframework.framework.flow.CFValue)52 Map (java.util.Map)46 HashSet (java.util.HashSet)40 JavaExpression (org.checkerframework.dataflow.expression.JavaExpression)39 CFStore (org.checkerframework.framework.flow.CFStore)39 HashMap (java.util.HashMap)37 QualifierHierarchy (org.checkerframework.framework.type.QualifierHierarchy)36 ExpressionTree (com.sun.source.tree.ExpressionTree)30 MethodTree (com.sun.source.tree.MethodTree)29