Example usage for org.eclipse.jdt.core.dom Type getParent

List of usage examples for org.eclipse.jdt.core.dom Type getParent

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.dom Type getParent.

Prototype

public final ASTNode getParent() 

Source Link

Document

Returns this node's parent node, or null if this is the root node.

Usage

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);
    }//w  w w .j av a 2 s. co 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;
}

From source file:org.spoofax.interpreter.adapter.ecj.ECJFactory.java

License:LGPL

private Type asType(IStrategoTerm term) {
    Type x = ((WrappedType) term).getWrappee();
    return x.getParent() == null && x.getAST() == ast ? x : (Type) ASTNode.copySubtree(ast, x);
}