Search in sources :

Example 6 with BodyHolderSourcePosition

use of spoon.reflect.cu.position.BodyHolderSourcePosition in project spoon by INRIA.

the class PositionTest method testPositionAbstractMethod.

@Test
public void testPositionAbstractMethod() throws Exception {
    final Factory build = build(FooAbstractMethod.class);
    final CtClass<FooMethod> foo = build.Class().get(FooAbstractMethod.class);
    String classContent = getClassContent(foo);
    CtMethod<?> method1 = foo.getMethodsByName("m").get(0);
    BodyHolderSourcePosition position1 = (BodyHolderSourcePosition) method1.getPosition();
    assertEquals(5, position1.getLine());
    assertEquals(5, position1.getEndLine());
    assertEquals(86, position1.getSourceStart());
    assertEquals(125, position1.getSourceEnd());
    assertEquals("public abstract void m(final int parm1);", contentAtPosition(classContent, position1));
    assertEquals("m", contentAtPosition(classContent, position1.getNameStart(), position1.getNameEnd()));
    assertEquals("public abstract", contentAtPosition(classContent, position1.getModifierSourceStart(), position1.getModifierSourceEnd()));
    // contract: body of abstract method is empty
    assertEquals("", contentAtPosition(classContent, position1.getBodyStart(), position1.getBodyEnd()));
    DeclarationSourcePosition positionParam1 = (DeclarationSourcePosition) method1.getParameters().get(0).getPosition();
    assertEquals(5, positionParam1.getLine());
    assertEquals(5, positionParam1.getEndLine());
    assertEquals(109, positionParam1.getSourceStart());
    assertEquals(123, positionParam1.getSourceEnd());
    assertEquals("final int parm1", contentAtPosition(classContent, positionParam1));
    assertEquals("parm1", contentAtPosition(classContent, positionParam1.getNameStart(), positionParam1.getNameEnd()));
    assertEquals("final", contentAtPosition(classContent, positionParam1.getModifierSourceStart(), positionParam1.getModifierSourceEnd()));
}
Also used : FooMethod(spoon.test.position.testclasses.FooMethod) BodyHolderSourcePosition(spoon.reflect.cu.position.BodyHolderSourcePosition) Factory(spoon.reflect.factory.Factory) DeclarationSourcePosition(spoon.reflect.cu.position.DeclarationSourcePosition) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)6 BodyHolderSourcePosition (spoon.reflect.cu.position.BodyHolderSourcePosition)6 Factory (spoon.reflect.factory.Factory)6 DeclarationSourcePosition (spoon.reflect.cu.position.DeclarationSourcePosition)4 File (java.io.File)3 SourcePosition (spoon.reflect.cu.SourcePosition)2 FooMethod (spoon.test.position.testclasses.FooMethod)2 CtMethod (spoon.reflect.declaration.CtMethod)1 FooAnnotation (spoon.test.position.testclasses.FooAnnotation)1 FooClazz (spoon.test.position.testclasses.FooClazz)1 FooGeneric (spoon.test.position.testclasses.FooGeneric)1 FooInterface (spoon.test.position.testclasses.FooInterface)1