@Override public void visitNode(Tree tree) { CompilationUnitTree cut = (CompilationUnitTree) tree; List<ImportClauseTree> staticImports = cut.imports().stream() .filter(importClauseTree -> importClauseTree.is(Tree.Kind.IMPORT) && ((ImportTree) importClauseTree).isStatic()) .collect(Collectors.toList()); int staticImportsCount = staticImports.size(); if (staticImportsCount > threshold) { List<JavaFileScannerContext.Location> flow = staticImports.stream() .map(importStatement -> new JavaFileScannerContext.Location("+1", importStatement)) .collect(Collectors.toList()); String message = String.format("Reduce the number of \"static\" imports in this class from %d to the maximum allowed %d.", staticImportsCount, threshold); reportIssue(staticImports.get(0), message, flow, null); } }
@Override public void visitNode(Tree tree) { CompilationUnitTree cut = (CompilationUnitTree) tree; List<ImportClauseTree> staticImports = cut.imports().stream() .filter(importClauseTree -> importClauseTree.is(Tree.Kind.IMPORT) && ((ImportTree) importClauseTree).isStatic()) .collect(Collectors.toList()); int staticImportsCount = staticImports.size(); if (staticImportsCount > threshold) { List<JavaFileScannerContext.Location> flow = staticImports.stream() .map(importStatement -> new JavaFileScannerContext.Location("+1", importStatement)) .collect(Collectors.toList()); String message = String.format("Reduce the number of \"static\" imports in this class from %d to the maximum allowed %d.", staticImportsCount, threshold); reportIssue(staticImports.get(0), message, flow, null); } }
private static int getLine(ImportClauseTree importClauseTree, boolean fromStart) { if (importClauseTree.is(Tree.Kind.IMPORT)) { if (fromStart) { return ((ImportTree) importClauseTree).importKeyword().line(); } else { return ((ImportTree) importClauseTree).semicolonToken().line(); } } return ((EmptyStatementTree) importClauseTree).semicolonToken().line(); }
private static int getLine(ImportClauseTree importClauseTree, boolean fromStart) { if (importClauseTree.is(Tree.Kind.IMPORT)) { if (fromStart) { return ((ImportTree) importClauseTree).importKeyword().line(); } else { return ((ImportTree) importClauseTree).semicolonToken().line(); } } return ((EmptyStatementTree) importClauseTree).semicolonToken().line(); }
ImportTree importTree = null; if (importClauseTree.is(Tree.Kind.IMPORT)) { importTree = (ImportTree) importClauseTree;
ImportTree importTree = null; if (importClauseTree.is(Tree.Kind.IMPORT)) { importTree = (ImportTree) importClauseTree;