use of spoon.reflect.path.CtPathStringBuilder in project spoon by INRIA.
the class PathTest method exceptionTest.
@Test
public void exceptionTest() {
try {
new CtPathStringBuilder().fromString("/CtClassss");
fail();
} catch (CtPathException e) {
assertEquals("Unable to locate element with type CtClassss in Spoon model", e.getMessage());
}
}
use of spoon.reflect.path.CtPathStringBuilder in project spoon by INRIA.
the class PathTest method testMultiPathFromString.
@Test
public void testMultiPathFromString() throws Exception {
// When role match a list but no index is provided, all of them must be returned
Collection<CtElement> results = new CtPathStringBuilder().fromString(".spoon.test.path.Foo.foo#body#statement").evaluateOn(factory.getModel().getRootPackage());
assertEquals(results.size(), 3);
// When role match a set but no name is provided, all of them must be returned
results = new CtPathStringBuilder().fromString("#subPackage").evaluateOn(factory.getModel().getRootPackage());
assertEquals(results.size(), 1);
// When role match a map but no key is provided, all of them must be returned
results = new CtPathStringBuilder().fromString(".spoon.test.path.Foo.bar##annotation[index=0]#value").evaluateOn(factory.getModel().getRootPackage());
assertEquals(results.size(), 1);
}
use of spoon.reflect.path.CtPathStringBuilder in project spoon by INRIA.
the class PathTest method testGetPathFromNonParent.
@Test
public void testGetPathFromNonParent() throws Exception {
CtMethod fooMethod = (CtMethod) new CtPathStringBuilder().fromString(".spoon.test.path.Foo.foo").evaluateOn(factory.getModel().getRootPackage()).iterator().next();
CtMethod barMethod = (CtMethod) new CtPathStringBuilder().fromString(".spoon.test.path.Foo.bar").evaluateOn(factory.getModel().getRootPackage()).iterator().next();
try {
new CtElementPathBuilder().fromElement(fooMethod, barMethod);
fail("No path should be found to .spoon.test.path.Foo.foo from .spoon.test.path.Foo.bar");
} catch (CtPathException e) {
}
}
use of spoon.reflect.path.CtPathStringBuilder in project spoon by INRIA.
the class PathTest method testBuilderMethod.
@Test
public void testBuilderMethod() throws Exception {
equalsSet(new CtPathBuilder().name("spoon").name("test").name("path").name("Foo").type(CtMethod.class).build(), factory.Type().get("spoon.test.path.Foo").getMethods());
equalsSet(new CtPathStringBuilder().fromString(".spoon.test.path.Foo/CtMethod"), factory.Type().get("spoon.test.path.Foo").getMethods());
}
use of spoon.reflect.path.CtPathStringBuilder in project spoon by INRIA.
the class PathTest method testIncorrectPathFromString.
@Test
public void testIncorrectPathFromString() throws Exception {
// match the else part of the if in Foo.bar() method which does not exist (Test non existing unique element)
Collection<CtElement> results = new CtPathStringBuilder().fromString(".spoon.test.path.Foo.bar#body#statement[index=2]#else").evaluateOn(factory.getModel().getRootPackage());
assertEquals(results.size(), 0);
// match the third statement of Foo.foo() method which does not exist (Test non existing element of a list)
results = new CtPathStringBuilder().fromString(".spoon.test.path.Foo.foo#body#statement[index=3]").evaluateOn(factory.getModel().getRootPackage());
assertEquals(results.size(), 0);
// match an non existing package (Test non existing element of a set)
results = new CtPathStringBuilder().fromString("#subPackage[name=nonExistingPackage]").evaluateOn(factory.getModel().getRootPackage());
assertEquals(results.size(), 0);
// match a non existing field of an annotation (Test non existing element of a map)
results = new CtPathStringBuilder().fromString(".spoon.test.path.Foo.bar##annotation[index=0]#value[key=misspelled]").evaluateOn(factory.getModel().getRootPackage());
assertEquals(results.size(), 0);
}
Aggregations