@Override public void visitNode(Tree tree) { int types = ((CompilationUnitTree) tree).types().size(); if (types > 1) { context.addIssue( -1, OneClassInterfacePerFileCheck.this, "There are " + types + " top-level types in this file; move all but one of them to other files.", types - 1); } }
@Override public void visitCompilationUnit(CompilationUnitTree tree) { // skips package name, imports, and annotations. scan(tree.types()); }
@Override public void visitNode(Tree tree) { int types = ((CompilationUnitTree) tree).types().size(); if (types > 1) { context.addIssue( -1, OneClassInterfacePerFileCheck.this, "There are " + types + " top-level types in this file; move all but one of them to other files.", types - 1); } }
@Override public void visitNode(Tree tree) { if (hasSemantic()) { resetAnnotationCache(); CompilationUnitTree cut = (CompilationUnitTree) tree; cut.types().stream().filter(typeTree -> typeTree.is(Kind.CLASS)).forEach(typeTree -> checkClass((ClassTree) typeTree)); } }
@Override public void visitNode(Tree tree) { if (hasSemantic()) { resetAnnotationCache(); CompilationUnitTree cut = (CompilationUnitTree) tree; cut.types().stream().filter(typeTree -> typeTree.is(Kind.CLASS)).forEach(typeTree -> checkClass((ClassTree) typeTree)); } }
@Override public void visitNode(Tree tree) { if (!hasSemantic()) { return; } CompilationUnitTree cut = (CompilationUnitTree) tree; cut.types().stream().filter(NOT_EMPTY_STATEMENT).map(t -> ((ClassTree) t).symbol()).forEach(this::checkSymbol); List<ImportTree> imports = cut.imports().stream().filter(NOT_EMPTY_STATEMENT).map(t -> (ImportTree) t).collect(Collectors.toList()); boolean fileContainsStarImport = imports.stream() .filter(it -> it.qualifiedIdentifier().is(Kind.MEMBER_SELECT)) .map(it -> ((MemberSelectExpressionTree) it.qualifiedIdentifier()).identifier()) .anyMatch(i -> "*".equals(i.name())); if(!fileContainsStarImport) { checkImports(imports); } }
@Override public void visitNode(Tree tree) { if (!hasSemantic()) { return; } CompilationUnitTree cut = (CompilationUnitTree) tree; cut.types().stream().filter(NOT_EMPTY_STATEMENT).map(t -> ((ClassTree) t).symbol()).forEach(this::checkSymbol); List<ImportTree> imports = cut.imports().stream().filter(NOT_EMPTY_STATEMENT).map(t -> (ImportTree) t).collect(Collectors.toList()); boolean fileContainsStarImport = imports.stream() .filter(it -> it.qualifiedIdentifier().is(Kind.MEMBER_SELECT)) .map(it -> ((MemberSelectExpressionTree) it.qualifiedIdentifier()).identifier()) .anyMatch(i -> "*".equals(i.name())); if(!fileContainsStarImport) { checkImports(imports); } }
@Override public void scanFile(JavaFileScannerContext context) { CompilationUnitTree tree = context.getTree(); if (tree.packageName() == null && tree.types().isEmpty()) { context.addIssue(context.getTree(), this, "This Java file is empty."); } }
@Override public void visitNode(Tree tree) { CompilationUnitTree cut = (CompilationUnitTree) tree; for (Tree typeTree : cut.types()) { if (typeTree.is(Kind.CLASS)) { ClassTree classTree = (ClassTree) typeTree; checkJunit3TestClass(classTree); checkJunit4TestClass(classTree); } } }
@Override public void visitCompilationUnit(CompilationUnitTree tree) { //do not scan imports and package name identifiers. scan(tree.packageAnnotations()); scan(tree.types()); }
@Override public void scanFile(JavaFileScannerContext context) { if (context.fileParsed()) { CompilationUnitTree cut = context.getTree(); if (cut.moduleDeclaration() == null && cut.packageDeclaration() == null && cut.types().isEmpty()) { context.addIssueOnFile(this, "This file has 0 lines of code."); } } }
@Override public void scanFile(JavaFileScannerContext context) { if (context.fileParsed()) { CompilationUnitTree cut = context.getTree(); if (cut.moduleDeclaration() == null && cut.packageDeclaration() == null && cut.types().isEmpty()) { context.addIssueOnFile(this, "This file has 0 lines of code."); } } }
@Override public void visitCompilationUnit(CompilationUnitTree tree) { //do not scan imports and package name identifiers. if (tree.packageDeclaration() != null) { scan(tree.packageDeclaration().annotations()); } scan(tree.types()); }
@Override public void visitCompilationUnit(CompilationUnitTree tree) { //do not scan imports and package name identifiers. if (tree.packageDeclaration() != null) { scan(tree.packageDeclaration().annotations()); } scan(tree.types()); }
@Override public void visitCompilationUnit(CompilationUnitTree tree) { scan(tree.packageDeclaration()); scan(tree.imports()); scan(tree.types()); }
@Override public void visitCompilationUnit(CompilationUnitTree tree) { scan(tree.packageDeclaration()); scan(tree.imports()); scan(tree.types()); scan(tree.moduleDeclaration()); }
@Override public void visitCompilationUnit(CompilationUnitTree tree) { scan(tree.packageDeclaration()); scan(tree.imports()); scan(tree.types()); scan(tree.moduleDeclaration()); }
@Override public void visitCompilationUnit(CompilationUnitTree tree) { scan(tree.packageAnnotations()); scan(tree.packageName()); scan(tree.imports()); scan(tree.types()); }
@Override public void visitCompilationUnit(CompilationUnitTree tree) { JavaSymbol.PackageJavaSymbol compilationUnitPackage = symbols.defaultPackage; PackageDeclarationTree packageDeclaration = tree.packageDeclaration(); if (packageDeclaration != null) { ExpressionTree packageName = packageDeclaration.packageName(); PackageResolverVisitor packageResolver = new PackageResolverVisitor(); packageName.accept(packageResolver); compilationUnitPackage = (JavaSymbol.PackageJavaSymbol) resolve.findIdentInPackage(compilationUnitPackage, packageResolver.packageName, JavaSymbol.PCK); semanticModel.associateSymbol(packageName, compilationUnitPackage); } compilationUnitPackage.members = new Scope(compilationUnitPackage); env = new Resolve.Env(); env.packge = compilationUnitPackage; env.scope = compilationUnitPackage.members; env.namedImports = new Scope.ImportScope(compilationUnitPackage); env.starImports = resolve.createStarImportScope(compilationUnitPackage); env.staticStarImports = resolve.createStaticStarImportScope(compilationUnitPackage); semanticModel.associateEnv(tree, env); scan(tree.types()); restoreEnvironment(tree); resolveImports(tree.imports()); completeSymbols(); }
@Override public void visitCompilationUnit(CompilationUnitTree tree) { JavaSymbol.PackageJavaSymbol compilationUnitPackage = symbols.defaultPackage; PackageDeclarationTree packageDeclaration = tree.packageDeclaration(); if (packageDeclaration != null) { ExpressionTree packageName = packageDeclaration.packageName(); PackageResolverVisitor packageResolver = new PackageResolverVisitor(); packageName.accept(packageResolver); compilationUnitPackage = (JavaSymbol.PackageJavaSymbol) resolve.findIdentInPackage(compilationUnitPackage, packageResolver.packageName, JavaSymbol.PCK); semanticModel.associateSymbol(packageName, compilationUnitPackage); } compilationUnitPackage.members = new Scope(compilationUnitPackage); env = new Resolve.Env(); env.packge = compilationUnitPackage; env.scope = compilationUnitPackage.members; env.namedImports = new Scope.ImportScope(compilationUnitPackage); env.starImports = resolve.createStarImportScope(compilationUnitPackage); env.staticStarImports = resolve.createStaticStarImportScope(compilationUnitPackage); semanticModel.associateEnv(tree, env); scan(tree.types()); restoreEnvironment(tree); resolveImports(tree.imports()); completeSymbols(); }