private boolean annotatedWith_NoBootstrap( List<JCTree.JCAnnotation> annotations ) { for( JCTree.JCAnnotation anno : annotations ) { if( anno.getAnnotationType().toString().endsWith( NoBootstrap.class.getSimpleName() ) ) { return true; } } return false; }
private boolean hasAnnotation( List<JCTree.JCAnnotation> annotations, Class<? extends Annotation> annoClass ) { for( JCTree.JCAnnotation anno: annotations ) { if( anno.getAnnotationType().type.toString().equals( annoClass.getCanonicalName() ) ) { return true; } } return false; }
private boolean hasAnnotation( List<JCTree.JCAnnotation> annotations, Class<? extends Annotation> annoClass ) { for( JCTree.JCAnnotation anno: annotations ) { if( anno.getAnnotationType().type.toString().equals( annoClass.getCanonicalName() ) ) { return true; } } return false; }
src.annotationMap.put(range.begin.line, annotation); } else { JCTree annotationType = anno.getAnnotationType(); String name = annotationType.toString(); Annotation annotation = new Annotation(name, startPos, range); JCTree annotationType = anno.getAnnotationType(); analyzeParsedTree(context, annotationType);
private static void analyzeAnnotationTree( final Source src, final EndPosTable endPosTable, final AnnotationTree at) { if (at instanceof JCTree.JCAnnotation) { JCTree.JCAnnotation anno = (JCTree.JCAnnotation) at; int startPos = anno.getPreferredPosition(); int endPos = anno.getEndPosition(endPosTable); JCTree annotationType = anno.getAnnotationType(); int annotationTypeEndPosition = annotationType.getEndPosition(endPosTable); Range range; if (endPos != annotationTypeEndPosition) { startPos = annotationTypeEndPosition; } range = Range.create(src, startPos + 1, endPos); Type type = anno.type; Annotation annotation; if (nonNull(type)) { annotation = new Annotation(type.toString(), startPos, range); } else { annotation = new Annotation(annotationType.toString(), startPos, range); } src.annotationMap.put(range.begin.line, annotation); } }
private static String parseModifiers( SourceContext context, @Nullable JCTree.JCModifiers modifiers) throws IOException { if (nonNull(modifiers)) { List<JCTree.JCAnnotation> annotations = modifiers.getAnnotations(); if (nonNull(annotations) && annotations.size() > 0) { for (JCTree.JCAnnotation anno : annotations) { JCTree annotationType = anno.getAnnotationType(); if (nonNull(annotationType)) { analyzeParsedTree(context, annotationType); } List<JCTree.JCExpression> arguments = anno.getArguments(); if (nonNull(arguments)) { for (JCTree.JCExpression jcExpression : arguments) { analyzeParsedTree(context, jcExpression); } } } String mod = modifiers.toString(); int lastIndexOf = mod.lastIndexOf('\n'); return mod.substring(lastIndexOf + 1); } return modifiers.toString(); } return ""; }
@Override public void visitAnnotation( JCTree.JCAnnotation tree ) { super.visitAnnotation( tree ); if( !Self.class.getTypeName().equals( tree.getAnnotationType().type.tsym.toString() ) ) { return; } if( !isSelfInReturn( tree, tree ) ) { _tp.report( tree, Diagnostic.Kind.ERROR, ExtIssueMsg.MSG_SELF_NOT_ALLOWED_HERE.get() ); } else { verifySelfOnThis( tree, tree ); } }
@Override public void visitAnnotation( JCTree.JCAnnotation tree ) { super.visitAnnotation( tree ); if( !Self.class.getTypeName().equals( tree.getAnnotationType().type.tsym.toString() ) ) { return; } if( !isSelfInReturn( tree, tree ) ) { _tp.report( tree, Diagnostic.Kind.ERROR, ExtIssueMsg.MSG_SELF_NOT_ALLOWED_HERE.get() ); } else { verifySelfOnThis( tree, tree ); } }
@Override public Description matchMethod(MethodTree method, VisitorState state) { if (!CAN_BE_A_MULTIBINDS_METHOD.matches(method, state)) { return NO_MATCH; } JCClassDecl enclosingClass = ASTHelpers.findEnclosingNode(state.getPath(), JCClassDecl.class); // Check to see if this is in a Dagger 1 module b/c it doesn't support @Multibinds for (JCAnnotation annotation : enclosingClass.getModifiers().getAnnotations()) { if (ASTHelpers.getSymbol(annotation.getAnnotationType()) .getQualifiedName() .contentEquals("dagger.Module") && HAS_DAGGER_ONE_MODULE_ARGUMENT.matches(annotation, state)) { return NO_MATCH; } } return fixByModifyingMethod(state, enclosingClass, method); }
@Override public void visitAnnotation(JCAnnotation node) { Annotation a = new Annotation(); a.rawAnnotationTypeReference(toTree(node.getAnnotationType(), FlagKey.TYPE_REFERENCE)); for (JCExpression elem : node.getArguments()) { AnnotationElement e = new AnnotationElement(); if (elem instanceof JCAssign) { JCExpression rawName = ((JCAssign) elem).getVariable(); if (rawName instanceof JCIdent) e.astName(setPos(rawName, new Identifier().astValue(((JCIdent)rawName).getName().toString()))); elem = ((JCAssign) elem).getExpression(); } e.rawValue(toTree(elem)); a.astElements().addToEnd(e); } set(node, a); } }
@Override public void visitAnnotation(JCAnnotation node) { Annotation a = new Annotation(); a.rawAnnotationTypeReference(toTree(node.getAnnotationType(), FlagKey.TYPE_REFERENCE)); for (JCExpression elem : node.getArguments()) { AnnotationElement e = new AnnotationElement(); if (elem instanceof JCAssign) { JCExpression rawName = ((JCAssign) elem).getVariable(); if (rawName instanceof JCIdent) e.astName(setPos(rawName, new Identifier().astValue(((JCIdent)rawName).getName().toString()))); elem = ((JCAssign) elem).getExpression(); } e.rawValue(toTree(elem)); a.astElements().addToEnd(e); } set(node, a); } }
private void precompileClasses( JCTree.JCClassDecl tree ) { Map<String, Set<String>> typeNames = new HashMap<>(); for( JCTree.JCAnnotation anno: tree.getModifiers().getAnnotations() ) { if( anno.getAnnotationType().type.toString().equals( Precompile.class.getCanonicalName() ) ) { getTypesToCompile( anno, typeNames ); } } if( !typeNames.isEmpty() ) { precompile( typeNames ); } }
@Override public void visitAnnotation(JCAnnotation node) { Annotation a = new Annotation(); a.rawAnnotationTypeReference(toTree(node.getAnnotationType(), FlagKey.TYPE_REFERENCE)); for (JCExpression elem : node.getArguments()) { AnnotationElement e = new AnnotationElement(); if (elem instanceof JCAssign) { JCExpression rawName = ((JCAssign) elem).getVariable(); if (rawName instanceof JCIdent) e.astName(setPos(rawName, new Identifier().astValue(((JCIdent)rawName).getName().toString()))); elem = ((JCAssign) elem).getExpression(); } e.rawValue(toTree(elem)); a.astElements().addToEnd(e); } set(node, a); } }
private Set<Object> findDrivers( JCTree.JCClassDecl tree ) { Set<Object> drivers = new HashSet<>(); for( JCTree.JCAnnotation anno: tree.getModifiers().getAnnotations() ) { if( anno.getAnnotationType().type.toString().equals( IncrementalCompile.class.getCanonicalName() ) ) { getIncrementalCompileDrivers( anno, drivers ); } } _tp.addDrivers( drivers ); return _tp.getDrivers(); }
private Set<Object> findDrivers( JCTree.JCClassDecl tree ) { Set<Object> drivers = new HashSet<>(); for( JCTree.JCAnnotation anno: tree.getModifiers().getAnnotations() ) { if( anno.getAnnotationType().type.toString().equals( IncrementalCompile.class.getCanonicalName() ) ) { getIncrementalCompileDrivers( anno, drivers ); } } _tp.addDrivers( drivers ); return _tp.getDrivers(); }
private void precompileClasses( JCTree.JCClassDecl tree ) { Map<String, Set<String>> typeNames = new HashMap<>(); for( JCTree.JCAnnotation anno: tree.getModifiers().getAnnotations() ) { if( anno.getAnnotationType().type.toString().equals( Precompile.class.getCanonicalName() ) ) { getTypesToCompile( anno, typeNames ); } } precompile( typeNames ); }
/** * Prints an annotation tree. */ @Override public void visitAnnotation(JCAnnotation annotation) { if (!context.hasAnnotationType(annotation.type.tsym, JSweetConfig.ANNOTATION_DECORATOR)) { return; } print("@").print(annotation.getAnnotationType()); if (annotation.getArguments() != null && !annotation.getArguments().isEmpty()) { print("("); isAnnotationScope = true; print(" { "); for (JCExpression e : annotation.getArguments()) { print(e); print(", "); } removeLastChars(2); print(" } "); isAnnotationScope = false; print(")"); } else if (getParentOfParent() instanceof JCClassDecl) { print("()"); } println().printIndent(); }
@Override public Description matchMethod(MethodTree method, VisitorState state) { if (!CAN_BE_A_MULTIBINDS_METHOD.matches(method, state)) { return NO_MATCH; } JCClassDecl enclosingClass = ASTHelpers.findEnclosingNode(state.getPath(), JCClassDecl.class); // Check to see if this is in a Dagger 1 module b/c it doesn't support @Multibinds for (JCAnnotation annotation : enclosingClass.getModifiers().getAnnotations()) { if (ASTHelpers.getSymbol(annotation.getAnnotationType()) .getQualifiedName() .contentEquals("dagger.Module") && HAS_DAGGER_ONE_MODULE_ARGUMENT.matches(annotation, state)) { return NO_MATCH; } } return fixByModifyingMethod(state, enclosingClass, method); }