use of org.eclipse.jface.text.BadLocationException in project che by eclipse.
the class JavaIndenter method getLeadingWhitespace.
/**
* Returns the indentation of the line at <code>offset</code> as a
* <code>StringBuffer</code>. If the offset is not valid, the empty string
* is returned.
*
* @param offset the offset in the document
* @return the indentation (leading whitespace) of the line in which
* <code>offset</code> is located
*/
private StringBuffer getLeadingWhitespace(int offset) {
StringBuffer indent = new StringBuffer();
try {
IRegion line = fDocument.getLineInformationOfOffset(offset);
int lineOffset = line.getOffset();
int nonWS = fScanner.findNonWhitespaceForwardInAnyPartition(lineOffset, lineOffset + line.getLength());
indent.append(fDocument.get(lineOffset, nonWS - lineOffset));
return indent;
} catch (BadLocationException e) {
return indent;
}
}
use of org.eclipse.jface.text.BadLocationException in project che by eclipse.
the class JavaContext method getEnd.
/*
* @see org.eclipse.jdt.internal.corext.template.DocumentTemplateContext#getEnd()
*/
@Override
public int getEnd() {
if (fIsManaged || getCompletionLength() == 0)
return super.getEnd();
try {
IDocument document = getDocument();
int start = getCompletionOffset();
int end = getCompletionOffset() + getCompletionLength();
while (start != end && Character.isWhitespace(document.getChar(end - 1))) end--;
return end;
} catch (BadLocationException e) {
return super.getEnd();
}
}
use of org.eclipse.jface.text.BadLocationException in project che by eclipse.
the class JavaDocContext method getStart.
/*
* @see DocumentTemplateContext#getStart()
*/
@Override
public int getStart() {
if (fIsManaged && getCompletionLength() > 0)
return super.getStart();
try {
IDocument document = getDocument();
if (getCompletionLength() == 0) {
int start = getCompletionOffset();
if ((start != 0) && (document.getChar(start - 1) == HTML_TAG_END))
start--;
while ((start != 0) && Character.isUnicodeIdentifierPart(document.getChar(start - 1))) start--;
if ((start != 0) && Character.isUnicodeIdentifierStart(document.getChar(start - 1)))
start--;
// include html and javadoc tags
if ((start != 0) && ((document.getChar(start - 1) == HTML_TAG_BEGIN) || (document.getChar(start - 1) == JAVADOC_TAG_BEGIN))) {
start--;
}
return start;
}
int start = getCompletionOffset();
int end = getCompletionOffset() + getCompletionLength();
while (start != 0 && Character.isUnicodeIdentifierPart(document.getChar(start - 1))) start--;
while (start != end && Character.isWhitespace(document.getChar(start))) start++;
if (start == end)
start = getCompletionOffset();
return start;
} catch (BadLocationException e) {
return getCompletionOffset();
}
}
use of org.eclipse.jface.text.BadLocationException in project che by eclipse.
the class JavaDocContext method getKey.
/*
* @see org.eclipse.jdt.internal.corext.template.DocumentTemplateContext#getKey()
*/
@Override
public String getKey() {
if (getCompletionLength() == 0)
return super.getKey();
try {
IDocument document = getDocument();
int start = getStart();
int end = getCompletionOffset();
return start <= end ? document.get(start, end - start) : //$NON-NLS-1$
"";
} catch (BadLocationException e) {
return super.getKey();
}
}
use of org.eclipse.jface.text.BadLocationException in project che by eclipse.
the class JavaDocContext method getEnd.
/*
* @see org.eclipse.jdt.internal.corext.template.DocumentTemplateContext#getEnd()
*/
@Override
public int getEnd() {
if (fIsManaged || getCompletionLength() == 0)
return super.getEnd();
try {
IDocument document = getDocument();
int start = getCompletionOffset();
int end = getCompletionOffset() + getCompletionLength();
while (start != end && Character.isWhitespace(document.getChar(end - 1))) end--;
return end;
} catch (BadLocationException e) {
return super.getEnd();
}
}
Aggregations