List of usage examples for org.eclipse.jdt.core.dom ImportDeclaration isStatic
boolean isStatic
To view the source code for org.eclipse.jdt.core.dom ImportDeclaration isStatic.
Click Source Link
From source file:at.bestsolution.fxide.jdt.corext.dom.ASTFlattener.java
License:Open Source License
@Override public boolean visit(ImportDeclaration node) { this.fBuffer.append("import ");//$NON-NLS-1$ if (node.getAST().apiLevel() >= JLS3) { if (node.isStatic()) { this.fBuffer.append("static ");//$NON-NLS-1$ }/* w ww . ja v a2 s . c om*/ } node.getName().accept(this); if (node.isOnDemand()) { this.fBuffer.append(".*");//$NON-NLS-1$ } this.fBuffer.append(";");//$NON-NLS-1$ return false; }
From source file:boa.datagen.util.Java7Visitor.java
License:Apache License
@Override public boolean visit(CompilationUnit node) { // b.setPosition(pos.build()); PackageDeclaration pkg = node.getPackage(); if (pkg == null) { b.setName(""); } else {/*from w w w .j a va 2 s. co m*/ b.setName(pkg.getName().getFullyQualifiedName()); for (Object a : pkg.annotations()) { ((Annotation) a).accept(this); b.addModifiers(modifiers.pop()); } } for (Object i : node.imports()) { ImportDeclaration id = (ImportDeclaration) i; String imp = ""; if (id.isStatic()) imp += "static "; imp += id.getName().getFullyQualifiedName(); if (id.isOnDemand()) imp += ".*"; imports.add(imp); } for (Object t : node.types()) { declarations.push(new ArrayList<boa.types.Ast.Declaration>()); ((AbstractTypeDeclaration) t).accept(this); for (boa.types.Ast.Declaration d : declarations.pop()) b.addDeclarations(d); } for (Object c : node.getCommentList()) ((org.eclipse.jdt.core.dom.Comment) c).accept(this); return false; }
From source file:coloredide.utils.CopiedNaiveASTFlattener.java
License:Open Source License
public boolean visit(ImportDeclaration node) { printIndent();//ww w . j av a 2s . c o m this.buffer.append("import ");//$NON-NLS-1$ if (node.getAST().apiLevel() >= AST.JLS3) { if (node.isStatic()) { this.buffer.append("static ");//$NON-NLS-1$ } } node.getName().accept(this); if (node.isOnDemand()) { this.buffer.append(".*");//$NON-NLS-1$ } this.buffer.append(";\n");//$NON-NLS-1$ return false; }
From source file:com.google.devtools.j2objc.jdt.JdtJ2ObjCIncompatibleStripper.java
License:Apache License
private JdtJ2ObjCIncompatibleStripper(CompilationUnit unit) { @SuppressWarnings("unchecked") List<ImportDeclaration> imports = unit.imports(); for (ImportDeclaration importNode : imports) { String name = getLastComponent(importNode.getName()); if (importNode.isStatic()) { unusedStaticImports.put(name, importNode); } else {/*www.j a v a 2 s .co m*/ unusedImports.put(name, importNode); } } }
From source file:com.google.devtools.j2objc.pipeline.J2ObjCIncompatibleStripper.java
License:Apache License
private J2ObjCIncompatibleStripper(CompilationUnit unit) { @SuppressWarnings("unchecked") List<ImportDeclaration> imports = unit.imports(); for (ImportDeclaration importNode : imports) { String name = getLastComponent(importNode.getName()); if (importNode.isStatic()) { unusedStaticImports.put(name, importNode); } else {/* w w w. j av a 2s. c o m*/ unusedImports.put(name, importNode); } } }
From source file:com.google.gdt.eclipse.appengine.rpc.util.CompilationUnitCreator.java
License:Open Source License
@SuppressWarnings("unchecked") private void removeUnusedImports(ICompilationUnit cu, Set<String> existingImports, boolean needsSave) throws CoreException { ASTParser parser = ASTParser.newParser(AST.JLS3); parser.setSource(cu);//w w w . jav a 2s . c o m parser.setResolveBindings(true); CompilationUnit root = (CompilationUnit) parser.createAST(null); if (root.getProblems().length == 0) { return; } List<ImportDeclaration> importsDecls = root.imports(); if (importsDecls.isEmpty()) { return; } ImportsManager imports = new ImportsManager(root); int importsEnd = ASTNodes.getExclusiveEnd((ASTNode) importsDecls.get(importsDecls.size() - 1)); IProblem[] problems = root.getProblems(); for (int i = 0; i < problems.length; i++) { IProblem curr = problems[i]; if (curr.getSourceEnd() < importsEnd) { int id = curr.getID(); if (id == IProblem.UnusedImport || id == IProblem.NotVisibleType) { int pos = curr.getSourceStart(); for (int k = 0; k < importsDecls.size(); k++) { ImportDeclaration decl = importsDecls.get(k); if (decl.getStartPosition() <= pos && pos < decl.getStartPosition() + decl.getLength()) { if (existingImports.isEmpty() || !existingImports.contains(ASTNodes.asString(decl))) { String name = decl.getName().getFullyQualifiedName(); if (decl.isOnDemand()) { name += ".*"; //$NON-NLS-1$ } if (decl.isStatic()) { imports.removeStaticImport(name); } else { imports.removeImport(name); } } break; } } } } } imports.create(needsSave, null); }
From source file:com.google.gdt.eclipse.appengine.rpc.wizards.helpers.RpcServiceLayerCreator.java
License:Open Source License
@SuppressWarnings("unchecked") private void removeUnusedImports(ICompilationUnit cu, Set<String> existingImports, boolean needsSave) throws CoreException { ASTParser parser = ASTParser.newParser(AST.JLS3); parser.setSource(cu);/* w w w . jav a2 s . c om*/ parser.setResolveBindings(true); CompilationUnit root = (CompilationUnit) parser.createAST(null); if (root.getProblems().length == 0) { return; } List<ImportDeclaration> importsDecls = root.imports(); if (importsDecls.isEmpty()) { return; } ImportsManager imports = new ImportsManager(root); int importsEnd = ASTNodes.getExclusiveEnd(importsDecls.get(importsDecls.size() - 1)); IProblem[] problems = root.getProblems(); for (int i = 0; i < problems.length; i++) { IProblem curr = problems[i]; if (curr.getSourceEnd() < importsEnd) { int id = curr.getID(); if (id == IProblem.UnusedImport || id == IProblem.NotVisibleType) { int pos = curr.getSourceStart(); for (int k = 0; k < importsDecls.size(); k++) { ImportDeclaration decl = importsDecls.get(k); if (decl.getStartPosition() <= pos && pos < decl.getStartPosition() + decl.getLength()) { if (existingImports.isEmpty() || !existingImports.contains(ASTNodes.asString(decl))) { String name = decl.getName().getFullyQualifiedName(); if (decl.isOnDemand()) { name += ".*"; //$NON-NLS-1$ } if (decl.isStatic()) { imports.removeStaticImport(name); } else { imports.removeImport(name); } } break; } } } } } imports.create(needsSave, null); }
From source file:com.google.googlejavaformat.java.JavaInputAstVisitor.java
License:Apache License
/** Visitor method for {@link ImportDeclaration}s. */ @Override//from ww w .ja v a 2 s . co m public boolean visit(ImportDeclaration node) { sync(node); token("import"); builder.space(); if (node.isStatic()) { token("static"); builder.space(); } visitName(node.getName(), BreakOrNot.NO); if (node.isOnDemand()) { token("."); token("*"); } token(";"); return false; }
From source file:com.google.googlejavaformat.java.RemoveUnusedImports.java
License:Open Source License
/** Construct replacements to fix unused imports. */ private static RangeMap<Integer, String> buildReplacements(String contents, CompilationUnit unit, Set<String> usedNames, Multimap<String, ASTNode> usedInJavadoc, JavadocOnlyImports javadocOnlyImports) { RangeMap<Integer, String> replacements = TreeRangeMap.create(); for (ImportDeclaration importTree : (List<ImportDeclaration>) unit.imports()) { String simpleName = importTree.getName() instanceof QualifiedName ? ((QualifiedName) importTree.getName()).getName().toString() : importTree.getName().toString(); if (usedNames.contains(simpleName)) { continue; }/*from ww w . ja v a 2s . c o m*/ if (usedInJavadoc.containsKey(simpleName) && javadocOnlyImports == JavadocOnlyImports.KEEP) { continue; } // delete the import int endPosition = importTree.getStartPosition() + importTree.getLength(); endPosition = Math.max(CharMatcher.isNot(' ').indexIn(contents, endPosition), endPosition); String sep = System.lineSeparator(); if (endPosition + sep.length() < contents.length() && contents.subSequence(endPosition, endPosition + sep.length()).equals(sep)) { endPosition += sep.length(); } replacements.put(Range.closedOpen(importTree.getStartPosition(), endPosition), ""); // fully qualify any javadoc references with the same simple name as a deleted // non-static import if (!importTree.isStatic()) { for (ASTNode doc : usedInJavadoc.get(simpleName)) { String replaceWith = importTree.getName().toString(); Range<Integer> range = Range.closedOpen(doc.getStartPosition(), doc.getStartPosition() + doc.getLength()); replacements.put(range, replaceWith); } } } return replacements; }
From source file:com.intel.ide.eclipse.mpt.ast.UnresolvedElementsSubProcessor.java
License:Open Source License
public static void importNotFoundProposals(IInvocationContext context, IProblemLocation problem, Map<String, LinkedCorrectionProposal> proposals) throws CoreException { ICompilationUnit cu = context.getCompilationUnit(); ASTNode selectedNode = problem.getCoveringNode(context.getASTRoot()); if (selectedNode == null) { return;/*from w ww.j a v a 2 s . co m*/ } ImportDeclaration importDeclaration = (ImportDeclaration) ASTNodes.getParent(selectedNode, ASTNode.IMPORT_DECLARATION); if (importDeclaration == null) { return; } if (!importDeclaration.isOnDemand()) { Name name = importDeclaration.getName(); if (importDeclaration.isStatic() && name.isQualifiedName()) { name = ((QualifiedName) name).getQualifier(); } int kind = JavaModelUtil.is50OrHigher(cu.getJavaProject()) ? SimilarElementsRequestor.REF_TYPES : SimilarElementsRequestor.CLASSES | SimilarElementsRequestor.INTERFACES; UnresolvedElementsSubProcessor.addNewTypeProposals(cu, name, kind, IProposalRelevance.IMPORT_NOT_FOUND_NEW_TYPE, proposals); } }