Search in sources :

Example 11 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 12 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 13 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)

Example 14 with BadLocationException

use of org.eclipse.jface.text.BadLocationException in project che by eclipse.

the class JavaFormatter method format.

/**
	 * Formats the template buffer.
	 * @param buffer
	 * @param context
	 * @throws BadLocationException
	 */
public void format(TemplateBuffer buffer, TemplateContext context) throws BadLocationException {
    try {
        VariableTracker tracker = new VariableTracker(buffer);
        IDocument document = tracker.getDocument();
        internalFormat(document, context);
        convertLineDelimiters(document);
        if (!(context instanceof JavaDocContext) && !isReplacedAreaEmpty(context))
            trimStart(document);
        tracker.updateBuffer();
    } catch (MalformedTreeException e) {
        throw new BadLocationException();
    }
}
Also used : MalformedTreeException(org.eclipse.text.edits.MalformedTreeException) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 15 with BadLocationException

use of org.eclipse.jface.text.BadLocationException in project che by eclipse.

the class UndoDocumentChange method perform.

/**
	 * {@inheritDoc}
	 */
public Change perform(IProgressMonitor pm) throws CoreException {
    try {
        UndoEdit redo = performEdits();
        Change result = new UndoDocumentChange(getName(), fDocument, redo);
        return result;
    } catch (MalformedTreeException e) {
        throw Changes.asCoreException(e);
    } catch (BadLocationException e) {
        throw Changes.asCoreException(e);
    }
}
Also used : MalformedTreeException(org.eclipse.text.edits.MalformedTreeException) Change(org.eclipse.ltk.core.refactoring.Change) UndoEdit(org.eclipse.text.edits.UndoEdit) BadLocationException(org.eclipse.jface.text.BadLocationException)

Aggregations

BadLocationException (org.eclipse.jface.text.BadLocationException)133 IDocument (org.eclipse.jface.text.IDocument)58 IRegion (org.eclipse.jface.text.IRegion)43 Document (org.eclipse.jface.text.Document)26 Point (org.eclipse.swt.graphics.Point)17 CoreException (org.eclipse.core.runtime.CoreException)16 Position (org.eclipse.jface.text.Position)13 StyledString (org.eclipse.jface.viewers.StyledString)13 MalformedTreeException (org.eclipse.text.edits.MalformedTreeException)13 TemplateBuffer (org.eclipse.jface.text.templates.TemplateBuffer)12 TemplateException (org.eclipse.jface.text.templates.TemplateException)12 TextEdit (org.eclipse.text.edits.TextEdit)12 UndoEdit (org.eclipse.text.edits.UndoEdit)10 Region (org.eclipse.jface.text.Region)9 ASTNode (org.eclipse.jdt.core.dom.ASTNode)8 ArrayList (java.util.ArrayList)7 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)7 ITextFileBuffer (org.eclipse.core.filebuffers.ITextFileBuffer)6 BadPositionCategoryException (org.eclipse.jface.text.BadPositionCategoryException)6 DefaultLineTracker (org.eclipse.jface.text.DefaultLineTracker)6