@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); } }
@Override public void visitNode(Tree tree) { ImportTree importTree = (ImportTree) tree; // See RSPEC-2208 : exception with static imports. if (fullQualifiedName(importTree.qualifiedIdentifier()).endsWith(".*") && !importTree.isStatic()) { reportIssue(importTree.qualifiedIdentifier(), "Explicitly import the specific classes needed."); } }
@Override public void visitNode(Tree tree) { ImportTree importTree = (ImportTree) tree; // See RSPEC-2208 : exception with static imports. if (fullQualifiedName(importTree.qualifiedIdentifier()).endsWith(".*") && !importTree.isStatic()) { reportIssue(importTree.qualifiedIdentifier(), "Explicitly import the specific classes needed."); } }
@Override public void visitImport(ImportTree tree) { //reset currentSymbol to default package currentSymbol = symbols.defaultPackage; isStatic = tree.isStatic(); tree.qualifiedIdentifier().accept(this); //Associate symbol only if found. if (currentSymbol.kind < JavaSymbol.ERRONEOUS) { enterSymbol(currentSymbol, tree); } else if (isStatic) { resolved.stream() //add only static fields //TODO accessibility should be checked : package/public .filter(symbol -> Flags.isFlagged(symbol.flags, Flags.STATIC)) //TODO only the first symbol found will be associated with the tree. .forEach(symbol -> enterSymbol(symbol, tree)); } }
@Override public void visitImport(ImportTree tree) { //reset currentSymbol to default package currentSymbol = symbols.defaultPackage; isStatic = tree.isStatic(); tree.qualifiedIdentifier().accept(this); //Associate symbol only if found. if (currentSymbol.kind < JavaSymbol.ERRONEOUS) { enterSymbol(currentSymbol, tree); } else if (isStatic) { resolved.stream() //add only static fields //TODO accessibility should be checked : package/public .filter(symbol -> Flags.isFlagged(symbol.flags, Flags.STATIC)) //TODO only the first symbol found will be associated with the tree. .forEach(symbol -> enterSymbol(symbol, tree)); } }
@Override public void visitImport(ImportTree tree) { //reset currentSymbol to default package currentSymbol = symbols.defaultPackage; isStatic = tree.isStatic(); super.visitImport(tree); //Associate symbol only if found. if (currentSymbol.kind < JavaSymbol.ERRONEOUS) { enterSymbol(currentSymbol, tree); } else { if (isStatic) { for (JavaSymbol symbol : resolved) { //add only static fields //TODO accessibility should be checked : package/public if ((symbol.flags & Flags.STATIC) != 0) { //TODO only the first symbol found will be associated with the tree. enterSymbol(symbol, tree); } } } } }
@Override public void visitImport(ImportTree tree) { //reset currentSymbol to default package currentSymbol = symbols.defaultPackage; isStatic = tree.isStatic(); super.visitImport(tree); //Associate symbol only if found. if (currentSymbol.kind < JavaSymbol.ERRONEOUS) { enterSymbol(currentSymbol, tree); } else { if (isStatic) { for (JavaSymbol symbol : resolved) { //add only static fields //TODO accessibility should be checked : package/public if ((symbol.flags & Flags.STATIC) != 0) { //TODO only the first symbol found will be associated with the tree. enterSymbol(symbol, tree); } } } } }
if (importTree == null || importTree.isStatic()) {
if (importTree == null || importTree.isStatic()) {
currentPackage = concatenate(cut.packageName()); for (ImportTree importTree : cut.imports()) { if (!importTree.isStatic()) { String importName = concatenate((ExpressionTree) importTree.qualifiedIdentifier()); if ("java.lang.*".equals(importName)) {