Search in sources :

Example 1 with FooClazz

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

the class PositionTest method testPositionClass.

@Test
public void testPositionClass() throws Exception {
    final Factory build = build(new File("src/test/java/spoon/test/position/testclasses/"));
    final CtType<FooClazz> foo = build.Type().get(FooClazz.class);
    String classContent = getClassContent(foo);
    BodyHolderSourcePosition position = (BodyHolderSourcePosition) foo.getPosition();
    assertEquals(4, position.getLine());
    assertEquals(6, position.getEndLine());
    assertEquals(42, position.getSourceStart());
    assertEquals(79, position.getSourceEnd());
    assertEquals("@Deprecated\n" + "public class FooClazz {\n" + "\n" + "}", contentAtPosition(classContent, position));
    assertEquals("{\n\n}", contentAtPosition(classContent, position.getBodyStart(), position.getBodyEnd()));
    // this specifies that getLine starts at name (and not at Javadoc or annotation)
    final CtType<FooClazz> foo2 = build.Type().get(FooClazz2.class);
    assertEquals(42, foo2.getPosition().getSourceStart());
    assertEquals(4, foo2.getPosition().getLine());
    assertEquals(4, foo2.getPosition().getEndLine());
    assertEquals("FooClazz", contentAtPosition(classContent, position.getNameStart(), position.getNameEnd()));
    assertEquals("public", contentAtPosition(classContent, position.getModifierSourceStart(), position.getModifierSourceEnd()));
}
Also used : FooClazz(spoon.test.position.testclasses.FooClazz) 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 FooClazz (spoon.test.position.testclasses.FooClazz)1