]> git.uio.no Git - ifi-stolz-refaktor.git/blame - software/no.uio.ifi.refaktor/src/no/uio/ifi/refaktor/utils/MethodRelativeCompilationUnitTextSelection.java
NullMethodHandle: throwing UnsupportedNullObjectOperationException instead of returni...
[ifi-stolz-refaktor.git] / software / no.uio.ifi.refaktor / src / no / uio / ifi / refaktor / utils / MethodRelativeCompilationUnitTextSelection.java
CommitLineData
6d081f7a
EK
1package no.uio.ifi.refaktor.utils;
2
3import org.eclipse.jdt.core.IMethod;
4import org.eclipse.jdt.core.JavaModelException;
5
6
7public class MethodRelativeCompilationUnitTextSelection extends CompilationUnitTextSelection {
8
9 private final IMethod method;
10 private final int relativeOffset;
11
12 public MethodRelativeCompilationUnitTextSelection(IMethod method, CompilationUnitTextSelection textSelection) {
13 super(textSelection);
14 this.method = method;
15
16 int methodOffset = 0;
17 try {
18 methodOffset = freshMethodOffset();
19 } catch (JavaModelException e) {
20 RefaktorDebug.log(e);
21 }
22 relativeOffset = textSelection.getOffset() - methodOffset;
23 }
24
25 private int freshMethodOffset() throws JavaModelException {
26 return method.getSourceRange().getOffset();
27 }
28
29 @Override
30 public int getOffset() {
31 try {
32 return freshMethodOffset() + relativeOffset;
33 } catch (JavaModelException e) {
34 RefaktorDebug.log(e);
35 return super.getOffset();
36 }
37 }
38
39}