use of spoon.test.imports.testclasses.ClientClass in project spoon by INRIA.
the class ImportTest method testAccessType.
@Test
public void testAccessType() throws Exception {
final Launcher launcher = new Launcher();
launcher.setArgs(new String[] { "-i", "./src/test/java/spoon/test/imports/testclasses", "--with-imports" });
launcher.buildModel();
final CtClass<ImportTest> aInnerClass = launcher.getFactory().Class().get(ClientClass.class.getName() + "$InnerClass");
final CtClass<ImportTest> aSuperClass = launcher.getFactory().Class().get("spoon.test.imports.testclasses.internal.SuperClass");
assertEquals(ClientClass.class.getName() + "$InnerClass", aInnerClass.getQualifiedName());
// Check that access type of ClientClass$InnerClass in package protected class is still ClientClass
assertEquals(ClientClass.class.getName(), aInnerClass.getReference().getAccessType().getQualifiedName());
final CtTypeReference<?> innerClassProtectedByGetSuperClass = aInnerClass.getSuperclass();
final CtTypeReference<?> innerClassProtectedByQualifiedName = launcher.getFactory().Class().get("spoon.test.imports.testclasses.internal.SuperClass$InnerClassProtected").getReference();
assertEquals("spoon.test.imports.testclasses.internal.SuperClass$InnerClassProtected", innerClassProtectedByGetSuperClass.getQualifiedName());
assertEquals("spoon.test.imports.testclasses.internal.SuperClass$InnerClassProtected", innerClassProtectedByQualifiedName.getQualifiedName());
assertEquals("spoon.test.imports.testclasses.internal.ChildClass", innerClassProtectedByGetSuperClass.getAccessType().getQualifiedName());
assertEquals("spoon.test.imports.testclasses.internal.SuperClass", innerClassProtectedByQualifiedName.getAccessType().getQualifiedName());
assertEquals("spoon.test.imports.testclasses.internal.ChildClass.InnerClassProtected", innerClassProtectedByGetSuperClass.toString());
assertEquals("spoon.test.imports.testclasses.internal.SuperClass.InnerClassProtected", innerClassProtectedByQualifiedName.toString());
}
use of spoon.test.imports.testclasses.ClientClass in project spoon by INRIA.
the class ImportTest method testSuperInheritanceHierarchyFunctionListener.
@Test
public void testSuperInheritanceHierarchyFunctionListener() throws Exception {
CtType<?> clientClass = (CtClass<?>) ModelUtils.buildClass(ClientClass.class);
CtTypeReference<?> childClass = clientClass.getSuperclass();
CtTypeReference<?> superClass = childClass.getSuperclass();
// contract: the enter and exit are always called with CtTypeReference instance
List<String> result = clientClass.map(new SuperInheritanceHierarchyFunction().includingSelf(true).setListener(new CtScannerListener() {
@Override
public ScanningMode enter(CtElement element) {
assertTrue(element instanceof CtTypeReference);
return ScanningMode.NORMAL;
}
@Override
public void exit(CtElement element) {
assertTrue(element instanceof CtTypeReference);
}
})).map(e -> {
assertTrue(e instanceof CtType);
return ((CtType) e).getQualifiedName();
}).list();
assertTrue(result.contains(clientClass.getQualifiedName()));
assertTrue(result.contains(childClass.getQualifiedName()));
assertTrue(result.contains(superClass.getQualifiedName()));
assertTrue(result.contains(Object.class.getName()));
// contract: if listener skips ALL, then skipped element and all super classes are not returned
result = clientClass.map(new SuperInheritanceHierarchyFunction().includingSelf(true).setListener(new CtScannerListener() {
@Override
public ScanningMode enter(CtElement element) {
assertTrue(element instanceof CtTypeReference);
if (superClass.getQualifiedName().equals(((CtTypeReference<?>) element).getQualifiedName())) {
return ScanningMode.SKIP_ALL;
}
return ScanningMode.NORMAL;
}
@Override
public void exit(CtElement element) {
assertTrue(element instanceof CtTypeReference);
}
})).map(e -> {
assertTrue(e instanceof CtType);
return ((CtType) e).getQualifiedName();
}).list();
assertTrue(result.contains(clientClass.getQualifiedName()));
assertTrue(result.contains(childClass.getQualifiedName()));
assertFalse(result.contains(superClass.getQualifiedName()));
assertFalse(result.contains(Object.class.getName()));
// contract: if listener skips CHIDLREN, then skipped element is returned but all super classes are not returned
result = clientClass.map(new SuperInheritanceHierarchyFunction().includingSelf(true).setListener(new CtScannerListener() {
@Override
public ScanningMode enter(CtElement element) {
assertTrue(element instanceof CtTypeReference);
if (superClass.getQualifiedName().equals(((CtTypeReference<?>) element).getQualifiedName())) {
return ScanningMode.SKIP_CHILDREN;
}
return ScanningMode.NORMAL;
}
@Override
public void exit(CtElement element) {
assertTrue(element instanceof CtTypeReference);
}
})).map(e -> {
assertTrue(e instanceof CtType);
return ((CtType) e).getQualifiedName();
}).list();
assertTrue(result.contains(clientClass.getQualifiedName()));
assertTrue(result.contains(childClass.getQualifiedName()));
assertTrue(result.contains(superClass.getQualifiedName()));
assertFalse(result.contains(Object.class.getName()));
}
use of spoon.test.imports.testclasses.ClientClass in project spoon by INRIA.
the class ImportTest method testSuperInheritanceHierarchyFunction.
@Test
public void testSuperInheritanceHierarchyFunction() throws Exception {
CtType<?> clientClass = (CtClass<?>) ModelUtils.buildClass(ClientClass.class);
CtTypeReference<?> childClass = clientClass.getSuperclass();
CtTypeReference<?> superClass = childClass.getSuperclass();
List<String> result = clientClass.map(new SuperInheritanceHierarchyFunction().includingSelf(true)).map(e -> {
assertTrue(e instanceof CtType);
return ((CtType) e).getQualifiedName();
}).list();
// contract: includingSelf(true) should return input type too
assertTrue(result.contains(clientClass.getQualifiedName()));
assertTrue(result.contains(childClass.getQualifiedName()));
assertTrue(result.contains(superClass.getQualifiedName()));
assertTrue(result.contains(Object.class.getName()));
result = clientClass.map(new SuperInheritanceHierarchyFunction().includingSelf(false)).map(e -> {
assertTrue(e instanceof CtType);
return ((CtType) e).getQualifiedName();
}).list();
// contract: includingSelf(false) should return input type too
assertFalse(result.contains(clientClass.getQualifiedName()));
assertTrue(result.contains(childClass.getQualifiedName()));
assertTrue(result.contains(superClass.getQualifiedName()));
assertTrue(result.contains(Object.class.getName()));
// contract: returnTypeReferences(true) returns CtTypeReferences
result = clientClass.map(new SuperInheritanceHierarchyFunction().includingSelf(true).returnTypeReferences(true)).map(e -> {
assertTrue(e instanceof CtTypeReference);
return ((CtTypeReference) e).getQualifiedName();
}).list();
// contract: includingSelf(false) should return input type too
assertTrue(result.contains(clientClass.getQualifiedName()));
assertTrue(result.contains(childClass.getQualifiedName()));
assertTrue(result.contains(superClass.getQualifiedName()));
assertTrue(result.contains(Object.class.getName()));
// contract: the mapping can be started on type reference too
result = clientClass.getReference().map(new SuperInheritanceHierarchyFunction().includingSelf(true).returnTypeReferences(true)).map(e -> {
assertTrue(e instanceof CtTypeReference);
return ((CtTypeReference) e).getQualifiedName();
}).list();
// contract: includingSelf(false) should return input type too
assertTrue(result.contains(clientClass.getQualifiedName()));
assertTrue(result.contains(childClass.getQualifiedName()));
assertTrue(result.contains(superClass.getQualifiedName()));
assertTrue(result.contains(Object.class.getName()));
// contract: super type of Object is nothing
List<CtTypeReference<?>> typeResult = clientClass.getFactory().Type().OBJECT.map(new SuperInheritanceHierarchyFunction().includingSelf(false).returnTypeReferences(true)).list();
assertEquals(0, typeResult.size());
typeResult = clientClass.getFactory().Type().OBJECT.map(new SuperInheritanceHierarchyFunction().includingSelf(true).returnTypeReferences(true)).list();
assertEquals(1, typeResult.size());
assertEquals(clientClass.getFactory().Type().OBJECT, typeResult.get(0));
}
use of spoon.test.imports.testclasses.ClientClass in project spoon by INRIA.
the class ChildClass method m.
public void m() {
File f;
ClientClass c;
}
Aggregations