/** * 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); }
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; }
/** * 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; }
@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; }
/** * 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; }
fieldRead.setVariable(fieldReference); invocation.setArguments( Arrays.asList( fieldRead,