public final static OffsetAndLength calculateOffset(BodyDeclaration declaration, boolean includingModifiers) {
if (!(declaration instanceof MethodDeclaration ) &&
!(declaration instanceof TypeDeclaration ) ) {
throw new IllegalArgumentException("declaration must be TypeDeclaration or MethodDeclaration");
}
SimpleName methodName = nameFor(declaration);
if (!includingModifiers) {
return new OffsetAndLength(methodName.getStartPosition(), methodName.getLength());
} else {
// including modifiers
int endOfMethodName = methodName.getStartPosition() + methodName.getLength();
ChildListPropertyDescriptor modifiersProperty = declaration.getModifiersProperty();
List<ASTNode> methodModifiers =
Generics.asT(declaration.getStructuralProperty(modifiersProperty));
if (methodModifiers.size() > 0) {
int startOfModifiers = methodModifiers.get(0).getStartPosition();