use of org.eclipse.jdt.core.dom.ImportDeclaration in project AutoRefactor by JnRouvignac.
the class ReplaceQualifiedNamesBySimpleNamesRefactoring method visit.
@Override
public boolean visit(TypeDeclaration node) {
final ITypeBinding typeBinding = node.resolveBinding();
if (typeBinding != null && !typeBinding.isNested() && node.getParent() instanceof CompilationUnit) {
final CompilationUnit compilationUnit = (CompilationUnit) node.getParent();
for (final ImportDeclaration importDecl : imports(compilationUnit)) {
readImport(importDecl);
}
importTypesFromPackage("java.lang", compilationUnit);
node.accept(new NamesCollector());
}
return VISIT_SUBTREE;
}
use of org.eclipse.jdt.core.dom.ImportDeclaration in project bndtools by bndtools.
the class NewTypeWizardPage method removeUnusedImports.
private void removeUnusedImports(ICompilationUnit cu, Set<String> existingImports, boolean needsSave) throws CoreException {
ASTParser parser = ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL);
parser.setSource(cu);
parser.setResolveBindings(true);
CompilationUnit root = (CompilationUnit) parser.createAST(null);
if (root.getProblems().length == 0) {
return;
}
@SuppressWarnings("unchecked") 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) {
// not visible problems hide unused -> remove both
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()) {
//$NON-NLS-1$
name += ".*";
}
if (decl.isStatic()) {
imports.removeStaticImport(name);
} else {
imports.removeImport(name);
}
}
break;
}
}
}
}
}
imports.create(needsSave, null);
}
use of org.eclipse.jdt.core.dom.ImportDeclaration in project flux by eclipse.
the class ScopeAnalyzer method getUsedVariableNames.
public Collection<String> getUsedVariableNames(int offset, int length) {
HashSet<String> result = new HashSet<String>();
IBinding[] bindingsBefore = getDeclarationsInScope(offset, VARIABLES);
for (int i = 0; i < bindingsBefore.length; i++) {
result.add(bindingsBefore[i].getName());
}
IBinding[] bindingsAfter = getDeclarationsAfter(offset + length, VARIABLES);
for (int i = 0; i < bindingsAfter.length; i++) {
result.add(bindingsAfter[i].getName());
}
List<ImportDeclaration> imports = fRoot.imports();
for (int i = 0; i < imports.size(); i++) {
ImportDeclaration decl = imports.get(i);
if (decl.isStatic() && !decl.isOnDemand()) {
result.add(ASTNodes.getSimpleNameIdentifier(decl.getName()));
}
}
return result;
}
use of org.eclipse.jdt.core.dom.ImportDeclaration in project che by eclipse.
the class UnusedCodeFix method createRemoveUnusedImportFix.
public static UnusedCodeFix createRemoveUnusedImportFix(CompilationUnit compilationUnit, IProblemLocation problem) {
if (isUnusedImport(problem)) {
ImportDeclaration node = getImportDeclaration(problem, compilationUnit);
if (node != null) {
String label = FixMessages.UnusedCodeFix_RemoveImport_description;
RemoveImportOperation operation = new RemoveImportOperation(node);
Map<String, String> options = new Hashtable<String, String>();
options.put(CleanUpConstants.REMOVE_UNUSED_CODE_IMPORTS, CleanUpOptions.TRUE);
return new UnusedCodeFix(label, compilationUnit, new CompilationUnitRewriteOperation[] { operation }, options);
}
}
return null;
}
use of org.eclipse.jdt.core.dom.ImportDeclaration in project che by eclipse.
the class ScopeAnalyzer method getUsedVariableNames.
public Collection<String> getUsedVariableNames(int offset, int length) {
HashSet<String> result = new HashSet<String>();
IBinding[] bindingsBefore = getDeclarationsInScope(offset, VARIABLES);
for (int i = 0; i < bindingsBefore.length; i++) {
result.add(bindingsBefore[i].getName());
}
IBinding[] bindingsAfter = getDeclarationsAfter(offset + length, VARIABLES);
for (int i = 0; i < bindingsAfter.length; i++) {
result.add(bindingsAfter[i].getName());
}
List<ImportDeclaration> imports = fRoot.imports();
for (int i = 0; i < imports.size(); i++) {
ImportDeclaration decl = imports.get(i);
if (decl.isStatic() && !decl.isOnDemand()) {
result.add(ASTNodes.getSimpleNameIdentifier(decl.getName()));
}
}
return result;
}
Aggregations