use of spoon.reflect.visitor.filter.TypeFilter in project dspot by STAMP-project.
the class StatementAddTest method testStatementAddOnArrayObjects.
@Test
public void testStatementAddOnArrayObjects() throws Exception {
final String packageName = "fr.inria.statementaddarray";
InputProgram inputProgram = Utils.getInputProgram();
final Factory factory = inputProgram.getFactory();
inputProgram.setFactory(factory);
AmplificationHelper.setSeedRandom(32L);
StatementAdd amplifier = new StatementAdd(packageName);
amplifier.reset(factory.Class().get(packageName + ".ClassTargetAmplify"));
CtMethod<?> ctMethod = Utils.findMethod(factory.Class().get(packageName + ".TestClassTargetAmplify"), "test");
List<CtMethod> amplifiedMethods = amplifier.apply(ctMethod);
System.out.println(amplifiedMethods);
assertEquals(5, amplifiedMethods.size());
List<String> expectedCalledMethod = Arrays.asList("methodWithArrayParatemeter", "methodWithArrayParatemeterFromDomain", "methodWithDomainParameter", "methodWithReturn", "method1");
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.visitor.filter.TypeFilter 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.visitor.filter.TypeFilter in project spoon by INRIA.
the class CommentTest method testCommentsInComment1And2.
@Test
public void testCommentsInComment1And2() {
Factory f = getSpoonFactory();
CtClass<?> type = (CtClass<?>) f.Type().get(Comment1.class);
List<CtComment> comments = type.getElements(new TypeFilter<CtComment>(CtComment.class));
assertEquals(4, comments.size());
type = (CtClass<?>) f.Type().get(Comment2.class);
comments = type.getElements(new TypeFilter<CtComment>(CtComment.class));
assertEquals(2, comments.size());
CtComment commentD = comments.get(1);
assertEquals("D", commentD.getContent());
}
use of spoon.reflect.visitor.filter.TypeFilter in project spoon by INRIA.
the class CtTypeTest method testIsSubTypeOfonTypeReferences.
@Test
public void testIsSubTypeOfonTypeReferences() throws Exception {
final Launcher launcher = new Launcher();
launcher.setArgs(new String[] { "-c" });
launcher.addInputResource("./src/test/java/spoon/test/ctType/testclasses/SubtypeModel.java");
launcher.buildModel();
Factory factory = launcher.getFactory();
CtType<?> oCtType = factory.Class().get("spoon.test.ctType.testclasses.SubtypeModel");
CtMethod<?> O_FooMethod = oCtType.filterChildren(new NamedElementFilter<>(CtMethod.class, "foo")).first();
Map<String, CtTypeReference<?>> nameToTypeRef = new HashMap<>();
O_FooMethod.filterChildren(new TypeFilter<>(CtLocalVariable.class)).forEach((CtLocalVariable var) -> {
nameToTypeRef.put(var.getSimpleName(), var.getType());
});
int[] count = new int[1];
O_FooMethod.filterChildren(new TypeFilter<>(CtAssignment.class)).forEach((CtAssignment ass) -> {
for (CtComment comment : ass.getComments()) {
checkIsNotSubtype(comment, nameToTypeRef);
count[0]++;
}
;
count[0]++;
checkIsSubtype(((CtVariableAccess) ass.getAssigned()).getVariable().getType(), ((CtVariableAccess) ass.getAssignment()).getVariable().getType(), nameToTypeRef);
});
assertTrue(count[0] > (9 * 8));
}
use of spoon.reflect.visitor.filter.TypeFilter in project spoon by INRIA.
the class DeleteTest method testDeleteChainOfAssignment.
@Test
public void testDeleteChainOfAssignment() throws Exception {
final Factory factory = build(Adobada.class);
final CtClass<Adobada> adobada = factory.Class().get(Adobada.class);
final CtMethod method = adobada.getMethod("m4", factory.Type().INTEGER_PRIMITIVE, factory.Type().FLOAT_PRIMITIVE, factory.Type().STRING);
final CtAssignment chainOfAssignment = method.getElements(new TypeFilter<>(CtAssignment.class)).get(0);
assertNotNull(chainOfAssignment.getAssignment());
chainOfAssignment.getAssignment().delete();
assertNull(chainOfAssignment.getAssignment());
}
Aggregations