Search in sources :

Example 26 with IDocument

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

the class JavaTypeCompletionProposalComputer method guessContextInformationPosition.

@Override
protected int guessContextInformationPosition(ContentAssistInvocationContext context) {
    final int contextPosition = context.getInvocationOffset();
    IDocument document = context.getDocument();
    JavaHeuristicScanner scanner = new JavaHeuristicScanner(document);
    int bound = Math.max(-1, contextPosition - 200);
    // try the innermost scope of angle brackets that looks like a generic type argument list
    try {
        int pos = contextPosition - 1;
        do {
            int angle = scanner.findOpeningPeer(pos, bound, '<', '>');
            if (angle == JavaHeuristicScanner.NOT_FOUND)
                break;
            int token = scanner.previousToken(angle - 1, bound);
            // next token must be a method name that is a generic type
            if (token == Symbols.TokenIDENT) {
                int off = scanner.getPosition() + 1;
                int end = angle;
                String ident = document.get(off, end - off).trim();
                if (JavaHeuristicScanner.isGenericStarter(ident))
                    return angle + 1;
            }
            pos = angle - 1;
        } while (true);
    } catch (BadLocationException x) {
    }
    return super.guessContextInformationPosition(context);
}
Also used : JavaHeuristicScanner(org.eclipse.jdt.internal.ui.text.JavaHeuristicScanner) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 27 with IDocument

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

the class JavaContext 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 28 with IDocument

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

the class JavaContext method getIndentation.

/**
	 * Returns the indentation level at the position of code completion.
	 *
	 * @return the indentation level at the position of the code completion
	 */
private int getIndentation() {
    int start = getStart();
    IDocument document = getDocument();
    try {
        IRegion region = document.getLineInformationOfOffset(start);
        String lineContent = document.get(region.getOffset(), region.getLength());
        IJavaProject project = getJavaProject();
        return Strings.computeIndentUnits(lineContent, project);
    } catch (BadLocationException e) {
        return 0;
    }
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject) IDocument(org.eclipse.jface.text.IDocument) IRegion(org.eclipse.jface.text.IRegion) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 29 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 30 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)

Aggregations

IDocument (org.eclipse.jface.text.IDocument)1055 BadLocationException (org.eclipse.jface.text.BadLocationException)379 Document (org.eclipse.jface.text.Document)189 IRegion (org.eclipse.jface.text.IRegion)150 Test (org.junit.Test)107 CoreException (org.eclipse.core.runtime.CoreException)102 Point (org.eclipse.swt.graphics.Point)94 IFile (org.eclipse.core.resources.IFile)90 ArrayList (java.util.ArrayList)85 ITextFileBuffer (org.eclipse.core.filebuffers.ITextFileBuffer)84 Position (org.eclipse.jface.text.Position)74 ITextEditor (org.eclipse.ui.texteditor.ITextEditor)74 IEditorPart (org.eclipse.ui.IEditorPart)62 ITextFileBufferManager (org.eclipse.core.filebuffers.ITextFileBufferManager)54 IPath (org.eclipse.core.runtime.IPath)54 ITextSelection (org.eclipse.jface.text.ITextSelection)53 TextEdit (org.eclipse.text.edits.TextEdit)49 Region (org.eclipse.jface.text.Region)47 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)44 IDocumentProvider (org.eclipse.ui.texteditor.IDocumentProvider)41