1 package no.uio.ifi.refaktor.utils;
3 import org.eclipse.jdt.core.ICompilationUnit;
4 import org.eclipse.jdt.core.dom.NodeFinder;
5 import org.eclipse.jface.text.IDocument;
6 import org.eclipse.jface.text.ITextSelection;
7 import org.eclipse.jface.text.TextSelection;
10 * A custom TextSelection that enforces the presence of
11 * a document to back the selection.
13 public class SmartTextSelection extends TextSelection implements ITextSelection {
15 public SmartTextSelection(IDocument document, int offset, int length) {
16 super(document, offset, length);
18 throw new NullPointerException(this.getClass().getCanonicalName() + ": given document cannot be null");
21 public SmartTextSelection(IDocument document, ITextSelection selection) {
22 this(document, selection.getOffset(), selection.getLength());
26 public IDocument getDocument() {
27 IDocument document = super.getDocument();
28 assert document != null;
33 return getOffset() + getLength();
36 public NodeFinder getNodeFinder() {
37 return ParseUtils.getNodeFinder(getDocument(), this);
40 public NodeFinder getNodeFinder(ICompilationUnit icu) {
41 return ParseUtils.makeNodeFinder(this, ParseUtils.parse(icu));