Example usage for org.eclipse.jdt.core.dom ClassInstanceCreation ClassInstanceCreation

List of usage examples for org.eclipse.jdt.core.dom ClassInstanceCreation ClassInstanceCreation

Introduction

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

Prototype

ClassInstanceCreation(AST ast) 

Source Link

Document

Creates a new AST node for a class instance creation expression owned by the given AST.

Usage

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

License:Open Source License

public ClassInstanceCreation convert(org.eclipse.jdt.internal.compiler.ast.AllocationExpression expression) {
    ClassInstanceCreation classInstanceCreation = new ClassInstanceCreation(this.ast);
    if (this.resolveBindings) {
        recordNodes(classInstanceCreation, expression);
    }/*from  w w w .  j av  a2  s . c o m*/
    if (expression.typeArguments != null) {
        switch (this.ast.apiLevel) {
        case AST.JLS2_INTERNAL:
            classInstanceCreation.setFlags(classInstanceCreation.getFlags() | ASTNode.MALFORMED);
            break;
        default:
            for (int i = 0, max = expression.typeArguments.length; i < max; i++) {
                classInstanceCreation.typeArguments().add(convertType(expression.typeArguments[i]));
            }
        }
    }
    switch (this.ast.apiLevel) {
    case AST.JLS2_INTERNAL:
        classInstanceCreation.internalSetName(convert(expression.type));
        break;
    default:
        classInstanceCreation.setType(convertType(expression.type));
    }
    classInstanceCreation.setSourceRange(expression.sourceStart,
            expression.sourceEnd - expression.sourceStart + 1);
    org.eclipse.jdt.internal.compiler.ast.Expression[] arguments = expression.arguments;
    if (arguments != null) {
        int length = arguments.length;
        for (int i = 0; i < length; i++) {
            classInstanceCreation.arguments().add(convert(arguments[i]));
        }
    }
    removeTrailingCommentFromExpressionEndingWithAParen(classInstanceCreation);
    return classInstanceCreation;
}

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

License:Open Source License

public Expression convert(org.eclipse.jdt.internal.compiler.ast.QualifiedAllocationExpression allocation) {
    final ClassInstanceCreation classInstanceCreation = new ClassInstanceCreation(this.ast);
    if (allocation.enclosingInstance != null) {
        classInstanceCreation.setExpression(convert(allocation.enclosingInstance));
    }//from   www.  ja v a 2  s . c om
    switch (this.ast.apiLevel) {
    case AST.JLS2_INTERNAL:
        classInstanceCreation.internalSetName(convert(allocation.type));
        break;
    default:
        classInstanceCreation.setType(convertType(allocation.type));
    }
    org.eclipse.jdt.internal.compiler.ast.Expression[] arguments = allocation.arguments;
    if (arguments != null) {
        int length = arguments.length;
        for (int i = 0; i < length; i++) {
            Expression argument = convert(arguments[i]);
            if (this.resolveBindings) {
                recordNodes(argument, arguments[i]);
            }
            classInstanceCreation.arguments().add(argument);
        }
    }
    if (allocation.typeArguments != null) {
        switch (this.ast.apiLevel) {
        case AST.JLS2_INTERNAL:
            classInstanceCreation.setFlags(classInstanceCreation.getFlags() | ASTNode.MALFORMED);
            break;
        default:
            for (int i = 0, max = allocation.typeArguments.length; i < max; i++) {
                classInstanceCreation.typeArguments().add(convertType(allocation.typeArguments[i]));
            }
        }
    }
    if (allocation.anonymousType != null) {
        int declarationSourceStart = allocation.sourceStart;
        classInstanceCreation.setSourceRange(declarationSourceStart,
                allocation.anonymousType.bodyEnd - declarationSourceStart + 1);
        final AnonymousClassDeclaration anonymousClassDeclaration = new AnonymousClassDeclaration(this.ast);
        int start = retrieveStartBlockPosition(allocation.anonymousType.sourceEnd,
                allocation.anonymousType.bodyEnd);
        anonymousClassDeclaration.setSourceRange(start, allocation.anonymousType.bodyEnd - start + 1);
        classInstanceCreation.setAnonymousClassDeclaration(anonymousClassDeclaration);
        buildBodyDeclarations(allocation.anonymousType, anonymousClassDeclaration);
        if (this.resolveBindings) {
            recordNodes(classInstanceCreation, allocation.anonymousType);
            recordNodes(anonymousClassDeclaration, allocation.anonymousType);
            anonymousClassDeclaration.resolveBinding();
        }
        return classInstanceCreation;
    } else {
        final int start = allocation.sourceStart;
        classInstanceCreation.setSourceRange(start, allocation.sourceEnd - start + 1);
        if (this.resolveBindings) {
            recordNodes(classInstanceCreation, allocation);
        }
        removeTrailingCommentFromExpressionEndingWithAParen(classInstanceCreation);
        return classInstanceCreation;
    }
}