Search in sources :

Example 46 with IDocument

use of org.eclipse.jface.text.IDocument 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 47 with IDocument

use of org.eclipse.jface.text.IDocument 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 48 with IDocument

use of org.eclipse.jface.text.IDocument 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 49 with IDocument

use of org.eclipse.jface.text.IDocument 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 50 with IDocument

use of org.eclipse.jface.text.IDocument 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)

Aggregations

IDocument (org.eclipse.jface.text.IDocument)488 BadLocationException (org.eclipse.jface.text.BadLocationException)195 Document (org.eclipse.jface.text.Document)118 Test (org.junit.Test)93 IRegion (org.eclipse.jface.text.IRegion)72 Point (org.eclipse.swt.graphics.Point)63 ITextFileBuffer (org.eclipse.core.filebuffers.ITextFileBuffer)54 Position (org.eclipse.jface.text.Position)51 ArrayList (java.util.ArrayList)44 CoreException (org.eclipse.core.runtime.CoreException)39 ITextFileBufferManager (org.eclipse.core.filebuffers.ITextFileBufferManager)30 IPath (org.eclipse.core.runtime.IPath)26 IFile (org.eclipse.core.resources.IFile)25 IStatus (org.eclipse.core.runtime.IStatus)25 ITextEditor (org.eclipse.ui.texteditor.ITextEditor)24 TextEdit (org.eclipse.text.edits.TextEdit)23 Region (org.eclipse.jface.text.Region)22 IAnnotationModel (org.eclipse.jface.text.source.IAnnotationModel)22 LinkedPositionGroup (org.eclipse.jface.text.link.LinkedPositionGroup)21 IDocumentProvider (org.eclipse.ui.texteditor.IDocumentProvider)20