ImportDeclaration id = ast.newImportDeclaration(); String classToImport = "path.to.some.class"; id.setName(ast.newName(classToImport.split("\\.")));
id.setName(ast.newName(new String[] { "java", "util", "Set" })); cu.imports().add(id);
private ImportDeclaration createImport(String fullName) { ImportDeclaration importDecl = ast.newImportDeclaration(); if (fullName.endsWith(".*")) { fullName = fullName.substring(0, fullName.lastIndexOf('.')); importDecl.setName(ast.newName(fullName)); importDecl.setOnDemand(true); } else { importDecl.setName(ast.newName(fullName)); } return importDecl; }
final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) { if (property == NAME_PROPERTY) { if (get) { return getName(); } else { setName((Name) child); return null; } } // allow default implementation to flag the error return super.internalGetSetChildProperty(property, get, child); }
final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) { if (property == NAME_PROPERTY) { if (get) { return getName(); } else { setName((Name) child); return null; } } // allow default implementation to flag the error return super.internalGetSetChildProperty(property, get, child); }
final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) { if (property == NAME_PROPERTY) { if (get) { return getName(); } else { setName((Name) child); return null; } } // allow default implementation to flag the error return super.internalGetSetChildProperty(property, get, child); }
final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) { if (property == NAME_PROPERTY) { if (get) { return getName(); } else { setName((Name) child); return null; } } // allow default implementation to flag the error return super.internalGetSetChildProperty(property, get, child); }
final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) { if (property == NAME_PROPERTY) { if (get) { return getName(); } else { setName((Name) child); return null; } } // allow default implementation to flag the error return super.internalGetSetChildProperty(property, get, child); }
@Override final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) { if (property == NAME_PROPERTY) { if (get) { return getName(); } else { setName((Name) child); return null; } } // allow default implementation to flag the error return super.internalGetSetChildProperty(property, get, child); }
@SuppressWarnings("unchecked") private void addImport(AST ast, QualifiedName qualifiedName) { ImportDeclaration impDecl = ast.newImportDeclaration(); impDecl.setName(ast.newName(qualifiedName.getFullyQualifiedName())); compilationUnit.imports().add(impDecl); }
private void addImport(AST ast, ASTRewrite rewriter, CompilationUnit astRoot, String imp, boolean isStatic) { ListRewrite lr = rewriter.getListRewrite(astRoot, CompilationUnit.IMPORTS_PROPERTY); ImportDeclaration id = ast.newImportDeclaration(); id.setStatic(isStatic); id.setName(ast.newName(imp)); lr.insertFirst(id, null); }
@Override ASTNode clone0(AST target) { ImportDeclaration result = new ImportDeclaration(target); result.setSourceRange(getStartPosition(), getLength()); result.setOnDemand(isOnDemand()); if (this.ast.apiLevel >= AST.JLS3_INTERNAL) { result.setStatic(isStatic()); } result.setName((Name) getName().clone(target)); return result; }
public ASTRewrite createRewriter(CompilationUnit astRoot, AST ast) { final ASTRewrite result = ASTRewrite.create(astRoot.getAST()); TestNGVisitor visitor = new TestNGVisitor(); astRoot.accept(visitor); // // Add a static import for this method // ListRewrite lr = result.getListRewrite(astRoot, CompilationUnit.IMPORTS_PROPERTY); ImportDeclaration id = ast.newImportDeclaration(); id.setStatic(true); id.setName(ast.newName("org.testng.AssertJUnit." + m_assert)); lr.insertFirst(id, null); return result; }
ASTNode clone0(AST target) { ImportDeclaration result = new ImportDeclaration(target); result.setSourceRange(getStartPosition(), getLength()); result.setOnDemand(isOnDemand()); if (this.ast.apiLevel >= AST.JLS3_INTERNAL) { result.setStatic(isStatic()); } result.setName((Name) getName().clone(target)); return result; }
ASTNode clone0(AST target) { ImportDeclaration result = new ImportDeclaration(target); result.setSourceRange(getStartPosition(), getLength()); result.setOnDemand(isOnDemand()); if (this.ast.apiLevel >= AST.JLS3_INTERNAL) { result.setStatic(isStatic()); } result.setName((Name) getName().clone(target)); return result; }
ASTNode clone0(AST target) { ImportDeclaration result = new ImportDeclaration(target); result.setSourceRange(getStartPosition(), getLength()); result.setOnDemand(isOnDemand()); if (this.ast.apiLevel >= AST.JLS3_INTERNAL) { result.setStatic(isStatic()); } result.setName((Name) getName().clone(target)); return result; }
ASTNode clone0(AST target) { ImportDeclaration result = new ImportDeclaration(target); result.setSourceRange(getStartPosition(), getLength()); result.setOnDemand(isOnDemand()); if (this.ast.apiLevel >= AST.JLS3) { result.setStatic(isStatic()); } result.setName((Name) getName().clone(target)); return result; }
ASTNode clone0(AST target) { ImportDeclaration result = new ImportDeclaration(target); result.setSourceRange(getStartPosition(), getLength()); result.setOnDemand(isOnDemand()); if (this.ast.apiLevel >= AST.JLS3_INTERNAL) { result.setStatic(isStatic()); } result.setName((Name) getName().clone(target)); return result; }