private static ImmutableSet<Symbol> getImportedSymbols( ImportTree importTree, VisitorState state) { if (importTree.isStatic()) { StaticImportInfo staticImportInfo = StaticImports.tryCreate(importTree, state); return staticImportInfo == null ? ImmutableSet.<Symbol>of() : staticImportInfo.members(); } else { @Nullable Symbol importedSymbol = getSymbol(importTree.getQualifiedIdentifier()); return importedSymbol == null ? ImmutableSet.<Symbol>of() : ImmutableSet.of(importedSymbol); } } }
/** Creates a {@link Fix} that replaces wildcard imports. */ static Fix createFix( ImmutableList<ImportTree> wildcardImports, Set<TypeToImport> typesToImport, VisitorState state) { Map<Symbol, List<TypeToImport>> toFix = typesToImport.stream().collect(Collectors.groupingBy(TypeToImport::owner)); final SuggestedFix.Builder fix = SuggestedFix.builder(); for (ImportTree importToDelete : wildcardImports) { String importSpecification = importToDelete.getQualifiedIdentifier().toString(); if (importToDelete.isStatic()) { fix.removeStaticImport(importSpecification); } else { fix.removeImport(importSpecification); } } for (Map.Entry<Symbol, List<TypeToImport>> entry : toFix.entrySet()) { final Symbol owner = entry.getKey(); if (entry.getKey().getKind() != ElementKind.PACKAGE && entry.getValue().size() > MAX_MEMBER_IMPORTS) { qualifiedNameFix(fix, owner, state); } else { for (TypeToImport toImport : entry.getValue()) { toImport.addFix(fix); } } } return fix.build(); }
case COMPILATION_UNIT: for (ImportTree importTree : ((CompilationUnitTree) curr).getImports()) { if (importTree.isStatic() && importTree.getQualifiedIdentifier().getKind() == Kind.MEMBER_SELECT) { MemberSelectTree memberSelectTree =
if (!tree.isStatic()) { return null;
ImmutableSet<Symbol> symbols; if (!tree.isStatic()) { symbol = ASTHelpers.getSymbol(tree.getQualifiedIdentifier()); if (symbol == null || isAcceptableImport(symbol, BAD_NESTED_CLASSES)) {
@Override public String visitImport(ImportTree reference, Void v) { return (reference != null) ? detailedKindString(reference, reference.isStatic() ? "static" : "non-static") : ""; }
@Override public String visitImport(ImportTree reference, Void v) { return (reference != null) ? detailedKindString(reference, reference.isStatic() ? "static" : "non-static") : ""; }
@Override public String visitImport(ImportTree reference, Void v) { return (reference != null) ? detailedKindString(reference, reference.isStatic() ? "static" : "non-static") : ""; }
private void handleUnresolvableImports(Element decl, boolean methodInvocation, boolean removeStarImports) { Name simpleName = decl.getSimpleName(); if (simpleName != null) { Collection<ImportTree> imps = simpleName2UnresolvableImports.get(simpleName.toString()); if (imps != null) { for (ImportTree imp : imps) { if (!methodInvocation || imp.isStatic()) { import2Highlight.remove(imp); } } } else { if (removeStarImports) { //TODO: explain for (ImportTree unresolvable : unresolvablePackageImports) { if (!methodInvocation || unresolvable.isStatic()) { import2Highlight.remove(unresolvable); } } } } } } }
@Override public Void visitImport(ImportTree expected, Tree actual) { Optional<ImportTree> other = checkTypeAndCast(expected, actual); if (!other.isPresent()) { addTypeMismatch(expected, actual); return null; } checkForDiff(expected.isStatic() == other.get().isStatic(), "Expected import to be <%s> but was <%s>.", expected.isStatic() ? "static" : "non-static", other.get().isStatic() ? "static" : "non-static"); scan(expected.getQualifiedIdentifier(), other.get().getQualifiedIdentifier()); return null; }
@Override public Void visitImport(ImportTree expected, Tree actual) { Optional<ImportTree> other = checkTypeAndCast(expected, actual); if (!other.isPresent()) { addTypeMismatch(expected, actual); return null; } checkForDiff(expected.isStatic() == other.get().isStatic(), "Expected import to be <%s> but was <%s>.", expected.isStatic() ? "static" : "non-static", other.get().isStatic() ? "static" : "non-static"); scan(expected.getQualifiedIdentifier(), other.get().getQualifiedIdentifier()); return null; }
@Override public Void visitImport(ImportTree expected, Tree actual) { Optional<ImportTree> other = checkTypeAndCast(expected, actual); if (!other.isPresent()) { addTypeMismatch(expected, actual); return null; } checkForDiff(expected.isStatic() == other.get().isStatic(), "Expected import to be <%s> but was <%s>.", expected.isStatic() ? "static" : "non-static", other.get().isStatic() ? "static" : "non-static"); scan(expected.getQualifiedIdentifier(), other.get().getQualifiedIdentifier()); return null; }
@Override public String visitImport( ImportTree node, Object v ) { StringBuilder out = new StringBuilder(); appendComment( node, out ); out.append( "uses " ); String fqn = node.getQualifiedIdentifier().accept( this, v ); if( node.isStatic() ) { int dot = fqn.lastIndexOf( "." ); fqn = fqn.substring( 0, dot ) + "#" + fqn.substring( dot + 1 ); } out.append( fqn ); out.append( "\n" ); return out.toString(); }
private static ImmutableSet<Symbol> getImportedSymbols( ImportTree importTree, VisitorState state) { if (importTree.isStatic()) { StaticImportInfo staticImportInfo = StaticImports.tryCreate(importTree, state); return staticImportInfo == null ? ImmutableSet.<Symbol>of() : staticImportInfo.members(); } else { @Nullable Symbol importedSymbol = getSymbol(importTree.getQualifiedIdentifier()); return importedSymbol == null ? ImmutableSet.<Symbol>of() : ImmutableSet.of(importedSymbol); } } }
/** Creates a {@link Fix} that replaces wildcard imports. */ static Fix createFix( ImmutableList<ImportTree> wildcardImports, Set<TypeToImport> typesToImport, VisitorState state) { Map<Symbol, List<TypeToImport>> toFix = typesToImport.stream().collect(Collectors.groupingBy(TypeToImport::owner)); final SuggestedFix.Builder fix = SuggestedFix.builder(); for (ImportTree importToDelete : wildcardImports) { String importSpecification = importToDelete.getQualifiedIdentifier().toString(); if (importToDelete.isStatic()) { fix.removeStaticImport(importSpecification); } else { fix.removeImport(importSpecification); } } for (Map.Entry<Symbol, List<TypeToImport>> entry : toFix.entrySet()) { final Symbol owner = entry.getKey(); if (entry.getValue().size() > MAX_MEMBER_IMPORTS) { qualifiedNameFix(fix, owner, state); } else { for (TypeToImport toImport : entry.getValue()) { toImport.addFix(fix); } } } return fix.build(); }
@Override public Void visitImport(ImportTree node, Stack<Tree> p) { if (node.isStatic() && toFind.getModifiers().contains(Modifier.STATIC)) { Tree qualIdent = node.getQualifiedIdentifier(); if (qualIdent.getKind() == Kind.MEMBER_SELECT) { MemberSelectTree mst = (MemberSelectTree) qualIdent; if (toFind.getSimpleName().contentEquals(mst.getIdentifier())) { Element el = info.getTrees().getElement(new TreePath(getCurrentPath(), mst.getExpression())); if (el != null && el.equals(toFind.getEnclosingElement())) { Token<JavaTokenId> t = Utilities.getToken(info, doc, new TreePath(getCurrentPath(), mst)); if (t != null) usages.add(t); } } } } return super.visitImport(node, p); } }
@Override @CheckForNull public Void visitImport (@NonNull final ImportTree node, @NonNull final Map<Pair<BinaryName,String>, UsagesData<String>> p) { this.isStaticImport = node.isStatic(); final Tree qit = node.getQualifiedIdentifier(); isPkgImport = qit.getKind() == Tree.Kind.MEMBER_SELECT && names.asterisk == (((MemberSelectTree)qit).getIdentifier()); final Void ret = super.visitImport(node, p); isStaticImport = isPkgImport = false; return ret; }
@Override public Tree visitImport(ImportTree tree, Void p) { ImportTree n = make.Import(tree.getQualifiedIdentifier(), tree.isStatic()); model.setType(n, model.getType(tree)); comments.copyComments(tree, n); model.setPos(n, model.getPos(tree)); return n; }
@Override public Boolean visitImport(ImportTree node, Void p) { accept(IMPORT); boolean old = continuationIndent; try { continuationIndent = true; space(); if (node.isStatic()) { accept(STATIC); space(); } scan(node.getQualifiedIdentifier(), p); accept(SEMICOLON); } finally { continuationIndent = old; } return true; }
protected final ImportTree rewriteChildren(ImportTree tree) { Tree qualid = translateClassRef(tree.getQualifiedIdentifier()); if (qualid == tree.getQualifiedIdentifier()) qualid = translate(tree.getQualifiedIdentifier()); if (qualid!=tree.getQualifiedIdentifier()) { ImportTree n = make.Import(qualid, tree.isStatic()); model.setType(n, model.getType(tree)); copyCommentTo(tree,n); copyPosTo(tree,n); tree = n; } return tree; }