@Override public List<TypeDeclaration> getInnerTypes() { return compilationUnit.getTypes(); }
@Override public List<ImportDeclaration> getImports() { return compilationUnit.getImports(); }
/** * Compare two {@link ImportDeclaration} * * @param declaration1 * @param declaration2 * @return true if are equals */ public static boolean equals(final ImportDeclaration declaration1, final ImportDeclaration declaration2) { return declaration1.isAsterisk() == declaration2.isAsterisk() && declaration1.isStatic() == declaration2.isStatic() && declaration1.getName().getName().equals(declaration2.getName().getName()); }
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());
if (!compilationUnit.getPackage().getName().getName() .equals(cidCompilationUnit.getPackage().getName().getName())) { compilationUnit.setPackage(cidCompilationUnit.getPackage()); return compilationUnit.toString();
@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(); }
return new NameExpr(typeToImport.getNameIncludingTypeParameters()); return new NameExpr(typeToImport.getSimpleTypeName()); return new NameExpr(typeToImport.getSimpleTypeName()); if (typeToImport.getEnclosingType() == null) { typeToImportExpr = new QualifiedNameExpr(new NameExpr(typeToImport.getPackage() .getFullyQualifiedPackageName()), typeToImport.getSimpleTypeName()); } else { typeToImportExpr = new QualifiedNameExpr(new NameExpr(typeToImport.getEnclosingType() .getFullyQualifiedTypeName()), typeToImport.getSimpleTypeName()); final ImportDeclaration newImport = new ImportDeclaration(typeToImportExpr, false, false); if (existingImport.getName().getName().equals(newImport.getName().getName())) { if (isEqual(existingImport.getName(), newImport.getName())) { useSimpleTypeName = true; break; return new NameExpr(typeToImport.toString()); return new NameExpr(typeToImport.getSimpleTypeName()); return new QualifiedNameExpr(new NameExpr(typeToImport.getPackage() .getFullyQualifiedPackageName()), typeToImport.getSimpleTypeName());
/** * Adapt the roo interface to the antlr-java-parser interface * * @param rooComment * @return */ private static Comment adaptComment( final org.springframework.roo.classpath.details.comments.AbstractComment rooComment) { Comment comment; if (rooComment instanceof org.springframework.roo.classpath.details.comments.LineComment) { comment = new LineComment(); } else if (rooComment instanceof org.springframework.roo.classpath.details.comments.JavadocComment) { comment = new JavadocComment(); } else { comment = new BlockComment(); } comment.setContent(rooComment.getComment()); return comment; } }
@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()); } } }
final NameExpr nameExpr = getNameExpr(typeDeclaration.getName()); final JavaType effectiveType = getJavaType(compilationUnitServices, nameExpr, null); final ClassOrInterfaceDeclaration clazz = (ClassOrInterfaceDeclaration) typeDeclaration; final List<TypeParameter> typeParameters = clazz.getTypeParameters(); if (typeParameters != null) { final Set<JavaSymbolName> locatedTypeParameters = new HashSet<JavaSymbolName>(); for (final TypeParameter candidate : typeParameters) { final JavaSymbolName currentTypeParam = new JavaSymbolName(candidate.getName()); locatedTypeParameters.add(currentTypeParam); JavaType javaType = null; if (candidate.getTypeBound() == null) { javaType = new JavaType(OBJECT.getFullyQualifiedTypeName(), 0, DataType.TYPE, currentTypeParam, null); } else { final ClassOrInterfaceType cit = candidate.getTypeBound().get(0); javaType = JavaParserUtils.getJavaTypeNow(compilationUnitServices, cit, locatedTypeParameters);
public static ClassOrInterfaceType getResolvedName(final JavaType target, final JavaType current, final CompilationUnit compilationUnit) { final NameExpr nameExpr = JavaParserUtils.importTypeIfRequired(target, compilationUnit.getImports(), current); final ClassOrInterfaceType resolvedName = JavaParserUtils.getClassOrInterfaceType(nameExpr); if (current.getParameters() != null && current.getParameters().size() > 0) { resolvedName.setTypeArgs(new ArrayList<Type>()); for (final JavaType param : current.getParameters()) { resolvedName.getTypeArgs().add(getResolvedName(target, param, compilationUnit)); } } return resolvedName; }
/** * 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; }
/** * Adapt the any comments to the roo interface * * @param parserNode The antlr-java-parser node from which the comments will * be read * @param commentStructure The roo structure from which to retrieve comments * @return List of comments from the antlr-java-parser package */ public static void updateCommentsToRoo(final CommentStructure commentStructure, final Node parserNode) { // Nothing to do here if (parserNode == null || commentStructure == null) { return; } commentStructure.setBeginComments(adaptToRooComments(parserNode.getBeginComments())); commentStructure.setInternalComments(adaptToRooComments(parserNode.getInternalComments())); commentStructure.setEndComments(adaptToRooComments(parserNode.getEndComments())); }
/** * Adapt the any comments to the antlr-java-parser interface * * @param parserNode The antlr-java-parser node to where the comments will * be set * @param commentStructure The roo structure from which to retrieve comments * @return List of comments from the antlr-java-parser package */ public static void updateCommentsToJavaParser(final Node parserNode, final CommentStructure commentStructure) { // Nothing to do here if (parserNode == null || commentStructure == null) { return; } parserNode.setBeginComments(adaptComments(commentStructure.getBeginComments())); parserNode.setInternalComments(adaptComments(commentStructure.getInternalComments())); parserNode.setEndComments(adaptComments(commentStructure.getEndComments())); }
final NameExpr candidateNameExpr = candidate.getName(); if (!candidate.toString().contains("*")) { Validate.isInstanceOf(QualifiedNameExpr.class, candidateNameExpr, "Expected import '%s' to use a fully-qualified type name", candidate); if (candidateNameExpr.getName().equals(nameExpr.getName())) { return candidate;
/** * Adapt a roo comment to antlr-java-parser comment * * @param antlrComment * @return */ private static org.springframework.roo.classpath.details.comments.AbstractComment adaptToRooComment( final Comment antlrComment) { org.springframework.roo.classpath.details.comments.AbstractComment comment; if (antlrComment instanceof LineComment) { comment = new org.springframework.roo.classpath.details.comments.LineComment(); } else if (antlrComment instanceof JavadocComment) { comment = new org.springframework.roo.classpath.details.comments.JavadocComment(); } else { comment = new org.springframework.roo.classpath.details.comments.BlockComment(); } comment.setComment(antlrComment.getContent()); return comment; }
boolean notFound; final List<TypeDeclaration> cidTypes = new ArrayList<TypeDeclaration>(cidCompilationUnit.getTypes()); for (final Iterator<TypeDeclaration> originalTypestIter = compilationUnit.getTypes().iterator(); originalTypestIter .hasNext();) { final TypeDeclaration originalType = originalTypestIter.next(); for (final Iterator<TypeDeclaration> newTypeIter = cidTypes.iterator(); newTypeIter.hasNext();) { final TypeDeclaration newType = newTypeIter.next(); if (originalType.getName().equals(newType.getName()) && originalType.getClass() == newType.getClass()) { compilationUnit.getTypes().addAll(cidTypes);
@Override public List<TypeDeclaration> getInnerTypes() { return compilationUnit.getTypes(); }
boolean notFound; final List<ImportDeclaration> cidImports = new ArrayList<ImportDeclaration>(); if (cidCompilationUnit.getImports() != null) { cidImports.addAll(cidCompilationUnit.getImports()); if (compilationUnit.getImports() != null) { for (final Iterator<ImportDeclaration> originalImportIter = compilationUnit.getImports().iterator(); originalImportIter.hasNext();) { final ImportDeclaration originalImport = originalImportIter.next(); notFound = true; compilationUnit.getImports().addAll(cidImports);