List of usage examples for org.eclipse.jdt.core.dom ImportDeclaration getParent
public final ASTNode getParent()
null
if this is the root node. From source file:com.windowtester.eclipse.ui.convert.WTConvertAPIContext.java
License:Open Source License
/** * Expand the specified demand import to be zero or more explicit imports * /*from w w w .ja v a 2 s . co m*/ * @param importNode the demand import to be expanded */ @SuppressWarnings("unchecked") public void expandImport(ImportDeclaration importNode) { assertInCompUnit(importNode); if (!importNode.isOnDemand()) throw new IllegalArgumentException("import is not on demand: " + importNode); String packageName = importNode.getName().getFullyQualifiedName(); Collection<String> wtTypeNames = getWTTypesInPackage(packageName); if (wtTypeNames == null) return; Collection<ASTNode> newNodes = new ArrayList<ASTNode>(); for (String typeName : new TreeSet<String>(wtTypeNames)) newNodes.add(newImport(typeName, false)); CompilationUnit compUnit = (CompilationUnit) importNode.getParent(); List<ASTNode> imports = compUnit.imports(); int index = imports.indexOf(importNode); // Intentionally do not use the add/remove import methods // because we are not changing the list of visible types insert(compUnit, imports, index, newNodes); remove(imports, importNode); }
From source file:org.spoofax.interpreter.adapter.ecj.ECJFactory.java
License:LGPL
private ImportDeclaration asImportDeclaration(IStrategoTerm term) { ImportDeclaration x = ((WrappedImportDeclaration) term).getWrappee(); return x.getParent() == null && x.getAST() == ast ? x : (ImportDeclaration) ASTNode.copySubtree(ast, x); }