]> git.uio.no Git - ifi-stolz-refaktor.git/blame - software/no.uio.ifi.refaktor/src/no/uio/ifi/refaktor/utils/SmartTextSelection.java
Adding some JavaDoc and cleaning up a bit.
[ifi-stolz-refaktor.git] / software / no.uio.ifi.refaktor / src / no / uio / ifi / refaktor / utils / SmartTextSelection.java
CommitLineData
9a55edb7
EK
1package no.uio.ifi.refaktor.utils;
2
2c782b57
VS
3import org.eclipse.jdt.core.ICompilationUnit;
4import org.eclipse.jdt.core.dom.NodeFinder;
9a55edb7
EK
5import org.eclipse.jface.text.IDocument;
6import org.eclipse.jface.text.ITextSelection;
7import 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
13public 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}