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());
}
use of spoon.reflect.visitor.filter.TypeFilter in project spoon by INRIA.
the class DeleteTest method testDeleteConditionInACondition.
@Test
public void testDeleteConditionInACondition() 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 CtIf anIf = method.getElements(new TypeFilter<>(CtIf.class)).get(0);
assertNotNull(anIf.getCondition());
anIf.getCondition().delete();
assertNull(anIf.getCondition());
}
use of spoon.reflect.visitor.filter.TypeFilter in project spoon by INRIA.
the class DeleteTest method testDeleteStatementInCase.
@Test
public void testDeleteStatementInCase() throws Exception {
final Factory factory = build(Adobada.class);
final CtClass<Adobada> adobada = factory.Class().get(Adobada.class);
final CtMethod method = adobada.getMethod("m3");
final CtCase aCase = method.getElements(new TypeFilter<>(CtCase.class)).get(0);
assertEquals(2, aCase.getStatements().size());
final CtStatement statement = aCase.getStatements().get(1);
statement.delete();
assertEquals(1, aCase.getStatements().size());
assertFalse(aCase.getStatements().contains(statement));
}
Aggregations