Search in sources :

Example 1 with FooGeneric

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

the class PositionTest method testPositionGeneric.

@Test
public void testPositionGeneric() throws Exception {
    final Factory build = build(FooGeneric.class);
    final CtClass<FooGeneric> foo = build.Class().get(FooGeneric.class);
    String classContent = getClassContent(foo);
    BodyHolderSourcePosition position = (BodyHolderSourcePosition) foo.getPosition();
    assertEquals(3, position.getLine());
    assertEquals(31, position.getEndLine());
    assertEquals(42, position.getSourceStart());
    assertEquals(411, position.getSourceEnd());
    assertEquals("FooGeneric", contentAtPosition(classContent, position.getNameStart(), position.getNameEnd()));
    assertEquals("public", contentAtPosition(classContent, position.getModifierSourceStart(), position.getModifierSourceEnd()));
    DeclarationSourcePosition position1 = (DeclarationSourcePosition) foo.getField("variable").getPosition();
    assertEquals(5, position1.getLine());
    assertEquals(5, position1.getEndLine());
    assertEquals(88, position1.getSourceStart());
    assertEquals(118, position1.getSourceEnd());
    assertEquals("public final T variable = null;", contentAtPosition(classContent, position1));
    assertEquals("variable", contentAtPosition(classContent, position1.getNameStart(), position1.getNameEnd()));
    assertEquals("public final", contentAtPosition(classContent, position1.getModifierSourceStart(), position1.getModifierSourceEnd()));
    CtMethod<?> method1 = foo.getMethodsByName("m").get(0);
    BodyHolderSourcePosition position2 = (BodyHolderSourcePosition) method1.getPosition();
    assertEquals("public @Deprecated static <S> S m(int parm1) {\n" + "\t\treturn null;\n" + "\t}", contentAtPosition(classContent, position2));
    assertEquals("m", contentAtPosition(classContent, position2.getNameStart(), position2.getNameEnd()));
    // /!\ the annotations can be between two modifiers
    assertEquals("public @Deprecated static", contentAtPosition(classContent, position2.getModifierSourceStart(), position2.getModifierSourceEnd()));
}
Also used : BodyHolderSourcePosition(spoon.reflect.cu.position.BodyHolderSourcePosition) FooGeneric(spoon.test.position.testclasses.FooGeneric) Factory(spoon.reflect.factory.Factory) DeclarationSourcePosition(spoon.reflect.cu.position.DeclarationSourcePosition) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 BodyHolderSourcePosition (spoon.reflect.cu.position.BodyHolderSourcePosition)1 DeclarationSourcePosition (spoon.reflect.cu.position.DeclarationSourcePosition)1 Factory (spoon.reflect.factory.Factory)1 FooGeneric (spoon.test.position.testclasses.FooGeneric)1