package no.uio.ifi.refaktor.utils; import org.eclipse.jdt.core.IMethod; import org.eclipse.jdt.core.JavaModelException; public class MethodRelativeCompilationUnitTextSelection extends CompilationUnitTextSelection { private final IMethod method; private final int relativeOffset; public MethodRelativeCompilationUnitTextSelection(IMethod method, CompilationUnitTextSelection textSelection) { super(textSelection); this.method = method; int methodOffset = 0; try { methodOffset = freshMethodOffset(); } catch (JavaModelException e) { RefaktorDebug.log(e); } relativeOffset = textSelection.getOffset() - methodOffset; } private int freshMethodOffset() throws JavaModelException { return method.getSourceRange().getOffset(); } @Override public int getOffset() { try { return freshMethodOffset() + relativeOffset; } catch (JavaModelException e) { RefaktorDebug.log(e); return super.getOffset(); } } }