Java Code Examples for org.eclipse.jdt.core.dom.ArrayCreation#dimensions()

The following examples show how to use org.eclipse.jdt.core.dom.ArrayCreation#dimensions() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CodeBlock.java    From SimFix with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example 2
Source File: ObjectCreation.java    From RefactoringMiner with MIT License 5 votes vote down vote up
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();
	}
}
 
Example 3
Source File: BindingSignatureVisitor.java    From JDeodorant with MIT License 5 votes vote down vote up
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;
}
 
Example 4
Source File: ArrayCreationWriter.java    From juniversal with MIT License 5 votes vote down vote up
@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);
    }
}
 
Example 5
Source File: ArrayCreationWriter.java    From juniversal with MIT License 5 votes vote down vote up
@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("]");
}
 
Example 6
Source File: JavaASTFlattener.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@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;
}