use of spoon.reflect.declaration.CtType in project spoon by INRIA.
the class AnnotationTest method testRepeatableAnnotationAreManaged.
@Test
public void testRepeatableAnnotationAreManaged() {
// contract: when two identical repeatable annotation are used, they should be displayed in two different annotations and not factorized
Launcher spoon = new Launcher();
spoon.addInputResource("./src/test/java/spoon/test/annotation/testclasses/repeatable");
spoon.buildModel();
CtType type = spoon.getFactory().Type().get(Repeated.class);
CtMethod firstMethod = (CtMethod) type.getMethodsByName("method").get(0);
List<CtAnnotation<?>> annotations = firstMethod.getAnnotations();
assertEquals(2, annotations.size());
for (CtAnnotation a : annotations) {
assertEquals("Tag", a.getAnnotationType().getSimpleName());
}
String classContent = type.toString();
assertTrue("Content of the file: " + classContent, classContent.contains("@spoon.test.annotation.testclasses.repeatable.Tag(\"machin\")"));
assertTrue("Content of the file: " + classContent, classContent.contains("@spoon.test.annotation.testclasses.repeatable.Tag(\"truc\")"));
}
use of spoon.reflect.declaration.CtType in project spoon by INRIA.
the class AnnotationTest method testSpoonManageRecursivelyDefinedAnnotation.
@Test
public void testSpoonManageRecursivelyDefinedAnnotation() {
// contract: Spoon manage to process recursively defined annotation in shadow classes
Launcher spoon = new Launcher();
CtType type = spoon.getFactory().Type().get(AliasFor.class);
assertEquals(3, type.getFields().size());
}
use of spoon.reflect.declaration.CtType in project spoon by INRIA.
the class AnnotationTest method testRepeatableAnnotationAreManagedWithArrays.
@Test
public void testRepeatableAnnotationAreManagedWithArrays() {
// contract: when two identical repeatable annotation with arrays are used, they should be displayed in two different annotations and not factorized
Launcher spoon = new Launcher();
spoon.addInputResource("./src/test/java/spoon/test/annotation/testclasses/repeatandarrays");
spoon.buildModel();
CtType type = spoon.getFactory().Type().get(RepeatedArrays.class);
CtMethod firstMethod = (CtMethod) type.getMethodsByName("method").get(0);
List<CtAnnotation<?>> annotations = firstMethod.getAnnotations();
assertEquals(2, annotations.size());
for (CtAnnotation a : annotations) {
assertEquals("TagArrays", a.getAnnotationType().getSimpleName());
}
String classContent = type.toString();
assertTrue("Content of the file: " + classContent, classContent.contains("@spoon.test.annotation.testclasses.repeatandarrays.TagArrays({ \"machin\", \"truc\" })"));
assertTrue("Content of the file: " + classContent, classContent.contains("@spoon.test.annotation.testclasses.repeatandarrays.TagArrays({ \"truc\", \"bidule\" })"));
}
use of spoon.reflect.declaration.CtType in project spoon by INRIA.
the class AnnotationTest method testCreateRepeatableAnnotationWithArrays.
@Test
public void testCreateRepeatableAnnotationWithArrays() {
// contract: when using annotate with a repeatable annotation, it will create a new annotation, even if an annotation with an array already exists
Launcher spoon = new Launcher();
spoon.addInputResource("./src/test/java/spoon/test/annotation/testclasses/repeatandarrays");
spoon.buildModel();
CtType type = spoon.getFactory().Type().get(Repeated.class);
CtMethod firstMethod = (CtMethod) type.getMethodsByName("withoutAnnotation").get(0);
List<CtAnnotation<?>> annotations = firstMethod.getAnnotations();
assertTrue(annotations.isEmpty());
spoon.getFactory().Annotation().annotate(firstMethod, TagArrays.class, "value", "foo");
assertEquals(1, firstMethod.getAnnotations().size());
spoon.getFactory().Annotation().annotate(firstMethod, TagArrays.class, "value", "bar");
annotations = firstMethod.getAnnotations();
assertEquals(2, annotations.size());
for (CtAnnotation a : annotations) {
assertEquals("TagArrays", a.getAnnotationType().getSimpleName());
}
String classContent = type.toString();
assertTrue("Content of the file: " + classContent, classContent.contains("@spoon.test.annotation.testclasses.repeatandarrays.TagArrays(\"foo\")"));
assertTrue("Content of the file: " + classContent, classContent.contains("@spoon.test.annotation.testclasses.repeatandarrays.TagArrays(\"bar\")"));
}
use of spoon.reflect.declaration.CtType in project spoon by INRIA.
the class TestCompilationUnit method testCompilationUnitDeclaredTypes.
@Test
public void testCompilationUnitDeclaredTypes() throws IOException {
// contract: the list of declared types should be unmodifiable
File resource = new File("./src/test/java/spoon/test/model/Foo.java");
final Launcher launcher = new Launcher();
launcher.addInputResource(resource.getPath());
launcher.buildModel();
CompilationUnit cu = launcher.getFactory().CompilationUnit().getOrCreate(resource.getCanonicalPath());
assertEquals(3, cu.getDeclaredTypes().size());
List<CtType<?>> typeList = cu.getDeclaredTypes();
try {
typeList.remove(0);
fail();
} catch (UnsupportedOperationException e) {
// do nothing
}
}
Aggregations