Search in sources :

Example 1 with FooInterface

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

the class PositionTest method testPositionInterface.

@Test
public void testPositionInterface() throws Exception {
    final Factory build = build(new File("src/test/java/spoon/test/position/testclasses/"));
    final CtType<FooInterface> foo = build.Type().get(FooInterface.class);
    String classContent = getClassContent(foo);
    BodyHolderSourcePosition position = (BodyHolderSourcePosition) foo.getPosition();
    assertEquals(7, position.getLine());
    assertEquals(9, position.getEndLine());
    assertEquals(96, position.getSourceStart());
    assertEquals(169, position.getSourceEnd());
    assertEquals("@Deprecated\n" + "@InnerAnnot(value=\"machin\")\n" + "public interface FooInterface {\n" + "\n" + "}", contentAtPosition(classContent, position));
    assertEquals("{\n\n}", contentAtPosition(classContent, position.getBodyStart(), position.getBodyEnd()));
    assertEquals("FooInterface", contentAtPosition(classContent, position.getNameStart(), position.getNameEnd()));
    assertEquals("public", contentAtPosition(classContent, position.getModifierSourceStart(), position.getModifierSourceEnd()));
    {
        SourcePosition annPosition = foo.getAnnotations().get(0).getPosition();
        assertEquals("@Deprecated", contentAtPosition(classContent, annPosition.getSourceStart(), annPosition.getSourceEnd()));
    }
    {
        SourcePosition annPosition = foo.getAnnotations().get(1).getPosition();
        assertEquals("@InnerAnnot(value=\"machin\")", contentAtPosition(classContent, annPosition.getSourceStart(), annPosition.getSourceEnd()));
    }
}
Also used : BodyHolderSourcePosition(spoon.reflect.cu.position.BodyHolderSourcePosition) DeclarationSourcePosition(spoon.reflect.cu.position.DeclarationSourcePosition) BodyHolderSourcePosition(spoon.reflect.cu.position.BodyHolderSourcePosition) SourcePosition(spoon.reflect.cu.SourcePosition) Factory(spoon.reflect.factory.Factory) File(java.io.File) FooInterface(spoon.test.position.testclasses.FooInterface) Test(org.junit.Test)

Aggregations

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