Search in sources :

Example 1 with Initializer

use of org.eclipse.jdt.internal.compiler.ast.Initializer in project che by eclipse.

the class SourceTypeConverter method convert.

/*
	 * Convert an initializerinfo into a parsed initializer declaration
	 */
private Initializer convert(InitializerElementInfo initializerInfo, CompilationResult compilationResult) throws JavaModelException {
    Block block = new Block(0);
    Initializer initializer = new Initializer(block, ClassFileConstants.AccDefault);
    int start = initializerInfo.getDeclarationSourceStart();
    int end = initializerInfo.getDeclarationSourceEnd();
    initializer.sourceStart = initializer.declarationSourceStart = start;
    initializer.sourceEnd = initializer.declarationSourceEnd = end;
    initializer.modifiers = initializerInfo.getModifiers();
    /* convert local and anonymous types */
    IJavaElement[] children = initializerInfo.getChildren();
    int typesLength = children.length;
    if (typesLength > 0) {
        Statement[] statements = new Statement[typesLength];
        for (int i = 0; i < typesLength; i++) {
            SourceType type = (SourceType) children[i];
            TypeDeclaration localType = convert(type, compilationResult);
            if ((localType.bits & ASTNode.IsAnonymousType) != 0) {
                QualifiedAllocationExpression expression = new QualifiedAllocationExpression(localType);
                expression.type = localType.superclass;
                localType.superclass = null;
                localType.superInterfaces = null;
                localType.allocation = expression;
                statements[i] = expression;
            } else {
                statements[i] = localType;
            }
        }
        block.statements = statements;
    }
    return initializer;
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) ArrayInitializer(org.eclipse.jdt.internal.compiler.ast.ArrayInitializer) Initializer(org.eclipse.jdt.internal.compiler.ast.Initializer) Statement(org.eclipse.jdt.internal.compiler.ast.Statement) ISourceType(org.eclipse.jdt.internal.compiler.env.ISourceType) SourceType(org.eclipse.jdt.internal.core.SourceType) QualifiedAllocationExpression(org.eclipse.jdt.internal.compiler.ast.QualifiedAllocationExpression) Block(org.eclipse.jdt.internal.compiler.ast.Block) TypeDeclaration(org.eclipse.jdt.internal.compiler.ast.TypeDeclaration)

Aggregations

IJavaElement (org.eclipse.jdt.core.IJavaElement)1 ArrayInitializer (org.eclipse.jdt.internal.compiler.ast.ArrayInitializer)1 Block (org.eclipse.jdt.internal.compiler.ast.Block)1 Initializer (org.eclipse.jdt.internal.compiler.ast.Initializer)1 QualifiedAllocationExpression (org.eclipse.jdt.internal.compiler.ast.QualifiedAllocationExpression)1 Statement (org.eclipse.jdt.internal.compiler.ast.Statement)1 TypeDeclaration (org.eclipse.jdt.internal.compiler.ast.TypeDeclaration)1 ISourceType (org.eclipse.jdt.internal.compiler.env.ISourceType)1 SourceType (org.eclipse.jdt.internal.core.SourceType)1