]>
Commit | Line | Data |
---|---|---|
6d081f7a EK |
1 | package no.uio.ifi.refaktor.utils; |
2 | ||
3 | import org.eclipse.jdt.core.IMethod; | |
4 | import org.eclipse.jdt.core.JavaModelException; | |
5 | ||
6 | ||
7 | public 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 | } |