if (parent != null) { getScope().innerClass = true; if (!classdecl.getModifiers().getFlags().contains(Modifier.STATIC)) { getScope().innerClassNotStatic = true; if (parent.getTypeParameters() != null) { if (classdecl.getModifiers().getFlags().contains(Modifier.ABSTRACT)) { print("abstract "); } else if (isAnonymousClass() && classdecl.getModifiers().getFlags().contains(Modifier.STATIC)) { JCNewClass newClass = getScope(1).anonymousClassesConstructors .get(getScope(1).anonymousClasses.indexOf(classdecl)); continue; if (!((JCVariableDecl) def).getModifiers().getFlags().contains(Modifier.STATIC) && ((JCVariableDecl) def).init == null) { hasUninitializedFields = true; if (!getScope().interfaceScope && classdecl.getModifiers().getFlags().contains(Modifier.ABSTRACT)) { List<MethodSymbol> methods = new ArrayList<>(); for (Type t : implementedInterfaces) {
scope.modifier = methodModifier.trim(); scope.returnType = TreeAnalyzer.markFQCN(src, returnFQCN); analyzeAnnotations(context, modifiers.getAnnotations(), scope);
if( hasAnnotation( param.getModifiers().getAnnotations(), This.class ) ) if( thisAnnoFound || hasAnnotation( tree.getModifiers().getAnnotations(), Extension.class ) )
if( hasAnnotation( param.getModifiers().getAnnotations(), This.class ) ) if( thisAnnoFound || hasAnnotation( tree.getModifiers().getAnnotations(), Extension.class ) )
int firstAnnotationPos = !oldT.getAnnotations().isEmpty() ? getOldPos(oldT.getAnnotations().head) : -1; int endOffset = endPos(oldT); printer.printFlags(newT.flags & ~Flags.INTERFACE, oldT.getFlags().isEmpty() ? true : false); tokenSequence.move(firstAnnotationPos); moveToSrcRelevant(tokenSequence, Direction.BACKWARD); localPointer = diffAnnotationsLists(oldT.getAnnotations(), newT.getAnnotations(), startPos, localPointer); printer.printFlags(newT.flags & ~Flags.INTERFACE, oldT.getFlags().isEmpty() ? true : false); localPointer = endOffset > 0 ? endOffset : localPointer; } else { copyTo(localPointer, localPointer = tokenSequence.offset()); localPointer = tokenSequence.offset(); if (!oldT.getFlags().isEmpty()) localPointer = endOffset; printer.printFlags(newT.flags, oldT.getFlags().isEmpty());
int endPos = classDecl.getEndPosition(endPosTable); JCTree.JCModifiers modifiers = classDecl.getModifiers(); List<JCTree.JCAnnotation> annotations = modifiers.getAnnotations();
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; }
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 SrcClass makeStubFromSource() { List<CompilationUnitTree> trees = new ArrayList<>(); _model.getHost().getJavaParser().parseText( _existingSource, trees, null, null, null ); JCTree.JCClassDecl classDecl = (JCTree.JCClassDecl)trees.get( 0 ).getTypeDecls().get( 0 ); SrcClass srcExtended = new SrcClass( _fqn, classDecl.getKind() == Tree.Kind.CLASS ? SrcClass.Kind.Class : SrcClass.Kind.Interface ) .modifiers( classDecl.getModifiers().getFlags() ); if( classDecl.extending != null ) { srcExtended.superClass( classDecl.extending.toString() ); } for( JCTree.JCExpression iface : classDecl.implementing ) { srcExtended.addInterface( iface.toString() ); } return srcExtended; }
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 SrcClass makeStubFromSource() { List<CompilationUnitTree> trees = new ArrayList<>(); _model.getHost().getJavaParser().parseText( _existingSource, trees, null, null, null ); JCTree.JCClassDecl classDecl = (JCTree.JCClassDecl)trees.get( 0 ).getTypeDecls().get( 0 ); SrcClass srcExtended = new SrcClass( _fqn, classDecl.getKind() == Tree.Kind.CLASS ? SrcClass.Kind.Class : SrcClass.Kind.Interface ) .modifiers( classDecl.getModifiers().getFlags() ); if( classDecl.extending != null ) { srcExtended.superClass( classDecl.extending.toString() ); } for( JCTree.JCExpression iface : classDecl.implementing ) { srcExtended.addInterface( iface.toString() ); } return srcExtended; }
@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 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 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(); }