本文整理汇总了Java中org.eclipse.jdt.core.dom.ImportDeclaration.setName方法的典型用法代码示例。如果您正苦于以下问题:Java ImportDeclaration.setName方法的具体用法?Java ImportDeclaration.setName怎么用?Java ImportDeclaration.setName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.core.dom.ImportDeclaration
的用法示例。
在下文中一共展示了ImportDeclaration.setName方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addImportToCompilationUnitIfMissing
import org.eclipse.jdt.core.dom.ImportDeclaration; //导入方法依赖的package包/类
/**
* Adds an import to a compilation unit, if missing
*
* @param node
* @param newImportName
*/
@SuppressWarnings("unchecked")
private static void addImportToCompilationUnitIfMissing(final ASTNode node, final String newImportName) {
final CompilationUnit compilationUnit = (CompilationUnit) node.getRoot();
boolean hasImport = false;
for (final Iterator<?> iterator = compilationUnit.imports().iterator(); iterator.hasNext() && !hasImport;) {
final ImportDeclaration importDeclaration = (ImportDeclaration) iterator.next();
final String importName = importDeclaration.getName().getFullyQualifiedName();
if (importName.equals(newImportName)) {
hasImport = true;
}
}
if (!hasImport) {
final ImportDeclaration newImportDeclaration = node.getAST().newImportDeclaration();
newImportDeclaration.setName(node.getAST().newName(newImportName));
compilationUnit.imports().add(newImportDeclaration);
}
}
示例2: after
import org.eclipse.jdt.core.dom.ImportDeclaration; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void after(CaptureLog log)
{
if(this.isXStreamNeeded)
{
ImportDeclaration id = ast.newImportDeclaration();
id.setName(ast.newName(new String[] { "com", "thoughtworks", "xstream", "XStream" }));
cu.imports().add(id);
// create XSTREAM constant: private static final XStream XSTREAM = new XStream();
final VariableDeclarationFragment vd = ast.newVariableDeclarationFragment();
vd.setName(ast.newSimpleName("XSTREAM"));
final ClassInstanceCreation ci = ast.newClassInstanceCreation();
ci.setType(this.createAstType("XStream", ast));
vd.setInitializer(ci);
final FieldDeclaration xstreamConst = ast.newFieldDeclaration(vd);
xstreamConst.setType(this.createAstType("XStream", ast));
xstreamConst.modifiers().add(ast.newModifier(ModifierKeyword.PRIVATE_KEYWORD));
xstreamConst.modifiers().add(ast.newModifier(ModifierKeyword.STATIC_KEYWORD));
xstreamConst.modifiers().add(ast.newModifier(ModifierKeyword.FINAL_KEYWORD));
td.bodyDeclarations().add(xstreamConst);
this.isXStreamNeeded = false;
}
//-- creates utility method to set field value via reflections
if(this.isSetFieldMethodNeeded)
{
this.createSetFieldMethod(td, cu, ast);
this.isSetFieldMethodNeeded = false;
}
//-- creates utility method to get field value via reflections
if(this.isGetFieldMethodNeeded)
{
this.createGetFieldMethod(td, cu, ast);
this.isGetFieldMethodNeeded = false;
}
//-- creates utility method to call method via reflections
if(this.isCallMethodMethodNeeded)
{
this.createCallMethod(td, cu, ast);
this.isCallMethodMethodNeeded = false;
}
//-- creates utility method to call constructor via reflections
if(this.isNewInstanceMethodNeeded)
{
this.createNewInstanceMethod(td, cu, ast);
this.isNewInstanceMethodNeeded = false;
}
}
示例3: addImports
import org.eclipse.jdt.core.dom.ImportDeclaration; //导入方法依赖的package包/类
public static void addImports(ASTRewrite rewrite, CompilationUnit compilationUnit,
Comparator<? super ImportDeclaration> comparator, boolean staticImports, String... imports) {
checkForNull(comparator, "import comparator");
checkForNull(imports, "imports");
final AST ast = rewrite.getAST();
SortedSet<ImportDeclaration> importDeclarations = new TreeSet<ImportDeclaration>(comparator);
for (String importName : imports) {
ImportDeclaration importDeclaration = ast.newImportDeclaration();
importDeclaration.setName(ast.newName(importName));
importDeclaration.setStatic(staticImports);
importDeclarations.add(importDeclaration);
}
addImports(rewrite, compilationUnit, importDeclarations);
}
示例4: addImport
import org.eclipse.jdt.core.dom.ImportDeclaration; //导入方法依赖的package包/类
private void addImport(AST ast, ListRewrite importRewrite, String fullyQualifierImport) {
ImportDeclaration importDeclaration = ast.newImportDeclaration();
importDeclaration.setName(ast.newName(fullyQualifierImport));
importRewrite.insertLast(importDeclaration, null);
}
示例5: getImportDeclaration
import org.eclipse.jdt.core.dom.ImportDeclaration; //导入方法依赖的package包/类
private ImportDeclaration getImportDeclaration(ASTRewrite rewrite) {
ImportDeclaration newImportDeclaration = rewrite.getAST().newImportDeclaration();
newImportDeclaration.setOnDemand(true);
newImportDeclaration.setName(rewrite.getAST().newName(new String[] { "edu", "cmu", "cs", "aliasjava", "annotations" }));
return newImportDeclaration;
}
示例6: before
import org.eclipse.jdt.core.dom.ImportDeclaration; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void before(CaptureLog log) {
ast = AST.newAST(AST.JLS3);
cu = ast.newCompilationUnit();
// package declaration
final PackageDeclaration p1 = ast.newPackageDeclaration();
p1.setName(ast.newName(packageName.split("\\.")));
cu.setPackage(p1);
// import specifications
ImportDeclaration id = ast.newImportDeclaration();
id.setName(ast.newName(new String[] { "org", "junit", "Test" }));
cu.imports().add(id);
// class declaration
td = ast.newTypeDeclaration();
td.setName(ast.newSimpleName(cuName));
td.modifiers().add(ast.newModifier(Modifier.ModifierKeyword.PUBLIC_KEYWORD));
cu.types().add(td);
// test method construction
final MethodDeclaration md = ast.newMethodDeclaration();
md.setName(ast.newSimpleName("test"));
md.thrownExceptions().add(ast.newSimpleName("Exception"));
// sets @Test annotation to test method
final NormalAnnotation annotation = ast.newNormalAnnotation();
annotation.setTypeName(ast.newSimpleName("Test"));
md.modifiers().add(annotation);
// sets method to public
md.modifiers().add(ast.newModifier(Modifier.ModifierKeyword.PUBLIC_KEYWORD));
td.bodyDeclarations().add(md);
methodBlock = ast.newBlock();
md.setBody(methodBlock);
}
示例7: createImportDeclaration
import org.eclipse.jdt.core.dom.ImportDeclaration; //导入方法依赖的package包/类
private ImportDeclaration createImportDeclaration(AST ast, String name, boolean isStatic) {
ImportDeclaration importDeclaration = ast.newImportDeclaration();
importDeclaration.setName(ast.newName(name));
importDeclaration.setStatic(isStatic);
return importDeclaration;
}