List of usage examples for org.eclipse.jdt.core.dom ArrayCreation ArrayCreation
ArrayCreation(AST ast)
From source file:org.eclipse.jdt.core.dom.ASTConverter.java
License:Open Source License
public ArrayCreation convert(org.eclipse.jdt.internal.compiler.ast.ArrayAllocationExpression expression) { ArrayCreation arrayCreation = new ArrayCreation(this.ast); if (this.resolveBindings) { recordNodes(arrayCreation, expression); }/*from w ww.j a v a 2s . c o m*/ arrayCreation.setSourceRange(expression.sourceStart, expression.sourceEnd - expression.sourceStart + 1); org.eclipse.jdt.internal.compiler.ast.Expression[] dimensions = expression.dimensions; int dimensionsLength = dimensions.length; for (int i = 0; i < dimensionsLength; i++) { if (dimensions[i] != null) { Expression dimension = convert(dimensions[i]); if (this.resolveBindings) { recordNodes(dimension, dimensions[i]); } arrayCreation.dimensions().add(dimension); } } Type type = convertType(expression.type); if (this.resolveBindings) { recordNodes(type, expression.type); } ArrayType arrayType = null; if (type.isArrayType()) { arrayType = (ArrayType) type; } else { arrayType = this.ast.newArrayType(type, dimensionsLength); if (this.resolveBindings) { completeRecord(arrayType, expression); } int start = type.getStartPosition(); int end = type.getStartPosition() + type.getLength(); int previousSearchStart = end - 1; ArrayType componentType = (ArrayType) type.getParent(); for (int i = 0; i < dimensionsLength; i++) { previousSearchStart = retrieveRightBracketPosition(previousSearchStart + 1, this.compilationUnitSourceLength); componentType.setSourceRange(start, previousSearchStart - start + 1); componentType = (ArrayType) componentType.getParent(); } } arrayCreation.setType(arrayType); if (this.resolveBindings) { recordNodes(arrayType, expression); } if (expression.initializer != null) { arrayCreation.setInitializer(convert(expression.initializer)); } return arrayCreation; }