@Override public Void visitIndexerExpression(final IndexerExpression node, final Void data) { parenthesizeIfRequired(node.getTarget(), PRIMARY); if (node.getTarget() instanceof ArrayCreationExpression) { final ArrayCreationExpression arrayCreation = (ArrayCreationExpression) node.getTarget(); if (_insertParenthesesForReadability || arrayCreation.getInitializer().isNull()) { // require parentheses for "(new int[1])[0]" parenthesize(arrayCreation); } } return super.visitIndexerExpression(node, data); }
@Override public boolean matches(final INode other, final Match match) { if (other instanceof ObjectCreationExpression) { final ObjectCreationExpression otherExpression = (ObjectCreationExpression) other; return !otherExpression.isNull() && getTarget().matches(otherExpression.getTarget(), match) && getType().matches(otherExpression.getType(), match) && getArguments().matches(otherExpression.getArguments(), match); } return false; } }
@Override public boolean matches(final INode other, final Match match) { if (other instanceof MemberReferenceExpression) { final MemberReferenceExpression otherExpression = (MemberReferenceExpression) other; return !otherExpression.isNull() && getTarget().matches(otherExpression.getTarget(), match) && matchString(getMemberName(), otherExpression.getMemberName()) && getTypeArguments().matches(otherExpression.getTypeArguments(), match); } return false; } }
@Override public boolean matches(final INode other, final Match match) { if (other instanceof TypeParameterDeclaration) { final TypeParameterDeclaration otherDeclaration = (TypeParameterDeclaration) other; return !otherDeclaration.isNull() && matchString(getName(), otherDeclaration.getName()) && getExtendsBound().matches(otherDeclaration.getExtendsBound(), match) && getAnnotations().matches(otherDeclaration.getAnnotations(), match); } return false; } }
public static void replaceAll(final AstNode tree) { for (final AstNode node : tree.getDescendants()) { if (node instanceof CommentStatement) { node.getParent().insertChildBefore( node, new Comment(((CommentStatement) node).getComment()), Roles.COMMENT ); node.remove(); } } }
@Override public boolean matches(final INode other, final Match match) { if (other instanceof InstanceOfExpression) { final InstanceOfExpression otherExpression = (InstanceOfExpression) other; return !otherExpression.isNull() && getExpression().matches(otherExpression.getExpression(), match) && getType().matches(otherExpression.getType(), match); } return false; } }
@Override public boolean matches(final INode other, final Match match) { if (other instanceof SwitchStatement) { final SwitchStatement otherStatement = (SwitchStatement) other; return !otherStatement.isNull() && getExpression().matches(otherStatement.getExpression(), match) && getSwitchSections().matches(otherStatement.getSwitchSections(), match); } return false; } }
@Override public Void visitTypeDeclaration(final TypeDeclaration node, final Void p) { if (!(node.getParent() instanceof CompilationUnit)) { final TypeDefinition type = node.getUserData(Keys.TYPE_DEFINITION); if (type != null && AstBuilder.isMemberHidden(type, context)) { node.remove(); return null; } } return super.visitTypeDeclaration(node, p); }
@Override public boolean matches(final INode other, final Match match) { if (other instanceof SynchronizedStatement) { final SynchronizedStatement otherStatement = (SynchronizedStatement) other; return !otherStatement.isNull() && getExpression().matches(otherStatement.getExpression(), match) && getEmbeddedStatement().matches(otherStatement.getEmbeddedStatement(), match); } return false; } }
@Override public boolean matches(final INode other, final Match match) { if (other instanceof CastExpression) { final CastExpression otherCast = (CastExpression) other; return !otherCast.isNull() && getType().matches(otherCast.getType(), match) && getExpression().matches(otherCast.getExpression(), match); } return false; } }
@Override public boolean matches(final INode other, final Match match) { if (other instanceof Annotation) { final Annotation otherAnnotation = (Annotation) other; return !otherAnnotation.isNull() && getType().matches(otherAnnotation.getType(), match) && getArguments().matches(otherAnnotation.getArguments(), match); } return false; }
@Override public Void visitAssignmentExpression(final AssignmentExpression node, final Void data) { parenthesizeIfRequired(node.getLeft(), ASSIGNMENT + 1); if (_insertParenthesesForReadability) { parenthesizeIfRequired(node.getRight(), RELATIONAL_AND_TYPE_TESTING + 1); } else { parenthesizeIfRequired(node.getRight(), ASSIGNMENT); } return super.visitAssignmentExpression(node, data); } }
@Override public boolean matches(final INode other, final Match match) { if (other instanceof InvocationExpression) { final InvocationExpression otherExpression = (InvocationExpression) other; return getTarget().matches(otherExpression.getTarget(), match) && getArguments().matches(otherExpression.getArguments(), match); } return false; } }
static void setModifiers(final AstNode node, final Collection<Modifier> modifiers) { final AstNodeCollection<JavaModifierToken> modifierTokens = node.getChildrenByRole(MODIFIER_ROLE); modifierTokens.clear(); for (final Modifier modifier : modifiers) { modifierTokens.add(new JavaModifierToken(TextLocation.EMPTY, modifier)); } }
@Override public Void visitFieldDeclaration(final FieldDeclaration node, final Void data) { final FieldDefinition field = node.getUserData(Keys.FIELD_DEFINITION); if (field != null && AstBuilder.isMemberHidden(field, context)) { node.remove(); return null; } return super.visitFieldDeclaration(node, data); }
@Override public boolean matches(final INode other, final Match match) { if (other instanceof AnonymousObjectCreationExpression) { final AnonymousObjectCreationExpression otherExpression = (AnonymousObjectCreationExpression) other; return super.matches(other, match) && getTypeDeclaration().matches(otherExpression.getTypeDeclaration(), match); } return false; } }
@Override public Void visitMemberReferenceExpression(final MemberReferenceExpression node, final Void data) { parenthesizeIfRequired(node.getTarget(), PRIMARY); return super.visitMemberReferenceExpression(node, data); }
@Override public boolean matches(final INode other, final Match match) { if (other instanceof InstanceOfExpression) { final InstanceOfExpression otherExpression = (InstanceOfExpression) other; return !otherExpression.isNull() && getExpression().matches(otherExpression.getExpression(), match) && getType().matches(otherExpression.getType(), match); } return false; } }
@Override public Void visitAssignmentExpression(final AssignmentExpression node, final Void data) { parenthesizeIfRequired(node.getLeft(), ASSIGNMENT + 1); if (_insertParenthesesForReadability) { parenthesizeIfRequired(node.getRight(), RELATIONAL_AND_TYPE_TESTING + 1); } else { parenthesizeIfRequired(node.getRight(), ASSIGNMENT); } return super.visitAssignmentExpression(node, data); } }
@Override public boolean matches(final INode other, final Match match) { if (other instanceof InvocationExpression) { final InvocationExpression otherExpression = (InvocationExpression) other; return getTarget().matches(otherExpression.getTarget(), match) && getArguments().matches(otherExpression.getArguments(), match); } return false; } }