List of usage examples for org.eclipse.jdt.internal.compiler.ast AllocationExpression enclosingInstance
public Expression enclosingInstance()
From source file:spoon.support.builder.JDTTreeBuilder.java
License:Open Source License
@SuppressWarnings("unchecked") @Override/*from ww w .j av a 2 s . co m*/ public boolean visit(AllocationExpression allocationExpression, BlockScope scope) { CtNewClass<?> c = factory.Core().createNewClass(); if (allocationExpression.type != null) c.setType(references.getTypeReference(allocationExpression.type.resolvedType)); c.setExecutable(references.getExecutableReference(allocationExpression.binding)); c.getExecutable().setType((CtTypeReference) c.getExecutable().getDeclaringType()); context.enter(c, allocationExpression); if (allocationExpression.enclosingInstance() != null) { context.target.push(c); allocationExpression.enclosingInstance().traverse(this, scope); context.target.pop(); } context.pushArgument(c); if (allocationExpression.arguments != null) { for (Expression e : allocationExpression.arguments) e.traverse(this, scope); } context.popArgument(c); return false; }
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 w w w. j av a2 s . c o m*/ } } 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; }