Example usage for org.eclipse.jdt.internal.compiler.ast AllocationExpression genericTypeArguments

List of usage examples for org.eclipse.jdt.internal.compiler.ast AllocationExpression genericTypeArguments

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.compiler.ast AllocationExpression genericTypeArguments.

Prototype

TypeBinding[] genericTypeArguments

To view the source code for org.eclipse.jdt.internal.compiler.ast AllocationExpression genericTypeArguments.

Click Source Link

Usage

From source file:spoon.support.compiler.jdt.JDTTreeBuilder.java

License:Open Source License

private <T extends CtConstructorCall<Object>> T buildCommonPartForCtNewClassAndCtConstructorCall(
        AllocationExpression allocationExpression, BlockScope scope, T constructorCall) {
    if (allocationExpression.type != null) {
        final TypeReference[][] typeArguments = allocationExpression.type.getTypeArguments();
        // If typeArguments are null or empty, we have an element with a generic type.
        if (typeArguments != null && typeArguments.length > 0) {
            context.isGenericTypeExplicit = true;
            // This loop is necessary because it is the only way to know if the generic type
            // is implicit or not.
            for (TypeReference[] typeArgument : typeArguments) {
                context.isGenericTypeExplicit = typeArgument != null && typeArgument.length > 0;
                if (context.isGenericTypeExplicit) {
                    break;
                }/*from ww w  .j  a v  a  2 s .  com*/
            }
        }
        constructorCall.setType(references.getTypeReference(allocationExpression.type.resolvedType));
        context.isGenericTypeExplicit = true;
    } else if (allocationExpression.expectedType() != null) {
        constructorCall.setType(references.getTypeReference(allocationExpression.expectedType()));
    }
    constructorCall.setExecutable(references.getExecutableReference(allocationExpression.binding));
    if (constructorCall.getExecutable() != null) {
        constructorCall.getExecutable()
                .setType((CtTypeReference<Object>) constructorCall.getExecutable().getDeclaringType());
    }

    if (allocationExpression.genericTypeArguments() != null) {
        constructorCall.setActualTypeArguments(
                references.getBoundedTypesReferences(allocationExpression.genericTypeArguments()));
    }

    context.enter(constructorCall, allocationExpression);

    if (allocationExpression.enclosingInstance() != null) {
        context.target.push(constructorCall);
        allocationExpression.enclosingInstance().traverse(this, scope);
        context.target.pop();
    }

    context.pushArgument(constructorCall);
    if (allocationExpression.arguments != null) {
        for (Expression e : allocationExpression.arguments) {
            e.traverse(this, scope);
        }
    }
    context.popArgument(constructorCall);
    return constructorCall;
}