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");
}
}
}
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;
}
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;
}
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);
}
}
}
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;
}
Aggregations