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 ""; }
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 ); } }
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 ); }
private Boolean getDisableAnnotationValue( JCTree.JCModifiers modifiers ) for( JCTree.JCAnnotation anno: modifiers.getAnnotations() )
private void verifyExtensionInterfaces( JCTree.JCClassDecl tree ) { if( !hasAnnotation( tree.getModifiers().getAnnotations(), Extension.class ) ) { return; } outer: for( JCExpression iface: tree.getImplementsClause() ) { final Symbol.TypeSymbol ifaceSym = iface.type.tsym; if( ifaceSym == _tp.getSymtab().objectType.tsym ) { continue; } for( Attribute.Compound anno: ifaceSym.getAnnotationMirrors() ) { if( anno.type.toString().equals( Structural.class.getName() ) ) { continue outer; } } // extension interfaces must be structural _tp.report( iface, Diagnostic.Kind.ERROR, ExtIssueMsg.MSG_ONLY_STRUCTURAL_INTERFACE_ALLOWED_HERE.get( iface.toString() ) ); } }
private void verifyExtensionInterfaces( JCTree.JCClassDecl tree ) { if( !hasAnnotation( tree.getModifiers().getAnnotations(), Extension.class ) ) { return; } outer: for( JCExpression iface: tree.getImplementsClause() ) { final Symbol.TypeSymbol ifaceSym = iface.type.tsym; if( ifaceSym == _tp.getSymtab().objectType.tsym ) { continue; } for( Attribute.Compound anno: ifaceSym.getAnnotationMirrors() ) { if( anno.type.toString().equals( Structural.class.getName() ) ) { continue outer; } } // extension interfaces must be structural _tp.report( iface, Diagnostic.Kind.ERROR, ExtIssueMsg.MSG_ONLY_STRUCTURAL_INTERFACE_ALLOWED_HERE.get( iface.toString() ) ); } }
private boolean isOnExtensionMethod( JCTree annotated, String fqn, JCTree.JCClassDecl enclosingClass ) { if( isExtensionClass( enclosingClass ) ) { String extendedClassName = getExtendedClassName(); if( extendedClassName != null && extendedClassName.equals( fqn ) ) { JCTree.JCMethodDecl declMethod = findDeclMethod( annotated ); if( declMethod != null ) { List<JCTree.JCVariableDecl> parameters = declMethod.getParameters(); for( JCTree.JCVariableDecl param: parameters ) { if( hasAnnotation( param.getModifiers().getAnnotations(), This.class ) ) { return true; } } } } } return false; }
private boolean isOnExtensionMethod( JCTree annotated, String fqn, JCTree.JCClassDecl enclosingClass ) { if( isExtensionClass( enclosingClass ) ) { String extendedClassName = getExtendedClassName(); if( extendedClassName != null && extendedClassName.equals( fqn ) ) { JCTree.JCMethodDecl declMethod = findDeclMethod( annotated ); if( declMethod != null ) { List<JCTree.JCVariableDecl> parameters = declMethod.getParameters(); for( JCTree.JCVariableDecl param: parameters ) { if( hasAnnotation( param.getModifiers().getAnnotations(), This.class ) ) { return true; } } } } } return false; }
@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); }
private boolean isSelfInReturn( Tree tree, JCTree.JCAnnotation anno ) { if( tree == null ) { return false; } Tree parent = _tp.getParent( tree ); if( parent instanceof JCTree.JCMethodDecl && (tree == ((JCTree.JCMethodDecl)parent).getModifiers() || tree == ((JCTree.JCMethodDecl)parent).getReturnType() || ((JCTree.JCMethodDecl)parent).getModifiers().getAnnotations().contains( anno )) ) { // @Self allowed only in/on return type of instance method return !((JCTree.JCMethodDecl)parent).getModifiers() .getFlags().contains( javax.lang.model.element.Modifier.STATIC ) || isExtensionClass( getEnclosingClass( parent ) ); } return isSelfInReturn( parent, anno ); }
private boolean isSelfInReturn( Tree tree, JCTree.JCAnnotation anno ) { if( tree == null ) { return false; } Tree parent = _tp.getParent( tree ); if( parent instanceof JCTree.JCMethodDecl && (tree == ((JCTree.JCMethodDecl)parent).getModifiers() || tree == ((JCTree.JCMethodDecl)parent).getReturnType() || ((JCTree.JCMethodDecl)parent).getModifiers().getAnnotations().contains( anno )) ) { // @Self allowed only in/on return type of instance method return !((JCTree.JCMethodDecl)parent).getModifiers() .getFlags().contains( javax.lang.model.element.Modifier.STATIC ) || isExtensionClass( getEnclosingClass( parent ) ); } return isSelfInReturn( parent, anno ); }
@Override public Description matchMethod(MethodTree tree, VisitorState state) { if (tree.getBody() == null) { return NO_MATCH; } SuggestedFix.Builder baseFixBuilder = SuggestedFix.builder(); JCExpression expectedException = deleteExpectedException( baseFixBuilder, ((JCMethodDecl) tree).getModifiers().getAnnotations(), state); SuggestedFix baseFix = baseFixBuilder.build(); if (expectedException == null) { return NO_MATCH; } return handleStatements(tree, state, expectedException, baseFix); }
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 boolean hasModifiers(JCModifiers mods) { return mods != null && (!mods.getFlags().isEmpty() || !mods.getAnnotations().isEmpty()); }
private boolean okToInsertBootstrap( JCTree.JCClassDecl tree ) { return !annotatedWith_NoBootstrap( tree.getModifiers().getAnnotations() ) && !JavacPlugin.instance().isNoBootstrapping() && !skipForOtherReasons( tree ); }
private boolean isExtensionClass( Tree parent ) { if( parent instanceof JCTree.JCClassDecl ) { return hasAnnotation( ((JCTree.JCClassDecl)parent).getModifiers().getAnnotations(), Extension.class ); } return false; }
private boolean isExtensionClass( Tree parent ) { if( parent instanceof JCTree.JCClassDecl ) { return hasAnnotation( ((JCTree.JCClassDecl)parent).getModifiers().getAnnotations(), Extension.class ); } return false; }
@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 Description matchMethod(MethodTree tree, VisitorState state) { if (tree.getBody() == null) { return NO_MATCH; } SuggestedFix.Builder baseFixBuilder = SuggestedFix.builder(); JCExpression expectedException = deleteExpectedException( baseFixBuilder, ((JCMethodDecl) tree).getModifiers().getAnnotations(), state); SuggestedFix baseFix = baseFixBuilder.build(); if (expectedException == null) { return NO_MATCH; } return handleStatements(tree, state, expectedException, baseFix); }