]>
Commit | Line | Data |
---|---|---|
9a55edb7 EK |
1 | package no.uio.ifi.refaktor.utils; |
2 | ||
2c782b57 VS |
3 | import org.eclipse.jdt.core.ICompilationUnit; |
4 | import org.eclipse.jdt.core.dom.NodeFinder; | |
9a55edb7 EK |
5 | import org.eclipse.jface.text.IDocument; |
6 | import org.eclipse.jface.text.ITextSelection; | |
7 | import org.eclipse.jface.text.TextSelection; | |
8 | ||
7a978020 EK |
9 | /** |
10 | * A custom TextSelection that enforces the presence of | |
11 | * a document to back the selection. | |
12 | */ | |
9a55edb7 EK |
13 | public class SmartTextSelection extends TextSelection implements ITextSelection { |
14 | ||
15 | public SmartTextSelection(IDocument document, int offset, int length) { | |
16 | super(document, offset, length); | |
17 | if (document == null) | |
18 | throw new NullPointerException(this.getClass().getCanonicalName() + ": given document cannot be null"); | |
19 | } | |
20 | ||
21 | public SmartTextSelection(IDocument document, ITextSelection selection) { | |
22 | this(document, selection.getOffset(), selection.getLength()); | |
23 | } | |
24 | ||
25 | @Override | |
26 | public IDocument getDocument() { | |
27 | IDocument document = super.getDocument(); | |
28 | assert document != null; | |
29 | return document; | |
30 | } | |
31 | ||
b9afe13c EK |
32 | public int getEnd() { |
33 | return getOffset() + getLength(); | |
34 | } | |
35 | ||
2c782b57 VS |
36 | public NodeFinder getNodeFinder() { |
37 | return ParseUtils.getNodeFinder(getDocument(), this); | |
38 | } | |
39 | ||
40 | public NodeFinder getNodeFinder(ICompilationUnit icu) { | |
41 | return ParseUtils.makeNodeFinder(this, ParseUtils.parse(icu)); | |
42 | } | |
9a55edb7 | 43 | } |