use of spoon.Launcher in project spoon by INRIA.
the class CtTypeTest method testHasMethodInSuperClass.
@Test
public void testHasMethodInSuperClass() throws Exception {
final Launcher launcher = new Launcher();
launcher.addInputResource("./src/test/java/spoon/test/ctType/testclasses/X.java");
launcher.run();
final CtClass<?> xClass = launcher.getFactory().Class().get("spoon.test.ctType.testclasses.X");
final CtClass<?> yClass = launcher.getFactory().Class().get("spoon.test.ctType.testclasses.Y");
final CtMethod<?> superMethod = xClass.getMethods().iterator().next();
assertTrue(yClass.hasMethod(superMethod));
}
use of spoon.Launcher 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.Launcher in project spoon by INRIA.
the class EqualTest method testEqualsComment.
@Test
public void testEqualsComment() throws Exception {
Factory factory = new Launcher().createFactory();
CtLocalVariable<?> var = factory.Code().createCodeSnippetStatement("int i=0").compile();
CtLocalVariable<?> var2 = var.clone();
var2.addComment(factory.Code().createComment("foo", CtComment.CommentType.INLINE));
assertNotEquals(1, var.getComments().size());
assertNotEquals(var2, var);
}
use of spoon.Launcher in project spoon by INRIA.
the class EqualTest method testEqualsMultitype.
@Test
public void testEqualsMultitype() throws Exception {
Factory factory = new Launcher().createFactory();
CtTry var = factory.Code().createCodeSnippetStatement("try{}catch(RuntimeException | AssertionError e){}").compile();
CtTry var2 = var.clone();
assertEquals(2, var2.getCatchers().get(0).getParameter().getMultiTypes().size());
// removing a multitype
var2.getCatchers().get(0).getParameter().getMultiTypes().remove(0);
assertEquals(1, var2.getCatchers().get(0).getParameter().getMultiTypes().size());
assertNotEquals(var2, var);
}
use of spoon.Launcher in project spoon by INRIA.
the class EqualTest method testEqualsActualTypeRef.
@Test
public void testEqualsActualTypeRef() throws Exception {
// contract: actual type refs are part of the identity
Factory factory = new Launcher().createFactory();
CtLocalVariable var = factory.Code().createCodeSnippetStatement("java.util.List<String> l ").compile();
CtLocalVariable var2 = factory.Code().createCodeSnippetStatement("java.util.List<Object> l ").compile();
assertNotEquals(var2, var);
}
Aggregations