本文整理汇总了Java中japa.parser.ast.CompilationUnit.setTypes方法的典型用法代码示例。如果您正苦于以下问题:Java CompilationUnit.setTypes方法的具体用法?Java CompilationUnit.setTypes怎么用?Java CompilationUnit.setTypes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类japa.parser.ast.CompilationUnit
的用法示例。
在下文中一共展示了CompilationUnit.setTypes方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getCompilationUnitContents
import japa.parser.ast.CompilationUnit; //导入方法依赖的package包/类
public final String getCompilationUnitContents(
final ClassOrInterfaceTypeDetails cid) {
Validate.notNull(cid, "Class or interface type details are required");
// Create a compilation unit to store the type to be created
final CompilationUnit compilationUnit = new CompilationUnit();
// NB: this import list is replaced at the end of this method by a
// sorted version
compilationUnit.setImports(new ArrayList<ImportDeclaration>());
if (!cid.getName().isDefaultPackage()) {
compilationUnit.setPackage(new PackageDeclaration(ASTHelper
.createNameExpr(cid.getName().getPackage()
.getFullyQualifiedPackageName())));
}
// Add the class of interface declaration to the compilation unit
final List<TypeDeclaration> types = new ArrayList<TypeDeclaration>();
compilationUnit.setTypes(types);
updateOutput(compilationUnit, null, cid, null);
return compilationUnit.toString();
}
示例2: addTypeDeclaration
import japa.parser.ast.CompilationUnit; //导入方法依赖的package包/类
/**
* Adds the given type declaration to the compilation unit. The list of
* types will be initialized if it is <code>null</code>.
*
* @param cu
* compilation unit
* @param type
* type declaration
*/
public static void addTypeDeclaration(CompilationUnit cu, TypeDeclaration type) {
List<TypeDeclaration> types = cu.getTypes();
if (types == null) {
types = new ArrayList<TypeDeclaration>();
cu.setTypes(types);
}
types.add(type);
}