@Override 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(); }
/** * 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); }
/** * 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); }
public CompilationUnit adapt(Java7Parser.CompilationUnitContext context, AdapterParameters adapterParameters) { CompilationUnit compilationUnit = new CompilationUnit(); compilationUnit.setPackage(Adapters.getPackageDeclarationContextAdapter().adapt(context.packageDeclaration(), adapterParameters)); List<ImportDeclaration> importDeclarationList = new LinkedList<ImportDeclaration>(); for (Java7Parser.ImportDeclarationContext importDeclarationContext : context.importDeclaration()) { importDeclarationList.add(Adapters.getImportDeclarationContextAdapter().adapt(importDeclarationContext, adapterParameters)); } compilationUnit.setImports(importDeclarationList); List<TypeDeclaration> typeDeclarationList = new LinkedList<TypeDeclaration>(); for (Java7Parser.TypeDeclarationContext typeDeclarationContext : context.typeDeclaration()) { typeDeclarationList.add(Adapters.getTypeDeclarationContextAdapter().adapt(typeDeclarationContext, adapterParameters)); } compilationUnit.setTypes(typeDeclarationList); return compilationUnit; } }
public CompilationUnit adapt(Java7Parser.CompilationUnitContext context, AdapterParameters adapterParameters) { CompilationUnit compilationUnit = new CompilationUnit(); compilationUnit.setPackage(Adapters.getPackageDeclarationContextAdapter().adapt(context.packageDeclaration(), adapterParameters)); List<ImportDeclaration> importDeclarationList = new LinkedList<ImportDeclaration>(); for (Java7Parser.ImportDeclarationContext importDeclarationContext : context.importDeclaration()) { importDeclarationList.add(Adapters.getImportDeclarationContextAdapter().adapt(importDeclarationContext, adapterParameters)); } compilationUnit.setImports(importDeclarationList); List<TypeDeclaration> typeDeclarationList = new LinkedList<TypeDeclaration>(); for (Java7Parser.TypeDeclarationContext typeDeclarationContext : context.typeDeclaration()) { typeDeclarationList.add(Adapters.getTypeDeclarationContextAdapter().adapt(typeDeclarationContext, adapterParameters)); } compilationUnit.setTypes(typeDeclarationList); return compilationUnit; } }