use of spoon.reflect.declaration.CtPackage in project spoon by INRIA.
the class PackageTest method testPrintPackageInfoWhenNothingInPackage.
@Test
public void testPrintPackageInfoWhenNothingInPackage() throws Exception {
final Launcher launcher = new Launcher();
launcher.addInputResource("./src/test/java/spoon/test/pkg/testclasses/internal");
launcher.setSourceOutputDirectory("./target/spooned/package");
launcher.getEnvironment().setCommentEnabled(true);
launcher.run();
final CtPackage aPackage = launcher.getFactory().Package().get("spoon.test.pkg.testclasses.internal");
assertEquals(1, aPackage.getAnnotations().size());
assertEquals(3, aPackage.getComments().size());
assertEquals(CtComment.CommentType.JAVADOC, aPackage.getComments().get(0).getCommentType());
assertEquals(CtComment.CommentType.BLOCK, aPackage.getComments().get(1).getCommentType());
assertEquals(CtComment.CommentType.INLINE, aPackage.getComments().get(2).getCommentType());
assertThat(aPackage).isEqualTo(ModelUtils.build(new File("./target/spooned/package/spoon/test/pkg/testclasses/internal")).Package().get("spoon.test.pkg.testclasses.internal"));
}
use of spoon.reflect.declaration.CtPackage in project spoon by INRIA.
the class PackageTest method testRenameRootPackageWithNullOrEmpty.
@Test
public void testRenameRootPackageWithNullOrEmpty() throws Exception {
final Launcher spoon = new Launcher();
spoon.addInputResource("./src/test/resources/noclasspath/app/Test.java");
spoon.getEnvironment().setNoClasspath(true);
spoon.buildModel();
CtPackage rootPackage = spoon.getFactory().Package().getRootPackage();
String rootPackageName = rootPackage.getSimpleName();
assertEquals(CtPackage.TOP_LEVEL_PACKAGE_NAME, rootPackageName);
rootPackage.setSimpleName("");
assertEquals(CtPackage.TOP_LEVEL_PACKAGE_NAME, rootPackageName);
rootPackage.setSimpleName(null);
assertEquals(CtPackage.TOP_LEVEL_PACKAGE_NAME, rootPackageName);
}
use of spoon.reflect.declaration.CtPackage in project spoon by INRIA.
the class PackageTest method testPackage.
@Test
public void testPackage() throws Exception {
final String classFilePath = "./src/test/java/spoon/test/pkg/name/PackageTestClass.java";
final String packageInfoFilePath = "./src/test/java/spoon/test/pkg/package-info.java";
final File packageInfoFile = new File(packageInfoFilePath);
Launcher spoon = new Launcher();
Factory factory = spoon.createFactory();
factory.getEnvironment().setCommentEnabled(true);
spoon.createCompiler(factory, SpoonResourceHelper.resources(classFilePath, packageInfoFilePath)).build();
CtClass<?> clazz = factory.Class().get(PackageTestClass.class);
Assert.assertEquals(PackageTestClass.class, clazz.getActualClass());
CtPackage ctPackage = clazz.getPackage();
Assert.assertEquals("spoon.test.pkg.name", ctPackage.getQualifiedName());
Assert.assertEquals("", ctPackage.getDocComment());
assertTrue(CtPackage.class.isAssignableFrom(ctPackage.getParent().getClass()));
ctPackage = (CtPackage) ctPackage.getParent();
Assert.assertEquals("spoon.test.pkg", ctPackage.getQualifiedName());
Assert.assertNotNull(ctPackage.getPosition());
Assert.assertEquals(packageInfoFile.getCanonicalPath(), ctPackage.getPosition().getFile().getCanonicalPath());
Assert.assertEquals(1, ctPackage.getPosition().getLine());
Assert.assertEquals(1, ctPackage.getAnnotations().size());
Assert.assertEquals("This is test\nJavaDoc.", ctPackage.getComments().get(0).getContent());
CtAnnotation<?> annotation = ctPackage.getAnnotations().get(0);
Assert.assertEquals(Deprecated.class, annotation.getAnnotationType().getActualClass());
Assert.assertEquals(packageInfoFile.getCanonicalPath(), annotation.getPosition().getFile().getCanonicalPath());
Assert.assertEquals(5, annotation.getPosition().getLine());
assertTrue(CtPackage.class.isAssignableFrom(ctPackage.getParent().getClass()));
ctPackage = (CtPackage) ctPackage.getParent();
Assert.assertEquals("spoon.test", ctPackage.getQualifiedName());
Assert.assertEquals("", ctPackage.getDocComment());
}
Aggregations