List of usage examples for org.eclipse.jdt.core.dom ImportDeclaration toString
@Override public final String toString()
From source file:com.windowtester.eclipse.ui.convert.WTConvertAPIContext.java
License:Open Source License
/** * Construct a new import declaration/*from ww w. j a v a2 s .c o m*/ * * @param typeName the fully qualified type name (not <code>null</code>, not empty) * @param isStatic <code>true</code> if the import should be a static import * @return the import declaration (not <code>null</code>) */ private ImportDeclaration newImport(String typeName, boolean isStatic) { ImportDeclaration newImport = compUnit.getAST().newImportDeclaration(); newImport.setStatic(isStatic); int start = 7; // 7 = position after the "import" keyword and one space if (isStatic) start += 7; // add length of "static" keyword and one space newImport.setName(newName(typeName, start)); newImport.setSourceRange(0, newImport.toString().trim().length()); return newImport; }
From source file:com.windowtester.eclipse.ui.convert.WTConvertAPIContextNodeListTest.java
License:Open Source License
public void testInsert() throws Exception { testAPI("contextAPI/nodelist", "NewContactSwingTest.txt", "insert", new APITest() { public void before(WTConvertAPIContext context) { }/* w w w .j av a 2 s .c o m*/ @SuppressWarnings("unchecked") public void test(WTConvertAPIContext context, CompilationUnit compUnit) { Name newName = context.newName("com.windowtester.runtime.swing.locator.JButtonLocator", 7); ImportDeclaration newImport = compUnit.getAST().newImportDeclaration(); newImport.setName(newName); newImport.setSourceRange(0, newImport.toString().trim().length()); context.insert(compUnit, compUnit.imports(), 0, newImport); } public void after(WTConvertAPIContext context) { } }); }
From source file:org.evosuite.junit.TestExtractingVisitor.java
License:Open Source License
/** {@inheritDoc} */ @Override//ww w . ja v a2s. co m public boolean visit(ImportDeclaration importDeclaration) { String[] importParts = importDeclaration.toString().split(" "); String fullImport = importParts[importParts.length - 1].replace(";", "").trim(); if (fullImport.contains("$")) { imports.put(fullImport.split("$")[1], fullImport); } else { String[] identifiers = fullImport.split("\\."); imports.put(identifiers[identifiers.length - 1], fullImport); } return false; }
From source file:ptolemy.backtrack.eclipse.ast.ASTFormatter.java
License:Open Source License
/** Visit an ast node, and return whether its children should be further * visited.//w w w .j av a 2s. c o m * * @param node The AST node. * @return Whether its children should be further visited. */ public boolean visit(CompilationUnit node) { // Set up the comment iterator. List comments = node.getCommentList(); if (!comments.isEmpty()) { _commentIterator = comments.iterator(); try { _nextComment(); } catch (IOException e) { throw new ASTIORuntimeException(e); } } // Sort all the importations. List imports = node.imports(); int length = imports.size(); AST ast = node.getAST(); for (int i = 0; i < (length - 1); i++) { for (int j = i + 1; j < length; j++) { ImportDeclaration import1 = (ImportDeclaration) imports.get(i); ImportDeclaration import2 = (ImportDeclaration) imports.get(j); if (import1.toString().compareTo(import2.toString()) > 0) { // Swap. imports.remove(j); imports.remove(i); imports.add(i, ASTNode.copySubtree(ast, import2)); imports.add(j, ASTNode.copySubtree(ast, import1)); } } } if (node.getPackage() != null) { node.getPackage().accept(this); } for (Iterator it = node.imports().iterator(); it.hasNext();) { ImportDeclaration d = (ImportDeclaration) it.next(); d.accept(this); } _output("\n"); for (Iterator it = node.types().iterator(); it.hasNext();) { AbstractTypeDeclaration d = (AbstractTypeDeclaration) it.next(); d.accept(this); } return false; }
From source file:tubame.wsearch.logics.analyzer.JavaAnalyzer.java
License:Apache License
/** * It is called automatically when parsing the Java source code.<br/> * The overriding a method ASTVisitor to extract the import class.<br/> * This method does not cause the user to call.<br/> * //from w ww . j a v a 2s .c o m * @param node * Node to be analyzed by visit * @return Whether to continue the code analysis continues */ @Override public boolean visit(final ImportDeclaration node) { String fullname = node.getName().getFullyQualifiedName(); if (node.toString().contains("*")) { fullname += ".*"; } if (node.isStatic()) { this.staticImportList.add(fullname); fullname = fullname.substring(0, fullname.lastIndexOf('.')); } if (fullname != null) { putResultMap(fullname, node); } return false; }