public final JavaTokenNode getRightBraceToken() { return getChildByRole(Roles.RIGHT_BRACE); }
public final AstNodeCollection<Expression> getElements() { return getChildrenByRole(Roles.EXPRESSION); }
@Override public boolean matches(final INode other, final Match match) { if (other instanceof ArrayInitializerExpression) { final ArrayInitializerExpression otherInitializer = (ArrayInitializerExpression) other; return !otherInitializer.isNull() && getElements().matches(otherInitializer.getElements(), match); } return false; }
final ArrayInitializerExpression initializer = new ArrayInitializerExpression(); final AstNodeCollection<Expression> elements = initializer.getElements();
@Override public Void visitArrayCreationExpression(final ArrayCreationExpression node, final Void ignored) { startNode(node); boolean needType = true; if (node.getDimensions().isEmpty() && node.getType() != null && (node.getParent() instanceof ArrayInitializerExpression || node.getParent() instanceof VariableInitializer)) { needType = false; } if (needType) { writeKeyword(ArrayCreationExpression.NEW_KEYWORD_ROLE); node.getType().acceptVisitor(this, ignored); for (final Expression dimension : node.getDimensions()) { writeToken(Roles.LEFT_BRACKET); dimension.acceptVisitor(this, ignored); writeToken(Roles.RIGHT_BRACKET); } for (final ArraySpecifier specifier : node.getAdditionalArraySpecifiers()) { specifier.acceptVisitor(this, ignored); } if (node.getInitializer() != null && !node.getInitializer().isNull()) { space(); } } node.getInitializer().acceptVisitor(this, ignored); endNode(node); return null; }
public ArrayInitializerExpression(final Expression... elements) { super( Expression.MYSTERY_OFFSET); // Don't care about this expression's line #, just care // about the line #s of individual Expressions in it. if (elements != null) { Collections.addAll(getElements(), elements); } }
@Override public Void visitArrayInitializerExpression(final ArrayInitializerExpression node, final Void data) { super.visitArrayInitializerExpression(node, data); final ArrayCreationExpression creation = firstOrDefault(ofType(node.getAncestors(), ArrayCreationExpression.class)); if (creation == null || !creation.getAdditionalArraySpecifiers().hasSingleElement()) { return null; } for (final Expression element : node.getElements()) { addCastForAssignment(creation.getType(), element); } return null; }
@Override public boolean matches(final INode other, final Match match) { if (other instanceof ArrayCreationExpression) { final ArrayCreationExpression otherExpression = (ArrayCreationExpression) other; return !otherExpression.isNull() && getType().matches(otherExpression.getType(), match) && getDimensions().matches(otherExpression.getDimensions(), match) && getInitializer().matches(otherExpression.getInitializer(), match) && getAdditionalArraySpecifiers().matches(otherExpression.getAdditionalArraySpecifiers(), match); } return false; } }
@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); }
arrayCreation.setInitializer(new ArrayInitializerExpression(arguments));
final ArrayInitializerExpression initializer = new ArrayInitializerExpression(); final AstNodeCollection<Expression> elements = initializer.getElements();
@Override public Void visitArrayCreationExpression(final ArrayCreationExpression node, final Void ignored) { startNode(node); boolean needType = true; if (node.getDimensions().isEmpty() && node.getType() != null && (node.getParent() instanceof ArrayInitializerExpression || node.getParent() instanceof VariableInitializer)) { needType = false; } if (needType) { writeKeyword(ArrayCreationExpression.NEW_KEYWORD_ROLE); node.getType().acceptVisitor(this, ignored); for (final Expression dimension : node.getDimensions()) { writeToken(Roles.LEFT_BRACKET); dimension.acceptVisitor(this, ignored); writeToken(Roles.RIGHT_BRACKET); } for (final ArraySpecifier specifier : node.getAdditionalArraySpecifiers()) { specifier.acceptVisitor(this, ignored); } if (node.getInitializer() != null && !node.getInitializer().isNull()) { space(); } } node.getInitializer().acceptVisitor(this, ignored); endNode(node); return null; }
public ArrayInitializerExpression(final Expression... elements) { super( Expression.MYSTERY_OFFSET); // Don't care about this expression's line #, just care // about the line #s of individual Expressions in it. if (elements != null) { Collections.addAll(getElements(), elements); } }
@Override public boolean matches(final INode other, final Match match) { if (other instanceof ArrayCreationExpression) { final ArrayCreationExpression otherExpression = (ArrayCreationExpression) other; return !otherExpression.isNull() && getType().matches(otherExpression.getType(), match) && getDimensions().matches(otherExpression.getDimensions(), match) && getInitializer().matches(otherExpression.getInitializer(), match) && getAdditionalArraySpecifiers().matches(otherExpression.getAdditionalArraySpecifiers(), match); } return false; } }
@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); }
arrayCreation.setInitializer(new ArrayInitializerExpression(arguments));
@Override public boolean matches(final INode other, final Match match) { if (other instanceof ArrayInitializerExpression) { final ArrayInitializerExpression otherInitializer = (ArrayInitializerExpression) other; return !otherInitializer.isNull() && getElements().matches(otherInitializer.getElements(), match); } return false; }
final ArrayInitializerExpression initializer = new ArrayInitializerExpression(); final AstNodeCollection<Expression> elements = initializer.getElements();
@Override public Void visitArrayCreationExpression(final ArrayCreationExpression node, final Void ignored) { startNode(node); boolean needType = true; if (node.getDimensions().isEmpty() && node.getType() != null && (node.getParent() instanceof ArrayInitializerExpression || node.getParent() instanceof VariableInitializer)) { needType = false; } if (needType) { writeKeyword(ArrayCreationExpression.NEW_KEYWORD_ROLE); node.getType().acceptVisitor(this, ignored); for (final Expression dimension : node.getDimensions()) { writeToken(Roles.LEFT_BRACKET); dimension.acceptVisitor(this, ignored); writeToken(Roles.RIGHT_BRACKET); } for (final ArraySpecifier specifier : node.getAdditionalArraySpecifiers()) { specifier.acceptVisitor(this, ignored); } if (node.getInitializer() != null && !node.getInitializer().isNull()) { space(); } } node.getInitializer().acceptVisitor(this, ignored); endNode(node); return null; }
public ArrayInitializerExpression(final Expression... elements) { super( Expression.MYSTERY_OFFSET); // Don't care about this expression's line #, just care // about the line #s of individual Expressions in it. if (elements != null) { Collections.addAll(getElements(), elements); } }