@Override ASTNode clone0(AST target) { ImportDeclaration result = new ImportDeclaration(target); result.setSourceRange(getStartPosition(), getLength()); result.setOnDemand(isOnDemand()); if (this.ast.apiLevel >= AST.JLS3_INTERNAL) { result.setStatic(isStatic()); } result.setName((Name) getName().clone(target)); return result; }
@Override public boolean visit(ImportDeclaration node) { if (node.isStatic() || node.isOnDemand()) { staticImports.add(node); } else { QualifiedName qualifiedName = (QualifiedName) node.getName(); String simpleName = simpleName(qualifiedName); if (!importedTypes.containsKey(simpleName)) importedTypes.put(simpleName, qualifiedName); } return true; } };
public boolean visit(ImportDeclaration node) { int s= node.getStartPosition(); int l= node.getLength(); int declarationEnd= s + l; if (fImportContainer == null) fImportContainer= new JavaNode(getCurrentContainer(), JavaNode.IMPORT_CONTAINER, null, s, l); String nm= node.getName().toString(); if (node.isOnDemand()) nm+= ".*"; //$NON-NLS-1$ new JavaNode(fImportContainer, JavaNode.IMPORT, nm, s, l); fImportContainer.setLength(declarationEnd - fImportContainer.getRange().getOffset() + 1); fImportContainer.setAppendPosition(declarationEnd + 2); // FIXME return false; }
public boolean visit(ImportDeclaration node) { String name = node.getName().getFullyQualifiedName(); IValueList importModifiers = new IValueList(values); if (node.getAST().apiLevel() >= AST.JLS3) { if (node.isStatic()) importModifiers.add(constructModifierNode("static")); if (node.isOnDemand()) importModifiers.add(constructModifierNode("onDemand")); } ownValue = constructDeclarationNode("import", values.string(name)); setKeywordParameters("modifiers", importModifiers); return false; }
protected boolean importIsFor(ImportDeclaration importDeclaration, String shortName, boolean static_) { if (importDeclaration.isStatic() != static_) { return false; } String importDeclarationName = importDeclaration.getName().getFullyQualifiedName(); return importDeclarationName.endsWith(shortName); }
private void updateReferenceInImport(ImportDeclaration enclosingImport, ASTNode node, CompilationUnitRewrite rewrite) throws CoreException { final IBinding binding= enclosingImport.resolveBinding(); if (binding instanceof ITypeBinding) { final ITypeBinding type= (ITypeBinding) binding; final ImportRewrite rewriter= rewrite.getImportRewrite(); if (enclosingImport.isStatic()) { final String oldImport= ASTNodes.asString(node); final StringBuffer buffer= new StringBuffer(oldImport); final String typeName= fType.getDeclaringType().getElementName(); final int index= buffer.indexOf(typeName); if (index >= 0) { buffer.delete(index, index + typeName.length() + 1); final String newImport= buffer.toString(); if (enclosingImport.isOnDemand()) { rewriter.removeStaticImport(oldImport + ".*"); //$NON-NLS-1$ rewriter.addStaticImport(newImport, "*", false); //$NON-NLS-1$ } else { rewriter.removeStaticImport(oldImport); final int offset= newImport.lastIndexOf('.'); if (offset >= 0 && offset < newImport.length() - 1) { rewriter.addStaticImport(newImport.substring(0, offset), newImport.substring(offset + 1), false); } } } } else rewriter.removeImport(type.getQualifiedName()); } }
@Override public String getQualifiedName() { return imprt.getName().getFullyQualifiedName(); }
private void processImport(ImportDeclaration node) { String name = node.getName().toString(); if (node.isOnDemand()) { state.getWildcardImports().add(name); String[] resolvedNames = this.wildcardImportResolver.resolve(name); for (String resolvedName : resolvedNames) { processImport(resolvedName, ResolutionStatus.RESOLVED, compilationUnit.getLineNumber(node.getName().getStartPosition()), compilationUnit.getColumnNumber(node.getName().getStartPosition()), node.getName().getLength(), node.toString().trim()); } /* * Also, register the wildcard itself so that we can have rules that match against wildcard imports, event if we do not know what classes * may be contained in that wildcard */ processImport(name + ".*", ResolutionStatus.RESOLVED, compilationUnit.getLineNumber(node.getName().getStartPosition()), compilationUnit.getColumnNumber(node.getName().getStartPosition()), node.getName().getLength(), node.toString().trim()); } else { String clzName = StringUtils.substringAfterLast(name, "."); state.getClassNameLookedUp().add(clzName); state.getClassNameToFQCN().put(clzName, name); ResolutionStatus status = node.resolveBinding() != null ? ResolutionStatus.RESOLVED : ResolutionStatus.RECOVERED; processImport(name, status, compilationUnit.getLineNumber(node.getName().getStartPosition()), compilationUnit.getColumnNumber(node.getName().getStartPosition()), node.getName().getLength(), node.toString().trim()); } }
@Override public boolean visit(ImportDeclaration node) { String name = node.getName().toString(); if (!node.isOnDemand()) { String clzName = StringUtils.substringAfterLast(name, "."); classNameToFullyQualified.put(clzName, name); processInterest(node.getName().toString(), cu.getLineNumber(node.getStartPosition()), "Import of", SourceType.IMPORT); } else { if (lineContainsPackageBlacklist(name)) { for (String knownClz : classNameToFullyQualified.values()) { if (StringUtils.startsWith(knownClz, name)) { processInterest(knownClz, cu.getLineNumber(node.getStartPosition()), "Leads to import of", SourceType.IMPORT); } } } } return true; }
private static String getFullName(ImportDeclaration decl) { String name= decl.getName().getFullyQualifiedName(); return decl.isOnDemand() ? name + ".*": name; //$NON-NLS-1$ }
/** Add imports as single node to foldable tree */ protected void addImportsTree() { @SuppressWarnings("unchecked") final List<ImportDeclaration> imports = (List<ImportDeclaration>) cu.imports(); if (!imports.isEmpty()) { // Get range of imports (starting after first import statement) final ImportDeclaration firstImport = imports.get(0); final int startChar = firstImport.getStartPosition() + firstImport.getLength() - 1; final ImportDeclaration lastImport = imports.get(imports.size() - 1); final int endChar = lastImport.getStartPosition() + lastImport.getLength() - 1; // Add import identifiers to identifier list final List<String> importIdentifiers = Lists.newArrayList(); for (final ImportDeclaration importNode : imports) putTokenizedImports(importIdentifiers, importNode.getName().getFullyQualifiedName()); // Remove import identifiers from root token list tree.getRoot().removeTerms(importIdentifiers); // Add imports as single node to tree final ImportDeclaration node = cu.getAST().newImportDeclaration(); node.setSourceRange(startChar, endChar - startChar + 1); final FoldableNode fn = tree.new FoldableNode(node); fn.addTerms(importIdentifiers); tree.getRoot().addChild(fn); // Add import range to allFolds importBlock = Range.closed(startChar, endChar); allFolds.add(importBlock); } }
void accept0(ASTVisitor visitor) { boolean visitChildren = visitor.visit(this); if (visitChildren) { acceptChild(visitor, getName()); } visitor.endVisit(this); }
int currOffset= curr.getStartPosition(); int currLength= curr.getLength(); int currEndLine= root.getLineNumber(currOffset + currLength); boolean isStatic= curr.isStatic(); String name= getFullName(curr); String packName= getQualifier(curr); int nextOffset= next.getStartPosition(); int nextLength= next.getLength(); int nextOffsetLine= root.getLineNumber(nextOffset); boolean isStatic= curr.isStatic(); String name= getFullName(curr); String packName= getQualifier(curr); this.packageEntries.add(currPackage); int length= this.replaceRange.getOffset() + this.replaceRange.getLength() - curr.getStartPosition(); currPackage.add(new ImportDeclEntry(packName.length(), name, isStatic, new Region(curr.getStartPosition(), length)));
@Override public boolean isStatic() { return imprt.isStatic(); }
@Override public boolean isWildcard() { return imprt.isOnDemand(); }
@Override public boolean visit(ImportDeclaration node) { if (considerBinding(node.resolveBinding(), node)) { fRemoveStaticImport = true; } return false; }
public static StubTypeContext createStubTypeContext(ICompilationUnit cu, CompilationUnit root, int focalPosition) throws CoreException { StringBuilder bufBefore= new StringBuilder(); StringBuilder bufAfter= new StringBuilder(); int introEnd= 0; PackageDeclaration pack= root.getPackage(); if (pack != null) introEnd= pack.getStartPosition() + pack.getLength(); List<ImportDeclaration> imports= root.imports(); if (imports.size() > 0) { ImportDeclaration lastImport= imports.get(imports.size() - 1); introEnd= lastImport.getStartPosition() + lastImport.getLength(); } bufBefore.append(cu.getBuffer().getText(0, introEnd)); fillWithTypeStubs(bufBefore, bufAfter, focalPosition, root.types()); bufBefore.append(' '); bufAfter.insert(0, ' '); return new StubTypeContext(cu, bufBefore.toString(), bufAfter.toString()); }
public static boolean isStaticMethodImport(ImportDeclaration imp, IMethodBinding method) { final IBinding binding = imp.resolveBinding(); switch (binding.getKind()) { case IBinding.TYPE: return imp.isOnDemand() && method.getDeclaringClass() == binding; case IBinding.METHOD: IMethodBinding bound = (IMethodBinding) binding; return bound.getDeclaringClass() == method.getDeclaringClass() && binding.getName().equals(method.getMethodDeclaration().getName()); } return false; }