/** * Creates an invocation (can be a statement or an expression). * * @param <T> * the return type of the invoked method * @param target * the target expression (may be null for static methods) * @param executable * the invoked executable * @param arguments * the argument list * @return the new invocation */ public <T> CtInvocation<T> createInvocation(CtExpression<?> target, CtExecutableReference<T> executable, List<CtExpression<?>> arguments) { return factory.Core().<T>createInvocation().<CtInvocation<T>>setTarget(target).<CtInvocation<T>>setExecutable(executable).setArguments(arguments); }
@Override public boolean visit(ExplicitConstructorCall explicitConstructor, BlockScope scope) { CtInvocation<Object> inv = factory.Core().createInvocation(); inv.setImplicit(explicitConstructor.isImplicitSuper()); inv.setExecutable(references.getExecutableReference(explicitConstructor.binding)); CtTypeReference<?> declaringType = inv.getExecutable().getDeclaringType(); inv.getExecutable().setType(declaringType == null ? null : (CtTypeReference<Object>) declaringType.clone()); context.enter(inv, explicitConstructor); return true; }
public <T> void visitCtInvocation(final spoon.reflect.code.CtInvocation<T> invocation) { spoon.reflect.code.CtInvocation<T> aCtInvocation = invocation.getFactory().Core().createInvocation(); this.builder.copy(invocation, aCtInvocation); aCtInvocation.setAnnotations(this.cloneHelper.clone(invocation.getAnnotations())); aCtInvocation.setTypeCasts(this.cloneHelper.clone(invocation.getTypeCasts())); aCtInvocation.setTarget(this.cloneHelper.clone(invocation.getTarget())); aCtInvocation.setExecutable(this.cloneHelper.clone(invocation.getExecutable())); aCtInvocation.setArguments(this.cloneHelper.clone(invocation.getArguments())); aCtInvocation.setComments(this.cloneHelper.clone(invocation.getComments())); this.cloneHelper.tailor(invocation, aCtInvocation); this.other = aCtInvocation; }
@Override public boolean visit(MessageSend messageSend, BlockScope scope) { CtInvocation<Object> inv = factory.Core().createInvocation(); inv.setExecutable(references.getExecutableReference(messageSend)); if (messageSend.binding instanceof ProblemMethodBinding) { // We are in a static complex in noclasspath mode. if (inv.getExecutable() != null && inv.getExecutable().getDeclaringType() != null) { inv.setTarget(factory.Code().createTypeAccess(inv.getExecutable().getDeclaringType(), inv.getExecutable().getDeclaringType().isAnonymous())); } if (messageSend.expectedType() != null) { inv.getExecutable().setType(references.getTypeReference(messageSend.expectedType())); } } context.enter(inv, messageSend); return true; }
@Override public <T> void visitCtInvocation(CtInvocation<T> invocation) { CtInvocation<T> i = invocation.getFactory().Core().createInvocation(); i.setExecutable(invocation.getExecutable()); i.setTypeCasts(invocation.getTypeCasts()); boolean constant = true;
/** * Creates an invocation (can be a statement or an expression). * * @param <T> * the return type of the invoked method * @param target * the target expression (may be null for static methods) * @param executable * the invoked executable * @param arguments * the argument list * @return the new invocation */ public <T> CtInvocation<T> createInvocation(CtExpression<?> target, CtExecutableReference<T> executable, List<CtExpression<?>> arguments) { return factory.Core().<T>createInvocation().<CtInvocation<T>>setTarget(target).<CtInvocation<T>>setExecutable(executable).setArguments(arguments); }
@Override public CtInvocation<?> buildInvocationToAssertion(CtMethod<?> testMethod, AssertEnum assertion, List<CtExpression> arguments) { final Factory factory = InputConfiguration.get().getFactory(); //assertThat(actual) final CtInvocation<?> assertThat = createAssertThat(arguments.get(arguments.size() - 1)); //isXXX(expected) final CtInvocation invocation = factory.createInvocation(); final CtExecutableReference<?> executableReference = factory.Core().createExecutableReference(); executableReference.setSimpleName(assertion.toStringAccordingToClass(this.getClass())); executableReference.setDeclaringType(factory.Type().createReference(assertion.toStringAccordingToClass(this.getClass()))); invocation.setExecutable(executableReference); if (arguments.size() > 1) { invocation.setArguments(Collections.singletonList(arguments.get(0))); } invocation.setType(factory.Type().voidPrimitiveType()); invocation.setTarget(assertThat); invocation.putMetadata(METADATA_ASSERT_AMPLIFICATION, true); return invocation; }
referenceToGetter.setSimpleName(executableName); referenceToGetter.setDeclaringType(ctType.getReference()); invocation.setExecutable(referenceToGetter); if (start != 1) { final String substringToBeRemove = invocationAsString.substring(start - 2, invocationAsString.indexOf("()") + 2);
private static <T> void processOverridden(CtClass<?> mergeInto, CtClass<?> toMerge, final CtMethod<T> methodToMerge) { List<CtInvocation<T>> superInvocations = mergeInto.getElements( new Filter<CtInvocation<T>>() { @Override public boolean matches(CtInvocation<T> invocation) { if (!(invocation.getTarget() instanceof CtSuperAccess)) return false; CtExecutable<?> m = invocation.getExecutable().getDeclaration(); return m != null && MethodNode.overrides((CtMethod<?>) m, methodToMerge); } }); methodToMerge.setSimpleName(classPrefixedName(toMerge, methodToMerge)); methodToMerge.setVisibility(PRIVATE); removeAnnotation(methodToMerge, Override.class); for (CtInvocation<T> superInvocation : superInvocations) { superInvocation.setTarget(null); superInvocation.setExecutable(methodToMerge.getReference()); } add(mergeInto, methodToMerge, mergeInto::addMethod); }
newInvocation.setExecutable(anotherMethod.getReference()); Ingredient newIngredient = new Ingredient(newInvocation); newIngredient.setDerivedFrom(invocationToReplace);
@SuppressWarnings("unchecked") private CtInvocation<?> createAssertThat(CtExpression<?> actual) { final Factory factory = InputConfiguration.get().getFactory(); final CtInvocation invocation = factory.createInvocation(); final CtExecutableReference executableReference = factory.Core().createExecutableReference(); executableReference.setStatic(true); executableReference.setSimpleName(ASSERT_THAT); executableReference.setDeclaringType(factory.Type().createReference(this.qualifiedNameOfAssertClass)); invocation.setExecutable(executableReference); invocation.setArguments(Collections.singletonList(actual)); invocation.setType(factory.Type().voidPrimitiveType()); invocation.setTarget(factory.createTypeAccess(factory.Type().createReference(this.qualifiedNameOfAssertClass))); invocation.putMetadata(METADATA_ASSERT_AMPLIFICATION, true); return invocation; }
inv.setExecutable(er); inv.getExecutable().setType((CtTypeReference<Object>) inv.getExecutable().getDeclaringType()); inv.setType(inv.getExecutable().getType());
CtInvocation<Object> inv = factory.Core().createInvocation(); if (messageSend.binding != null) { inv.setExecutable(references.getExecutableReference(messageSend.binding)); if (messageSend.binding instanceof ProblemMethodBinding) { inv.setExecutable(ref);
/** * Builds an invocation to <code>methodName</code> of {@link org.junit.Assert}. * This should be a correct method name such as assertEquals, assertTrue... * * @param assertion the type of the assertion method * @param arguments the arguments of the assertion, <i>e.g.</i> the two element to be compared in {@link org.junit.Assert#assertEquals(Object, Object)} * @return a spoon node representing the invocation to the assertion, ready to be inserted in a test method */ @Override public CtInvocation<?> buildInvocationToAssertion(CtMethod<?> testMethod, AssertEnum assertion, List<CtExpression> arguments) { final Factory factory = InputConfiguration.get().getFactory(); final CtInvocation invocation = factory.createInvocation(); final CtExecutableReference<?> executableReference = factory.Core().createExecutableReference(); executableReference.setStatic(true); executableReference.setSimpleName(assertion.toStringAccordingToClass(JUnitSupport.class)); executableReference.setDeclaringType(factory.Type().createReference(this.qualifiedNameOfAssertClass)); invocation.setExecutable(executableReference); invocation.setArguments(arguments); // TODO invocation.setType(factory.Type().voidPrimitiveType()); invocation.setTarget(factory.createTypeAccess(factory.Type().createReference(this.qualifiedNameOfAssertClass))); invocation.putMetadata(METADATA_ASSERT_AMPLIFICATION, true); return invocation; }
public <T> void visitCtInvocation(CtInvocation<T> invocation) { CtInvocation<T> i = invocation.getFactory().Core().createInvocation(); i.setType(invocation.getType()); i.setExecutable(invocation.getExecutable()); boolean constant = true; i.setTarget(evaluate(i, invocation.getTarget()));
executableReference.setSimpleName("assertThrows"); executableReference.setDeclaringType(factory.Type().createReference(this.qualifiedNameOfAssertClass)); invocation.setExecutable(executableReference); invocation.setType(factory.Type().voidPrimitiveType()); invocation.setTarget(factory.createTypeAccess(factory.Type().createReference(this.qualifiedNameOfAssertClass)));