Bug 510030 - Add toString() to Line and TextSelection
Change-Id: Idc8d4bd0224d1a84932e02a9914bf1f59fe56580
Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/TextSelection.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/TextSelection.java
index b29e1ea..92e4fb0 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/TextSelection.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/TextSelection.java
@@ -123,6 +123,7 @@
if (fDocument != null)
return fDocument.getLineOfOffset(fOffset);
} catch (BadLocationException x) {
+ // ignore
}
return -1;
@@ -138,6 +139,7 @@
return fDocument.getLineOfOffset(endOffset);
}
} catch (BadLocationException x) {
+ // ignore
}
return -1;
@@ -149,6 +151,7 @@
if (fDocument != null)
return fDocument.get(fOffset, fLength);
} catch (BadLocationException x) {
+ // ignore
}
return null;
@@ -176,6 +179,7 @@
String content= fDocument.get(fOffset, fLength);
return sContent.equals(content);
} catch (BadLocationException x) {
+ // ignore
}
}
@@ -197,5 +201,26 @@
protected IDocument getDocument() {
return fDocument;
}
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ sb.append("TextSelection [offset: ").append(fOffset); //$NON-NLS-1$
+ int startLine = getStartLine();
+ sb.append(", startLine: ").append(startLine); //$NON-NLS-1$
+ int endLine = getEndLine();
+ if (endLine != startLine) {
+ sb.append(", endLine: ").append(endLine); //$NON-NLS-1$
+ }
+ sb.append(", length: ").append(fLength); //$NON-NLS-1$
+ if (fLength != 0) {
+ sb.append(", text: ").append(getText()); //$NON-NLS-1$
+ }
+ if (fDocument != null) {
+ sb.append(", document: ").append(fDocument); //$NON-NLS-1$
+ }
+ sb.append("]"); //$NON-NLS-1$
+ return sb.toString();
+ }
}
diff --git a/org.eclipse.text/src/org/eclipse/jface/text/Line.java b/org.eclipse.text/src/org/eclipse/jface/text/Line.java
index 9e1dd7a..f219c0d 100644
--- a/org.eclipse.text/src/org/eclipse/jface/text/Line.java
+++ b/org.eclipse.text/src/org/eclipse/jface/text/Line.java
@@ -59,6 +59,11 @@
public int getLength() {
return length;
}
+
+ @Override
+ public String toString() {
+ return "Line [offset: " + offset + ", length: " + length + ", delimiter: '" + delimiter + "']"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ }
}