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

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

Introduction

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

Prototype

final void setParent(ASTNode parent, StructuralPropertyDescriptor property) 

Source Link

Document

Sets or clears this node's parent node and location.

Usage

From source file:org.eclipse.jdt.core.dom.ASTConverter.java

License:Open Source License

protected void setTypeForField(FieldDeclaration fieldDeclaration, Type type, int extraDimension) {
    if (extraDimension != 0) {
        if (type.isArrayType()) {
            ArrayType arrayType = (ArrayType) type;
            int remainingDimensions = arrayType.getDimensions() - extraDimension;
            if (remainingDimensions == 0) {
                // the dimensions are after the name so the type of the fieldDeclaration is a simpleType
                Type elementType = arrayType.getElementType();
                // cut the child loose from its parent (without creating garbage)
                elementType.setParent(null, null);
                this.ast.getBindingResolver().updateKey(type, elementType);
                fieldDeclaration.setType(elementType);
            } else {
                int start = type.getStartPosition();
                ArrayType subarrayType = arrayType;
                int index = extraDimension;
                while (index > 0) {
                    subarrayType = (ArrayType) subarrayType.getComponentType();
                    index--;//from  ww w.  ja va2 s.c om
                }
                int end = retrieveProperRightBracketPosition(remainingDimensions, start);
                subarrayType.setSourceRange(start, end - start + 1);
                // cut the child loose from its parent (without creating garbage)
                subarrayType.setParent(null, null);
                fieldDeclaration.setType(subarrayType);
                updateInnerPositions(subarrayType, remainingDimensions);
                this.ast.getBindingResolver().updateKey(type, subarrayType);
            }
        } else {
            fieldDeclaration.setType(type);
        }
    } else {
        if (type.isArrayType()) {
            // update positions of the component types of the array type
            int dimensions = ((ArrayType) type).getDimensions();
            updateInnerPositions(type, dimensions);
        }
        fieldDeclaration.setType(type);
    }
}

From source file:org.eclipse.jdt.core.dom.ASTConverter.java

License:Open Source License

protected void setTypeForMethodDeclaration(MethodDeclaration methodDeclaration, Type type, int extraDimension) {
    if (extraDimension != 0) {
        if (type.isArrayType()) {
            ArrayType arrayType = (ArrayType) type;
            int remainingDimensions = arrayType.getDimensions() - extraDimension;
            if (remainingDimensions == 0) {
                // the dimensions are after the name so the type of the fieldDeclaration is a simpleType
                Type elementType = arrayType.getElementType();
                // cut the child loose from its parent (without creating garbage)
                elementType.setParent(null, null);
                this.ast.getBindingResolver().updateKey(type, elementType);
                switch (this.ast.apiLevel) {
                case AST.JLS2_INTERNAL:
                    methodDeclaration.internalSetReturnType(elementType);
                    break;
                default:
                    methodDeclaration.setReturnType2(elementType);
                    break;
                }//from   w w  w.j a  v a 2s .  c o m
            } else {
                int start = type.getStartPosition();
                ArrayType subarrayType = arrayType;
                int index = extraDimension;
                while (index > 0) {
                    subarrayType = (ArrayType) subarrayType.getComponentType();
                    index--;
                }
                int end = retrieveProperRightBracketPosition(remainingDimensions, start);
                subarrayType.setSourceRange(start, end - start + 1);
                // cut the child loose from its parent (without creating garbage)
                subarrayType.setParent(null, null);
                updateInnerPositions(subarrayType, remainingDimensions);
                switch (this.ast.apiLevel) {
                case AST.JLS2_INTERNAL:
                    methodDeclaration.internalSetReturnType(subarrayType);
                    break;
                default:
                    methodDeclaration.setReturnType2(subarrayType);
                    break;
                }
                this.ast.getBindingResolver().updateKey(type, subarrayType);
            }
        } else {
            switch (this.ast.apiLevel) {
            case AST.JLS2_INTERNAL:
                methodDeclaration.internalSetReturnType(type);
                break;
            default:
                methodDeclaration.setReturnType2(type);
                break;
            }
        }
    } else {
        switch (this.ast.apiLevel) {
        case AST.JLS2_INTERNAL:
            methodDeclaration.internalSetReturnType(type);
            break;
        default:
            methodDeclaration.setReturnType2(type);
            break;
        }
    }
}

From source file:org.eclipse.jdt.core.dom.ASTConverter.java

License:Open Source License

protected void setTypeForSingleVariableDeclaration(SingleVariableDeclaration singleVariableDeclaration,
        Type type, int extraDimension) {
    if (extraDimension != 0) {
        if (type.isArrayType()) {
            ArrayType arrayType = (ArrayType) type;
            int remainingDimensions = arrayType.getDimensions() - extraDimension;
            if (remainingDimensions == 0) {
                // the dimensions are after the name so the type of the fieldDeclaration is a simpleType
                Type elementType = arrayType.getElementType();
                // cut the child loose from its parent (without creating garbage)
                elementType.setParent(null, null);
                this.ast.getBindingResolver().updateKey(type, elementType);
                singleVariableDeclaration.setType(elementType);
            } else {
                int start = type.getStartPosition();
                ArrayType subarrayType = arrayType;
                int index = extraDimension;
                while (index > 0) {
                    subarrayType = (ArrayType) subarrayType.getComponentType();
                    index--;//  ww  w  . ja va2s.  c  om
                }
                int end = retrieveProperRightBracketPosition(remainingDimensions, start);
                subarrayType.setSourceRange(start, end - start + 1);
                // cut the child loose from its parent (without creating garbage)
                subarrayType.setParent(null, null);
                updateInnerPositions(subarrayType, remainingDimensions);
                singleVariableDeclaration.setType(subarrayType);
                this.ast.getBindingResolver().updateKey(type, subarrayType);
            }
        } else {
            singleVariableDeclaration.setType(type);
        }
    } else {
        singleVariableDeclaration.setType(type);
    }
}

From source file:org.eclipse.jdt.core.dom.ASTConverter.java

License:Open Source License

protected void setTypeForVariableDeclarationExpression(
        VariableDeclarationExpression variableDeclarationExpression, Type type, int extraDimension) {
    if (extraDimension != 0) {
        if (type.isArrayType()) {
            ArrayType arrayType = (ArrayType) type;
            int remainingDimensions = arrayType.getDimensions() - extraDimension;
            if (remainingDimensions == 0) {
                // the dimensions are after the name so the type of the fieldDeclaration is a simpleType
                Type elementType = arrayType.getElementType();
                // cut the child loose from its parent (without creating garbage)
                elementType.setParent(null, null);
                this.ast.getBindingResolver().updateKey(type, elementType);
                variableDeclarationExpression.setType(elementType);
            } else {
                int start = type.getStartPosition();
                ArrayType subarrayType = arrayType;
                int index = extraDimension;
                while (index > 0) {
                    subarrayType = (ArrayType) subarrayType.getComponentType();
                    index--;/*from   w  ww.j  a v  a 2  s .  c  o  m*/
                }
                int end = retrieveProperRightBracketPosition(remainingDimensions, start);
                subarrayType.setSourceRange(start, end - start + 1);
                // cut the child loose from its parent (without creating garbage)
                subarrayType.setParent(null, null);
                updateInnerPositions(subarrayType, remainingDimensions);
                variableDeclarationExpression.setType(subarrayType);
                this.ast.getBindingResolver().updateKey(type, subarrayType);
            }
        } else {
            variableDeclarationExpression.setType(type);
        }
    } else {
        variableDeclarationExpression.setType(type);
    }
}

From source file:org.eclipse.jdt.core.dom.ASTConverter.java

License:Open Source License

protected void setTypeForVariableDeclarationStatement(VariableDeclarationStatement variableDeclarationStatement,
        Type type, int extraDimension) {
    if (extraDimension != 0) {
        if (type.isArrayType()) {
            ArrayType arrayType = (ArrayType) type;
            int remainingDimensions = arrayType.getDimensions() - extraDimension;
            if (remainingDimensions == 0) {
                // the dimensions are after the name so the type of the fieldDeclaration is a simpleType
                Type elementType = arrayType.getElementType();
                // cut the child loose from its parent (without creating garbage)
                elementType.setParent(null, null);
                this.ast.getBindingResolver().updateKey(type, elementType);
                variableDeclarationStatement.setType(elementType);
            } else {
                int start = type.getStartPosition();
                ArrayType subarrayType = arrayType;
                int index = extraDimension;
                while (index > 0) {
                    subarrayType = (ArrayType) subarrayType.getComponentType();
                    index--;/*from  w  w  w.j a  v  a  2 s  . com*/
                }
                int end = retrieveProperRightBracketPosition(remainingDimensions, start);
                subarrayType.setSourceRange(start, end - start + 1);
                // cut the child loose from its parent (without creating garbage)
                subarrayType.setParent(null, null);
                updateInnerPositions(subarrayType, remainingDimensions);
                variableDeclarationStatement.setType(subarrayType);
                this.ast.getBindingResolver().updateKey(type, subarrayType);
            }
        } else {
            variableDeclarationStatement.setType(type);
        }
    } else {
        variableDeclarationStatement.setType(type);
    }
}