Search in sources :

Example 1 with FooAnnotation

use of spoon.test.position.testclasses.FooAnnotation in project spoon by INRIA.

the class PositionTest method testPositionAnnotation.

@Test
public void testPositionAnnotation() throws Exception {
    final Factory build = build(new File("src/test/java/spoon/test/position/testclasses/"));
    final CtType<FooAnnotation> foo = build.Type().get(FooAnnotation.class);
    String classContent = getClassContent(foo);
    BodyHolderSourcePosition position = (BodyHolderSourcePosition) foo.getPosition();
    assertEquals(9, position.getLine());
    assertEquals(11, position.getEndLine());
    assertEquals(163, position.getSourceStart());
    assertEquals(279, position.getSourceEnd());
    assertEquals("@Target(value={})\n" + "@Retention(RetentionPolicy.RUNTIME)  \n" + "public abstract @interface FooAnnotation {\n" + "\tString value();\n" + "}", contentAtPosition(classContent, position));
    assertEquals("{\n" + "\tString value();\n" + "}", contentAtPosition(classContent, position.getBodyStart(), position.getBodyEnd()));
    assertEquals("FooAnnotation", contentAtPosition(classContent, position.getNameStart(), position.getNameEnd()));
    assertEquals("public abstract", contentAtPosition(classContent, position.getModifierSourceStart(), position.getModifierSourceEnd()));
    CtMethod<?> method1 = foo.getMethodsByName("value").get(0);
    BodyHolderSourcePosition position1 = (BodyHolderSourcePosition) method1.getPosition();
    assertEquals(10, position1.getLine());
    assertEquals(10, position1.getEndLine());
    assertEquals(263, position1.getSourceStart());
    assertEquals(277, position1.getSourceEnd());
    assertEquals("String value();", contentAtPosition(classContent, position1));
    assertEquals("value", contentAtPosition(classContent, position1.getNameStart(), position1.getNameEnd()));
    assertEquals("", contentAtPosition(classContent, position1.getModifierSourceStart(), position1.getModifierSourceEnd()));
    // contract: body of abstract method is empty
    assertEquals("", contentAtPosition(classContent, position1.getBodyStart(), position1.getBodyEnd()));
}
Also used : FooAnnotation(spoon.test.position.testclasses.FooAnnotation) BodyHolderSourcePosition(spoon.reflect.cu.position.BodyHolderSourcePosition) Factory(spoon.reflect.factory.Factory) File(java.io.File) Test(org.junit.Test)

Aggregations

File (java.io.File)1 Test (org.junit.Test)1 BodyHolderSourcePosition (spoon.reflect.cu.position.BodyHolderSourcePosition)1 Factory (spoon.reflect.factory.Factory)1 FooAnnotation (spoon.test.position.testclasses.FooAnnotation)1