@Override public Void visitCompilationUnit(final CompilationUnit node, final Void data) { super.visitCompilationUnit(node, data); final Set<String> topLevelTypeNames = new LinkedHashSet<>(); final List<ImportDeclaration> importsToRemove = new ArrayList<>(); for (final AstNode m : node.getChildrenByRole(CompilationUnit.TYPE_ROLE)) { if (m instanceof TypeDeclaration) { topLevelTypeNames.add(((TypeDeclaration) m).getName()); } } for (final ImportDeclaration d : node.getChildrenByRole(CompilationUnit.IMPORT_ROLE)) { final TypeReference importedType = d.getUserData(Keys.TYPE_REFERENCE); if (importedType != null && topLevelTypeNames.contains(importedType.getSimpleName())) { importsToRemove.add(d); } } for (final ImportDeclaration d : importsToRemove) { d.remove(); } return null; }
@Override public Set<Object> visitLocalTypeDeclarationStatement(final LocalTypeDeclarationStatement node, final String name) { final TypeDeclaration typeDeclaration = node.getTypeDeclaration(); if (typeDeclaration.isNull()) { return Collections.emptySet(); } if (StringUtilities.equals(typeDeclaration.getName(), name)) { final TypeDefinition type = typeDeclaration.getUserData(Keys.TYPE_DEFINITION); if (type != null) { return Collections.<Object>singleton(type); } } return searchUpScope( name, typeDeclaration.getUserData(Keys.TYPE_DEFINITION), new LinkedHashSet<String>(), true ); }
@Override public Set<Object> visitLocalTypeDeclarationStatement(final LocalTypeDeclarationStatement node, final String name) { final TypeDeclaration typeDeclaration = node.getTypeDeclaration(); if (typeDeclaration.isNull()) { return Collections.emptySet(); } if (StringUtilities.equals(typeDeclaration.getName(), name)) { final TypeDefinition type = typeDeclaration.getUserData(Keys.TYPE_DEFINITION); if (type != null) { return Collections.<Object>singleton(type); } } return searchUpScope( name, typeDeclaration.getUserData(Keys.TYPE_DEFINITION), new LinkedHashSet<String>(), true ); }
@Override public Set<Object> visitLocalTypeDeclarationStatement(final LocalTypeDeclarationStatement node, final String name) { final TypeDeclaration typeDeclaration = node.getTypeDeclaration(); if (typeDeclaration.isNull()) { return Collections.emptySet(); } if (StringUtilities.equals(typeDeclaration.getName(), name)) { final TypeDefinition type = typeDeclaration.getUserData(Keys.TYPE_DEFINITION); if (type != null) { return Collections.<Object>singleton(type); } } return searchUpScope( name, typeDeclaration.getUserData(Keys.TYPE_DEFINITION), new LinkedHashSet<String>(), true ); }
@Override public boolean matches(final INode other, final Match match) { if (other instanceof TypeDeclaration) { final TypeDeclaration otherDeclaration = (TypeDeclaration) other; return !otherDeclaration.isNull() && _classType == otherDeclaration._classType && matchString(getName(), otherDeclaration.getName()) && matchAnnotationsAndModifiers(otherDeclaration, match) && getTypeParameters().matches(otherDeclaration.getTypeParameters(), match) && getBaseType().matches(otherDeclaration.getBaseType(), match) && getInterfaces().matches(otherDeclaration.getInterfaces(), match) && getMembers().matches(otherDeclaration.getMembers(), match); } return false; }
@Override public boolean matches(final INode other, final Match match) { if (other instanceof TypeDeclaration) { final TypeDeclaration otherDeclaration = (TypeDeclaration) other; return !otherDeclaration.isNull() && _classType == otherDeclaration._classType && matchString(getName(), otherDeclaration.getName()) && matchAnnotationsAndModifiers(otherDeclaration, match) && getTypeParameters().matches(otherDeclaration.getTypeParameters(), match) && getBaseType().matches(otherDeclaration.getBaseType(), match) && getInterfaces().matches(otherDeclaration.getInterfaces(), match) && getMembers().matches(otherDeclaration.getMembers(), match); } return false; }
@Override public boolean matches(final INode other, final Match match) { if (other instanceof TypeDeclaration) { final TypeDeclaration otherDeclaration = (TypeDeclaration) other; return !otherDeclaration.isNull() && _classType == otherDeclaration._classType && matchString(getName(), otherDeclaration.getName()) && matchAnnotationsAndModifiers(otherDeclaration, match) && getTypeParameters().matches(otherDeclaration.getTypeParameters(), match) && getBaseType().matches(otherDeclaration.getBaseType(), match) && getInterfaces().matches(otherDeclaration.getInterfaces(), match) && getMembers().matches(otherDeclaration.getMembers(), match); } return false; }
@Override public Void visitConstructorDeclaration(final ConstructorDeclaration node, final Void ignored) { startNode(node); writeAnnotations(node.getAnnotations(), true); writeModifiers(node.getModifiers()); final AstNode parent = node.getParent(); final TypeDeclaration type = parent instanceof TypeDeclaration ? (TypeDeclaration) parent : null; startNode(node.getNameToken()); writeIdentifier(type != null ? type.getName() : node.getName()); endNode(node.getNameToken()); space(policy.SpaceBeforeConstructorDeclarationParentheses); writeCommaSeparatedListInParenthesis(node.getParameters(), policy.SpaceWithinMethodDeclarationParentheses); final AstNodeCollection<AstType> thrownTypes = node.getThrownTypes(); if (!thrownTypes.isEmpty()) { space(); writeKeyword(MethodDeclaration.THROWS_KEYWORD); writeCommaSeparatedList(thrownTypes); } writeMethodBody(null, node.getBody()); endNode(node); return null; }
@Override public Void visitConstructorDeclaration(final ConstructorDeclaration node, final Void ignored) { startNode(node); writeAnnotations(node.getAnnotations(), true); writeModifiers(node.getModifiers()); final AstNode parent = node.getParent(); final TypeDeclaration type = parent instanceof TypeDeclaration ? (TypeDeclaration) parent : null; startNode(node.getNameToken()); writeIdentifier(type != null ? type.getName() : node.getName()); endNode(node.getNameToken()); space(policy.SpaceBeforeConstructorDeclarationParentheses); writeCommaSeparatedListInParenthesis(node.getParameters(), policy.SpaceWithinMethodDeclarationParentheses); final AstNodeCollection<AstType> thrownTypes = node.getThrownTypes(); if (!thrownTypes.isEmpty()) { space(); writeKeyword(MethodDeclaration.THROWS_KEYWORD); writeCommaSeparatedList(thrownTypes); } writeMethodBody(null, node.getBody()); endNode(node); return null; }
writeIdentifier(type != null ? type.getName() : node.getName()); endNode(node.getNameToken()); space(policy.SpaceBeforeConstructorDeclarationParentheses);