use of spoon.reflect.visitor.filter.NamedElementFilter in project spoon by INRIA.
the class MethodTest method testGetAllMethodsAdaptingType.
@Test
public void testGetAllMethodsAdaptingType() throws Exception {
// contract: AbstractTypingContext should not enter in recursive calls when resolving autoreferenced bounding type
// such as T extends Comparable<? super T>
Launcher l = new Launcher();
l.getEnvironment().setNoClasspath(true);
l.addInputResource("src/test/resources/noclasspath/spring/PropertyComparator.java");
l.buildModel();
CtType<?> propertyComparator = l.getModel().getElements(new NamedElementFilter<CtType>(CtType.class, "PropertyComparator")).get(0);
Set<CtMethod<?>> allMethods = propertyComparator.getAllMethods();
boolean compareFound = false;
for (CtMethod<?> method : allMethods) {
if (method.getSimpleName().equals("compare")) {
assertEquals("compare(T,T)", method.getSignature());
compareFound = true;
}
}
assertTrue(compareFound);
}
use of spoon.reflect.visitor.filter.NamedElementFilter in project spoon by INRIA.
the class InsertMethodsTest method testInsertBeforeWithBrace.
@Test
public void testInsertBeforeWithBrace() throws Exception {
CtMethod<?> ifWithBraces_m = insertExampleClass.getElements(new NamedElementFilter<>(CtMethod.class, "ifWithBraces")).get(0);
// replace the return
CtCodeSnippetStatement s = factory.Code().createCodeSnippetStatement("return 2");
CtIf ifWithBraces = ifWithBraces_m.getElements(new TypeFilter<CtIf>(CtIf.class)).get(0);
// Inserts a s before the then statement
ifWithBraces.getThenStatement().insertBefore(s);
assertTrue(ifWithBraces.getThenStatement() instanceof CtBlock);
assertEquals(s, ((CtBlock<?>) ifWithBraces.getThenStatement()).getStatement(0));
assertEquals(ifWithBraces.getThenStatement(), s.getParent());
}
use of spoon.reflect.visitor.filter.NamedElementFilter in project spoon by INRIA.
the class InsertMethodsTest method testInsertAfterWithBrace.
@Test
public void testInsertAfterWithBrace() throws Exception {
CtMethod<?> ifWithBraces_m = insertExampleClass.getElements(new NamedElementFilter<>(CtMethod.class, "ifWithBraces")).get(0);
// replace the return
CtCodeSnippetStatement s = factory.Code().createCodeSnippetStatement("return 2");
CtIf ifWithBraces = ifWithBraces_m.getElements(new TypeFilter<CtIf>(CtIf.class)).get(0);
// Inserts a s before the then statement
ifWithBraces.getThenStatement().insertAfter(s);
assertTrue(ifWithBraces.getThenStatement() instanceof CtBlock);
assertEquals(s, ((CtBlock<?>) ifWithBraces.getThenStatement()).getStatement(1));
assertEquals(ifWithBraces.getThenStatement(), s.getParent());
}
use of spoon.reflect.visitor.filter.NamedElementFilter in project spoon by INRIA.
the class InsertMethodsTest method testInsertAfterWithoutBrace.
@Test
public void testInsertAfterWithoutBrace() throws Exception {
CtMethod<?> ifWithoutBraces_m = insertExampleClass.getElements(new NamedElementFilter<>(CtMethod.class, "ifWithoutBraces")).get(0);
// replace the return
CtCodeSnippetStatement s = factory.Code().createCodeSnippetStatement("return 2");
CtIf ifWithoutBraces = ifWithoutBraces_m.getElements(new TypeFilter<>(CtIf.class)).get(0);
// Inserts a s before the then statement
ifWithoutBraces.getThenStatement().insertAfter(s);
assertTrue(ifWithoutBraces.getThenStatement() instanceof CtBlock);
assertEquals(s, ((CtBlock<?>) ifWithoutBraces.getThenStatement()).getStatement(1));
assertEquals(ifWithoutBraces.getThenStatement(), s.getParent());
}
use of spoon.reflect.visitor.filter.NamedElementFilter in project spoon by INRIA.
the class InsertMethodsTest method testInsertBeforeWithoutBrace.
@Test
public void testInsertBeforeWithoutBrace() throws Exception {
CtMethod<?> ifWithoutBraces_m = insertExampleClass.getElements(new NamedElementFilter<>(CtMethod.class, "ifWithoutBraces")).get(0);
// replace the return
CtCodeSnippetStatement s = factory.Code().createCodeSnippetStatement("return 2");
CtIf ifWithoutBraces = ifWithoutBraces_m.getElements(new TypeFilter<>(CtIf.class)).get(0);
// Inserts a s before the then statement
ifWithoutBraces.getThenStatement().insertBefore(s);
assertTrue(ifWithoutBraces.getThenStatement() instanceof CtBlock);
assertEquals(s, ((CtBlock<?>) ifWithoutBraces.getThenStatement()).getStatement(0));
assertEquals(ifWithoutBraces.getThenStatement(), s.getParent());
}
Aggregations