Search in sources :

Example 41 with BadLocationException

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;
    }
}
Also used : IRegion(org.eclipse.jface.text.IRegion) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 42 with BadLocationException

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();
    }
}
Also used : IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 43 with BadLocationException

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();
    }
}
Also used : IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 44 with BadLocationException

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();
    }
}
Also used : IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 45 with BadLocationException

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();
    }
}
Also used : IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException)

Aggregations

BadLocationException (org.eclipse.jface.text.BadLocationException)455 IDocument (org.eclipse.jface.text.IDocument)196 IRegion (org.eclipse.jface.text.IRegion)161 Test (org.junit.Test)102 Position (org.eclipse.jface.text.Position)101 Region (org.eclipse.jface.text.Region)68 Point (org.eclipse.swt.graphics.Point)61 Document (org.eclipse.jface.text.Document)47 CoreException (org.eclipse.core.runtime.CoreException)34 ArrayList (java.util.ArrayList)27 ITypedRegion (org.eclipse.jface.text.ITypedRegion)27 BadPositionCategoryException (org.eclipse.jface.text.BadPositionCategoryException)22 DocumentEvent (org.eclipse.jface.text.DocumentEvent)21 ITextSelection (org.eclipse.jface.text.ITextSelection)21 StyledText (org.eclipse.swt.custom.StyledText)18 StyledString (org.eclipse.jface.viewers.StyledString)17 IStatus (org.eclipse.core.runtime.IStatus)16 ITextFileBuffer (org.eclipse.core.filebuffers.ITextFileBuffer)15 FindReplaceDocumentAdapter (org.eclipse.jface.text.FindReplaceDocumentAdapter)15 MalformedTreeException (org.eclipse.text.edits.MalformedTreeException)15