@Override public List<ImportDeclaration> getImports() { return compilationUnit.getImports(); }
fileIdentifier.substring(fileIdentifier.lastIndexOf(File.separator) + 1, fileIdentifier.lastIndexOf(".")); for (final TypeDeclaration typeDeclaration : compilationUnit.getTypes()) { if (typeName.equals(typeDeclaration.getName())) { return new JavaType(compilationUnit.getPackage().getName().getName() + "." + typeDeclaration.getName());
@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(); }
if (!compilationUnit.getPackage().getName().getName() .equals(cidCompilationUnit.getPackage().getName().getName())) { compilationUnit.setPackage(cidCompilationUnit.getPackage()); return compilationUnit.toString();
public Boolean visit(CompilationUnit n1, Node arg) { CompilationUnit n2 = (CompilationUnit) arg; if (!nodeEquals(n1.getPackage(), n2.getPackage())) { return Boolean.FALSE; } if (!nodesEquals(n1.getImports(), n2.getImports())) { return Boolean.FALSE; } if (!nodesEquals(n1.getTypes(), n2.getTypes())) { return Boolean.FALSE; } return Boolean.TRUE; }
public Node visit(CompilationUnit n, A arg) { if (n.getPackage() != null) { n.setPackage((PackageDeclaration) n.getPackage().accept(this, arg)); } List<ImportDeclaration> imports = n.getImports(); if (imports != null) { for (int i = 0; i < imports.size(); i++) { imports.set(i, (ImportDeclaration) imports.get(i).accept(this, arg)); } removeNulls(imports); } List<TypeDeclaration> types = n.getTypes(); if (types != null) { for (int i = 0; i < types.size(); i++) { types.set(i, (TypeDeclaration) types.get(i).accept(this, arg)); } removeNulls(types); } return n; }
@Override public ClassOrInterfaceTypeDetails build() { Validate.notEmpty(compilationUnit.getTypes(), "No types in compilation unit, so unable to continue parsing"); EnumDeclaration enumClazz = null; final StringBuilder sb = new StringBuilder(compilationUnit.getPackage().getName().toString()); if (name.getEnclosingType() != null) { sb.append(".").append(name.getEnclosingType().getSimpleTypeName()); cidBuilder.setPhysicalTypeCategory(physicalTypeCategory); imports = compilationUnit.getImports(); if (imports == null) { imports = new ArrayList<ImportDeclaration>(); compilationUnit.setImports(imports);
final ClassOrInterfaceTypeDetails cid, final List<BodyDeclaration> parent) { Validate.notNull(compilationUnit.getImports(), "Compilation unit imports should be non-null when producing type '%s'", cid.getName()); for (final ImportMetadata importType : cid.getRegisteredImports()) { compilationUnit.getImports().add(importDeclaration); JavaParserUtils.importTypeIfRequired(cid.getName(), compilationUnit.getImports(), param); final String tempName = Validate.notNull(compilationUnit.getTypes(), "Compilation unit types must not be null when attempting to add '%s'", cid.getName()); compilationUnit.getTypes().add(typeDeclaration); } else { List<Comment> classComments = compilationUnit.getComments(); if (classComments == null || classComments.isEmpty()) { CommentStructure defaultCommentStructure = new CommentStructure(); for (final ImportDeclaration importDeclaration : compilationUnit.getImports()) { JavaPackage importPackage = null; JavaType importType = null; compilationUnit.setImports(imports);
@Override public List<TypeDeclaration> getInnerTypes() { return compilationUnit.getTypes(); }
/** * 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); }
String pkg = compUnit.getPackage().getName().toString(); Path.SRC_MAIN_JAVA, "")), new WSCompilationUnit(new JavaPackage(pkg), type, compUnit.getImports(), new ArrayList<TypeDeclaration>(), PhysicalTypeCategory.CLASS), fields, body);
@Override public final JavaPackage getPackage(final String fileIdentifier) { Validate.notBlank(fileIdentifier, "Compilation unit path required"); Validate.isTrue(new File(fileIdentifier).exists(), "The file doesn't exist"); Validate.isTrue(new File(fileIdentifier).isFile(), "The identifier doesn't represent a file"); try { final File file = new File(fileIdentifier); String typeContents = ""; try { typeContents = FileUtils.readFileToString(file); } catch (final IOException ignored) { } if (StringUtils.isBlank(typeContents)) { return null; } final CompilationUnit compilationUnit = JavaParser.parse(new ByteArrayInputStream(typeContents.getBytes())); if (compilationUnit == null || compilationUnit.getPackage() == null) { return null; } return new JavaPackage(compilationUnit.getPackage().getName().toString()); } catch (final IOException e) { throw new IllegalStateException(e); } catch (final ParseException e) { throw new IllegalStateException("Failed to parse " + fileIdentifier + " : " + e.getMessage()); } } }
public Boolean visit(CompilationUnit n1, Node arg) { CompilationUnit n2 = (CompilationUnit) arg; if (!nodeEquals(n1.getPackage(), n2.getPackage())) { return Boolean.FALSE; } if (!nodesEquals(n1.getImports(), n2.getImports())) { return Boolean.FALSE; } if (!nodesEquals(n1.getTypes(), n2.getTypes())) { return Boolean.FALSE; } return Boolean.TRUE; }
public Node visit(CompilationUnit n, A arg) { if (n.getPackage() != null) { n.setPackage((PackageDeclaration) n.getPackage().accept(this, arg)); } List<ImportDeclaration> imports = n.getImports(); if (imports != null) { for (int i = 0; i < imports.size(); i++) { imports.set(i, (ImportDeclaration) imports.get(i).accept(this, arg)); } removeNulls(imports); } List<TypeDeclaration> types = n.getTypes(); if (types != null) { for (int i = 0; i < types.size(); i++) { types.set(i, (TypeDeclaration) types.get(i).accept(this, arg)); } removeNulls(types); } return n; }
@Override public List<TypeDeclaration> getInnerTypes() { return compilationUnit.getTypes(); }
/** * 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); }
.getPackage().getAnnotations(); for (AnnotationExpr annot : annots) { if (annot instanceof NormalAnnotationExpr) {
public void visit(CompilationUnit n, A arg) { if (n.getPackage() != null) { n.getPackage().accept(this, arg); } if (n.getImports() != null) { for (ImportDeclaration i : n.getImports()) { i.accept(this, arg); } } if (n.getTypes() != null) { for (TypeDeclaration typeDeclaration : n.getTypes()) { typeDeclaration.accept(this, arg); } } }
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; } }
/** * Searches a compilation unit and locates the declaration with the given * type's simple name. * * @param compilationUnit to scan (required) * @param javaType the target to locate (required) * @return the located type declaration or null if it could not be found */ public static TypeDeclaration locateTypeDeclaration(final CompilationUnit compilationUnit, final JavaType javaType) { Validate.notNull(compilationUnit, "Compilation unit required"); Validate.notNull(javaType, "Java type to search for required"); if (compilationUnit.getTypes() == null) { return null; } for (final TypeDeclaration candidate : compilationUnit.getTypes()) { if (javaType.getSimpleTypeName().equals(candidate.getName())) { // We have the required type declaration return candidate; } } return null; }