下面列出了org.eclipse.jdt.core.dom.ArrayCreation#dimensions ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private ArrayCreate visit(ArrayCreation node) {
int startLine = _cunit.getLineNumber(node.getStartPosition());
int endLine = _cunit.getLineNumber(node.getStartPosition() + node.getLength());
ArrayCreate arrayCreate = new ArrayCreate(startLine, endLine, node);
arrayCreate.setArrayType(node.getType());
arrayCreate.setType(node.getType());
List<Expr> dimension = new ArrayList<>();
for(Object object : node.dimensions()){
Expr dim = (Expr) process((ASTNode) object);
dim.setParent(arrayCreate);
dimension.add(dim);
}
arrayCreate.setDimension(dimension);
if(node.getInitializer() != null){
ArrayInitial arrayInitializer = (ArrayInitial) process(node.getInitializer());
arrayInitializer.setParent(arrayCreate);
arrayCreate.setInitializer(arrayInitializer);
}
return arrayCreate;
}
public ObjectCreation(CompilationUnit cu, String filePath, ArrayCreation creation) {
this.locationInfo = new LocationInfo(cu, filePath, creation, CodeElementType.ARRAY_CREATION);
this.isArray = true;
this.type = UMLType.extractTypeObject(cu, filePath, creation.getType(), 0);
this.typeArguments = creation.dimensions().size();
this.arguments = new ArrayList<String>();
List<Expression> args = creation.dimensions();
for(Expression argument : args) {
this.arguments.add(argument.toString());
}
if(creation.getInitializer() != null) {
this.anonymousClassDeclaration = creation.getInitializer().toString();
}
}
public boolean visit(ArrayCreation expr) {
handleType(expr.getType());
List dimensions = expr.dimensions();
for (int i = 0; i < dimensions.size(); i++) {
handleExpression((Expression) dimensions.get(i));
}
if(expr.getInitializer() != null) {
visit(expr.getInitializer());
}
return false;
}
@Override
public void write(ArrayCreation arrayCreation) {
// TODO: C# doesn't support an exact equivalent to Integer[], with boxed integers (or other primitive types).
// Consider disallowing arrays of that type to be created, instead forcing the dev to either create an
// Object[] if they want boxed types or an int[] if they want primitive types
List<?> dimensions = arrayCreation.dimensions();
// TODO: Support multidimensional arrays
if (dimensions.size() > 1)
throw new JUniversalException("Multidimensional arrays not currently supported");
matchAndWrite("new");
copySpaceAndComments();
writeNode(arrayCreation.getType().getElementType());
copySpaceAndComments();
matchAndWrite("[");
writeNodes(arrayCreation.dimensions());
copySpaceAndComments();
matchAndWrite("]");
// TODO: Check all syntax combinations here
@Nullable ArrayInitializer arrayInitializer = arrayCreation.getInitializer();
if (arrayInitializer != null) {
copySpaceAndComments();
writeNode(arrayInitializer);
}
}
@Override
public void write(ArrayCreation arrayCreation) {
matchAndWrite("new");
List<?> dimensions = arrayCreation.dimensions();
// TODO: Support multidimensional arrays
if (dimensions.size() > 1)
throw new JUniversalException("Multidimensional arrays not currently supported");
// TODO: Support array initializers
if (arrayCreation.getInitializer() != null)
throw new JUniversalException("Array initializers not currently supported");
Expression dimensionSizeExpression = (Expression) dimensions.get(0);
setPosition(dimensionSizeExpression.getStartPosition());
write("(");
writeNode(dimensionSizeExpression);
copySpaceAndComments();
write(") ");
ArrayType arrayType = arrayCreation.getType();
setPosition(arrayType.getStartPosition());
write("Array<");
writeNode(arrayType.getElementType());
skipSpaceAndComments();
write(">");
setPosition(ASTUtil.getEndPosition(dimensionSizeExpression));
skipSpaceAndComments();
match("]");
}
@Override
public boolean visit(final ArrayCreation node) {
ArrayType at = node.getType();
int dims = at.getDimensions();
if ((dims > 1)) {
StringConcatenation _builder = new StringConcatenation();
_builder.append("/* FIXME Only one dimensional arrays are supported. ");
_builder.append(node);
_builder.append("*/");
this.appendToBuffer(_builder.toString());
this.addProblem(node, "Only one dimension arrays are supported.");
return false;
}
ArrayInitializer _initializer = node.getInitializer();
boolean _tripleNotEquals = (_initializer != null);
if (_tripleNotEquals) {
if (this.fallBackStrategy) {
this.appendToBuffer("(");
}
node.getInitializer().accept(this);
if (this.fallBackStrategy) {
this.appendToBuffer(" as ");
at.accept(this);
this.appendToBuffer(")");
}
} else {
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("new");
String _xifexpression = null;
boolean _isPrimitiveType = node.getType().getElementType().isPrimitiveType();
if (_isPrimitiveType) {
Type _elementType = node.getType().getElementType();
_xifexpression = StringExtensions.toFirstUpper(((PrimitiveType) _elementType).getPrimitiveTypeCode().toString());
}
_builder_1.append(_xifexpression);
_builder_1.append("ArrayOfSize(");
this.appendToBuffer(_builder_1.toString());
List _dimensions = node.dimensions();
(((Expression[])Conversions.unwrapArray(((Iterable<Expression>) _dimensions), Expression.class))[0]).accept(this);
this.appendToBuffer(")");
}
return false;
}