当前位置: 首页>>代码示例>>Java>>正文


Java ImportDeclaration.setName方法代码示例

本文整理汇总了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);
	}
}
 
开发者ID:awltech,项目名称:eclipse-i18ntools,代码行数:24,代码来源:ResourceBundleWrapper.java

示例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;
	}
}
 
开发者ID:EvoSuite,项目名称:evosuite,代码行数:56,代码来源:JUnitCodeGenerator.java

示例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);
}
 
开发者ID:OpenNTF,项目名称:FindBug-for-Domino-Designer,代码行数:16,代码来源:ASTUtil.java

示例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);
}
 
开发者ID:helospark,项目名称:SparkBuilderGenerator,代码行数:6,代码来源:ImportPopulator.java

示例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;
  }
 
开发者ID:aroog,项目名称:code,代码行数:7,代码来源:SaveAnnotations.java

示例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);
	
}
 
开发者ID:EvoSuite,项目名称:evosuite,代码行数:45,代码来源:JUnitCodeGenerator.java

示例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;
}
 
开发者ID:OpenNTF,项目名称:FindBug-for-Domino-Designer,代码行数:7,代码来源:CreateDoPrivilegedBlockResolution.java


注:本文中的org.eclipse.jdt.core.dom.ImportDeclaration.setName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。