@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; } }
public final AstType getType() { return getChildByRole(Roles.TYPE); }
public final AstNodeCollection<ArraySpecifier> getAdditionalArraySpecifiers() { return getChildrenByRole(ADDITIONAL_ARRAY_SPECIFIER_ROLE); }
@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; }
new ArrayCreationExpression( byteCode.getOffset()); arrayCreation.setType(elementType.clone()); arrayCreation.getDimensions().add(arguments.get(i)); --rank; arrayCreation.getAdditionalArraySpecifiers().add(new ArraySpecifier()); new ArrayCreationExpression( byteCode.getOffset()); arrayCreation.getAdditionalArraySpecifiers().add(new ArraySpecifier()); elementType = elementType.getElementType(); arrayCreation.setType(_astBuilder.convertType(elementType)); arrayCreation.getDimensions().add(arg1); new ArrayCreationExpression( byteCode.getOffset()); arrayCreation.getAdditionalArraySpecifiers().add(new ArraySpecifier()); elementType = elementType.getElementType(); arrayCreation.setType(_astBuilder.convertType(elementType)); arrayCreation.setInitializer(new ArrayInitializerExpression(arguments));
@Override public ResolveResult visitArrayCreationExpression(final ArrayCreationExpression node, final Void data) { final TypeReference elementType = node.getType().toTypeReference(); if (elementType == null) { return null; } final int rank = node.getDimensions().size() + node.getAdditionalArraySpecifiers().size(); TypeReference arrayType = elementType; for (int i = 0; i < rank; i++) { arrayType = arrayType.makeArrayType(); } return new ResolveResult(arrayType); }
final ArrayCreationExpression arrayCreation = new ArrayCreationExpression(Expression.MYSTERY_OFFSET); arrayCreation.getDimensions().add(new IdentifierExpressionBackReference("size").toExpression()); arrayCreation.setType(new NamedNode("type", new AnyNode()).toType());
final MemberReferenceExpression target = (MemberReferenceExpression) node.getTarget(); if (!newArray.getAdditionalArraySpecifiers().hasSingleElement()) { return null; final ArrayInitializerExpression initializer = newArray.getInitializer(); final boolean hasElements = !initializer.isNull() && !initializer.getElements().isEmpty();
@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; }
public final void setInitializer(final ArrayInitializerExpression value) { setChildByRole(INITIALIZER_ROLE, value); }
@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 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; }
new ArrayCreationExpression( byteCode.getOffset()); arrayCreation.setType(elementType.clone()); arrayCreation.getDimensions().add(arguments.get(i)); --rank; arrayCreation.getAdditionalArraySpecifiers().add(new ArraySpecifier()); new ArrayCreationExpression( byteCode.getOffset()); arrayCreation.getAdditionalArraySpecifiers().add(new ArraySpecifier()); elementType = elementType.getElementType(); arrayCreation.setType(_astBuilder.convertType(elementType)); arrayCreation.getDimensions().add(arg1); new ArrayCreationExpression( byteCode.getOffset()); arrayCreation.getAdditionalArraySpecifiers().add(new ArraySpecifier()); elementType = elementType.getElementType(); arrayCreation.setType(_astBuilder.convertType(elementType)); arrayCreation.setInitializer(new ArrayInitializerExpression(arguments));
@Override public ResolveResult visitArrayCreationExpression(final ArrayCreationExpression node, final Void data) { final TypeReference elementType = node.getType().toTypeReference(); if (elementType == null) { return null; } final int rank = node.getDimensions().size() + node.getAdditionalArraySpecifiers().size(); TypeReference arrayType = elementType; for (int i = 0; i < rank; i++) { arrayType = arrayType.makeArrayType(); } return new ResolveResult(arrayType); }
final ArrayCreationExpression arrayCreation = new ArrayCreationExpression(Expression.MYSTERY_OFFSET); arrayCreation.getDimensions().add(new IdentifierExpressionBackReference("size").toExpression()); arrayCreation.setType(new NamedNode("type", new AnyNode()).toType());
final MemberReferenceExpression target = (MemberReferenceExpression) node.getTarget(); if (!newArray.getAdditionalArraySpecifiers().hasSingleElement()) { return null; final ArrayInitializerExpression initializer = newArray.getInitializer(); final boolean hasElements = !initializer.isNull() && !initializer.getElements().isEmpty();
public final void setType(final AstType type) { setChildByRole(Roles.TYPE, type); }
@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 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 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; }