use of org.eclipse.jdt.core.dom.ImportDeclaration in project AutoRefactor by JnRouvignac.
the class TypeNameDecider method getImportedTypes.
private static NavigableSet<String> getImportedTypes(CompilationUnit cu) {
final TreeSet<String> results = new TreeSet<String>();
for (ImportDeclaration importDecl : imports(cu)) {
Name importName = importDecl.getName();
results.add(importName.getFullyQualifiedName());
}
return results;
}
use of org.eclipse.jdt.core.dom.ImportDeclaration in project liferay-ide by liferay.
the class QuickFixGradleDep method _importNotFoundProposal.
private void _importNotFoundProposal(IInvocationContext context, IProblemLocation problem, Collection<IJavaCompletionProposal> proposals) {
ASTNode selectedNode = problem.getCoveringNode(context.getASTRoot());
if (selectedNode == null) {
return;
}
ImportDeclaration importDeclaration = (ImportDeclaration) ASTNodes.getParent(selectedNode, ASTNode.IMPORT_DECLARATION);
if (importDeclaration == null) {
return;
}
String importName = importDeclaration.getName().toString();
List<String> serviceWrapperList;
List<String> servicesList;
boolean depWrapperCanFixed = false;
try {
serviceWrapperList = TargetPlatformUtil.getServiceWrapperList().getServiceList();
servicesList = TargetPlatformUtil.getServicesList().getServiceList();
if (serviceWrapperList.contains(importName)) {
ServiceContainer bundle = TargetPlatformUtil.getServiceWrapperBundle(importName);
depWrapperCanFixed = true;
_createDepProposal(context, proposals, bundle);
}
if (!depWrapperCanFixed) {
if (servicesList.contains(importName)) {
ServiceContainer bundle = TargetPlatformUtil.getServiceBundle(importName);
_createDepProposal(context, proposals, bundle);
}
}
if (TargetPlatformUtil.getThirdPartyBundleList(importName) != null) {
ServiceContainer bundle = TargetPlatformUtil.getThirdPartyBundleList(importName);
_createDepProposal(context, proposals, bundle);
}
} catch (Exception e) {
GradleCore.logError("Gradle dependence got error", e);
}
}
use of org.eclipse.jdt.core.dom.ImportDeclaration in project liferay-ide by liferay.
the class JavaFileJDT method findImport.
@Override
public SearchResult findImport(String importName) {
List<SearchResult> searchResults = new ArrayList<>();
_ast.accept(new ASTVisitor() {
@Override
public boolean visit(ImportDeclaration node) {
String searchContext = node.getName().toString();
if (importName.equals(searchContext)) {
int startLine = _ast.getLineNumber(node.getName().getStartPosition());
int startOffset = node.getName().getStartPosition();
int endLine = _ast.getLineNumber(node.getName().getStartPosition() + node.getName().getLength());
int endOffset = node.getName().getStartPosition() + node.getName().getLength();
searchResults.add(createSearchResult(searchContext, startOffset, endOffset, startLine, endLine, true));
}
return false;
}
});
if (ListUtil.isNotEmpty(searchResults)) {
return searchResults.get(0);
}
return null;
}
use of org.eclipse.jdt.core.dom.ImportDeclaration in project eclipse.jdt.ls 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<>();
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 whole by wholeplatform.
the class CompilationUnitBuilder method addImportDeclaration.
public boolean addImportDeclaration(String typeName, boolean onDemand, boolean isStatic) {
if (onDemand) {
if (packageImportSet.contains(typeName))
return true;
packageImportSet.add(typeName);
} else {
String packageName = StringUtils.toPackageName(typeName);
String simpleName = StringUtils.toSimpleName(typeName);
if (classImportSet.contains(typeName))
return true;
if (// && StringUtils.isAmbiguous(simpleName)
"java.lang".equals(packageName))
return !simpleNameImportSet.contains(simpleName);
if (!StringUtils.isAmbiguous(simpleName)) {
if (packageNoImportSet.contains(packageName) || simpleNameImportSet.contains(simpleName))
return false;
else if (packageImportSet.contains(packageName)) {
classImportSet.add(typeName);
simpleNameImportSet.add(simpleName);
return true;
}
}
classImportSet.add(typeName);
simpleNameImportSet.add(simpleName);
}
ImportDeclaration id = ast.newImportDeclaration();
id.setName(newQualifiedName(typeName));
id.setOnDemand(onDemand);
id.setStatic(isStatic);
cu.imports().add(id);
return true;
}
Aggregations