@Override public boolean visit(AllocationExpression allocationExpression, BlockScope scope) { CtConstructorCall constructorCall = factory.Core().createConstructorCall(); constructorCall.setExecutable(references.getExecutableReference(allocationExpression)); ASTPair first = this.context.stack.getFirst(); // in case of enum values the constructor call is often implicit if (first.element instanceof CtEnumValue) { if (allocationExpression.sourceEnd == first.node.sourceEnd) { constructorCall.setImplicit(true); } } context.enter(constructorCall, allocationExpression); return true; }
@Override public boolean visit(QualifiedAllocationExpression qualifiedAllocationExpression, BlockScope scope) { CtConstructorCall constructorCall; if (qualifiedAllocationExpression.anonymousType != null) { constructorCall = factory.Core().createNewClass(); } else { constructorCall = factory.Core().createConstructorCall(); } constructorCall.setExecutable(references.getExecutableReference(qualifiedAllocationExpression)); context.enter(constructorCall, qualifiedAllocationExpression); return true; }
/** * Creates a constructor call. The correct constructor is inferred based on parameters * * @param type the decelerating type of the constructor * @param parameters the arguments of the constructor call * @param <T> the actual type of the decelerating type of the constructor if available * @return the constructor call */ public <T> CtConstructorCall<T> createConstructorCall(CtTypeReference<T> type, CtExpression<?>...parameters) { CtConstructorCall<T> constructorCall = factory.Core() .createConstructorCall(); CtExecutableReference<T> executableReference = factory.Core() .createExecutableReference(); executableReference.setType(type); executableReference.setDeclaringType(type == null ? type : type.clone()); executableReference.setSimpleName(CtExecutableReference.CONSTRUCTOR_NAME); List<CtTypeReference<?>> typeReferences = new ArrayList<>(); for (CtExpression<?> parameter : parameters) { typeReferences.add(parameter.getType()); } executableReference.setParameters(typeReferences); constructorCall.setArguments(Arrays.asList(parameters)); constructorCall.setExecutable(executableReference); return constructorCall; }
@java.lang.Override public <T> void visitCtConstructorCall(final spoon.reflect.code.CtConstructorCall<T> ctConstructorCall) { spoon.reflect.code.CtConstructorCall<T> aCtConstructorCall = ctConstructorCall.getFactory().Core().createConstructorCall(); this.builder.copy(ctConstructorCall, aCtConstructorCall); aCtConstructorCall.setAnnotations(this.cloneHelper.clone(ctConstructorCall.getAnnotations())); aCtConstructorCall.setTypeCasts(this.cloneHelper.clone(ctConstructorCall.getTypeCasts())); aCtConstructorCall.setExecutable(this.cloneHelper.clone(ctConstructorCall.getExecutable())); aCtConstructorCall.setTarget(this.cloneHelper.clone(ctConstructorCall.getTarget())); aCtConstructorCall.setArguments(this.cloneHelper.clone(ctConstructorCall.getArguments())); aCtConstructorCall.setComments(this.cloneHelper.clone(ctConstructorCall.getComments())); this.cloneHelper.tailor(ctConstructorCall, aCtConstructorCall); this.other = aCtConstructorCall; }
constructorCall.setType(references.getTypeReference(allocationExpression.expectedType())); constructorCall.setExecutable(references.getExecutableReference(allocationExpression.binding)); if (constructorCall.getExecutable() != null) { constructorCall.getExecutable().setType((CtTypeReference<Object>) constructorCall.getExecutable().getDeclaringType());