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()));
}
Aggregations