use of spoon.reflect.code.CtInvocation in project dspot by STAMP-project.
the class StatementAddTest method testStatementAddOnUnderTest.
@Test
public void testStatementAddOnUnderTest() throws Exception {
Factory factory = Utils.getFactory();
CtClass<Object> ctClass = factory.Class().get("fr.inria.mutation.ClassUnderTestTest");
AmplificationHelper.setSeedRandom(23L);
StatementAdd amplificator = new StatementAdd();
amplificator.reset(ctClass);
CtMethod originalMethod = Utils.findMethod(ctClass, "testLit");
List<CtMethod> amplifiedMethods = amplificator.apply(originalMethod);
System.out.println(amplifiedMethods);
assertEquals(2, amplifiedMethods.size());
List<String> expectedCalledMethod = Arrays.asList("plusOne", "minusOne");
assertTrue(amplifiedMethods.stream().allMatch(amplifiedMethod -> amplifiedMethod.filterChildren(new TypeFilter<CtInvocation<?>>(CtInvocation.class) {
@Override
public boolean matches(CtInvocation<?> element) {
return expectedCalledMethod.contains(element.getExecutable().getSimpleName());
}
}).first() != null));
}
use of spoon.reflect.code.CtInvocation in project dspot by STAMP-project.
the class ChangeMinimizer method minimize.
@Override
public CtMethod<?> minimize(CtMethod<?> amplifiedTestToBeMinimized) {
final CtMethod<?> generalMinimize = super.minimize(amplifiedTestToBeMinimized);
final CtMethod<?> changeMinimize = generalMinimize.clone();
final long time = System.currentTimeMillis();
final Failure failureToKeep = this.failurePerAmplifiedTest.get(amplifiedTestToBeMinimized);
final List<CtInvocation> assertions = changeMinimize.filterChildren(AmplificationHelper.ASSERTIONS_FILTER).list();
LOGGER.info("Minimizing {} assertions.", assertions.size());
assertions.forEach(invocation -> {
DSpotUtils.printProgress(assertions.indexOf(invocation), assertions.size());
tryToRemoveAssertion(changeMinimize, invocation, failureToKeep);
});
LOGGER.info("Reduce {}, {} statements to {} statements in {} ms.", amplifiedTestToBeMinimized.getSimpleName(), generalMinimize.getBody().getStatements().size(), changeMinimize.getBody().getStatements().size(), System.currentTimeMillis() - time);
// now that we reduce the amplified test, we must update the stack trace
updateStackTrace(amplifiedTestToBeMinimized, changeMinimize);
return changeMinimize;
}
use of spoon.reflect.code.CtInvocation in project dspot by STAMP-project.
the class TestMethodCallAdder method apply.
public List<CtMethod> apply(CtMethod method) {
List<CtMethod> methods = new ArrayList<>();
if (method.getDeclaringType() != null) {
// get the list of method calls
List<CtInvocation> invocations = Query.getElements(method, new TypeFilter(CtInvocation.class));
// this index serves to replace ith literal is replaced by zero in the ith clone of the method
int invocation_index = 0;
for (CtInvocation invocation : invocations) {
try {
if (AmplificationChecker.canBeAdded(invocation) && !AmplificationChecker.isAssert(invocation)) {
methods.add(apply(method, invocation_index));
}
} catch (Exception e) {
throw new RuntimeException(e);
}
invocation_index++;
}
}
return methods;
}
use of spoon.reflect.code.CtInvocation in project spoon by INRIA.
the class CtParameterRemoveRefactoring method computeAllInvocations.
/**
* search for all methods and lambdas which has to be refactored together with target method
*/
private void computeAllInvocations() {
ExecutableReferenceFilter execRefFilter = new ExecutableReferenceFilter();
for (CtExecutable<?> exec : getTargetExecutables()) {
execRefFilter.addExecutable(exec);
}
// all the invocations, which belongs to same inheritance tree
final List<CtInvocation<?>> invocations = new ArrayList<>();
target.getFactory().getModel().filterChildren(execRefFilter).forEach(new CtConsumer<CtExecutableReference<?>>() {
@Override
public void accept(CtExecutableReference<?> t) {
CtElement parent = t.getParent();
if (parent instanceof CtInvocation<?>) {
invocations.add((CtInvocation<?>) parent);
}
// else ignore other hits, which are not in context of invocation
}
});
targetInvocations = Collections.unmodifiableList(invocations);
}
use of spoon.reflect.code.CtInvocation in project spoon by INRIA.
the class GenericsTest method testGetExecDeclarationOfEnumSetOf.
@Test
public void testGetExecDeclarationOfEnumSetOf() {
Launcher launcher = new Launcher();
launcher.addInputResource("./src/test/java/spoon/test/generics/testclasses/EnumSetOf.java");
launcher.buildModel();
CtClass<?> ctClass = launcher.getFactory().Class().get(EnumSetOf.class);
CtInvocation invocation = ctClass.getMethodsByName("m").get(0).getBody().getStatement(0);
CtExecutable<?> decl = invocation.getExecutable().getDeclaration();
assertNull(decl);
CtClass<?> enumClass = launcher.getFactory().Class().get(EnumSet.class);
List<CtMethod<?>> methods = enumClass.getMethodsByName("of");
CtMethod rightOfMethod = null;
for (CtMethod method : methods) {
if (method.getParameters().size() == 1) {
rightOfMethod = method;
}
}
assertNotNull(rightOfMethod);
decl = invocation.getExecutable().getExecutableDeclaration();
assertEquals(rightOfMethod, decl);
}
Aggregations