Search in sources :

Example 96 with IDocument

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

the class TemplateEngine method reset.

/**
	 * Empties the collector.
	 */
public void reset() {
    fProposals.clear();
    for (Iterator<Entry<IDocument, Position>> it = fPositions.entrySet().iterator(); it.hasNext(); ) {
        Entry<IDocument, Position> entry = it.next();
        IDocument doc = entry.getKey();
        Position position = entry.getValue();
        doc.removePosition(position);
    }
    fPositions.clear();
}
Also used : Entry(java.util.Map.Entry) Position(org.eclipse.jface.text.Position) IDocument(org.eclipse.jface.text.IDocument)

Example 97 with IDocument

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

the class ContentAssistInvocationContext method computeIdentifierPrefix.

/**
	 * Computes the identifier (as specified by {@link Character#isJavaIdentifierPart(char)}) that
	 * immediately precedes the invocation offset.
	 *
	 * @return the prefix preceding the content assist invocation offset, <code>null</code> if
	 *         there is no document
	 * @throws org.eclipse.jface.text.BadLocationException if accessing the document fails
	 */
public CharSequence computeIdentifierPrefix() throws BadLocationException {
    if (fPrefix == null) {
        IDocument document = getDocument();
        if (document == null)
            return null;
        int end = getInvocationOffset();
        int start = end;
        while (--start >= 0) {
            if (!Character.isJavaIdentifierPart(document.getChar(start)))
                break;
        }
        start++;
        fPrefix = document.get(start, end - start);
    }
    return fPrefix;
}
Also used : IDocument(org.eclipse.jface.text.IDocument)

Example 98 with IDocument

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

the class CUCorrectionProposal method getAdditionalProposalInfo.

@Override
public Object getAdditionalProposalInfo(IProgressMonitor monitor) {
    StringBuffer buf = new StringBuffer();
    try {
        TextChange change = getTextChange();
        change.setKeepPreviewEdits(true);
        IDocument previewDocument = change.getPreviewDocument(monitor);
        TextEdit rootEdit = change.getPreviewEdit(change.getEdit());
        EditAnnotator ea = new EditAnnotator(buf, previewDocument);
        rootEdit.accept(ea);
        // Final pre-existing region
        ea.unchangedUntil(previewDocument.getLength());
    } catch (CoreException e) {
        JavaPlugin.log(e);
    }
    return buf.toString();
}
Also used : EditAnnotator(org.eclipse.jdt.internal.ui.text.correction.proposals.EditAnnotator) CoreException(org.eclipse.core.runtime.CoreException) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) TextEdit(org.eclipse.text.edits.TextEdit) TextChange(org.eclipse.ltk.core.refactoring.TextChange) IDocument(org.eclipse.jface.text.IDocument)

Example 99 with IDocument

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

the class TemplateProposal method computeRelevance.

/**
     * Computes the relevance to match the relevance values generated by the
     * core content assistant.
     *
     * @return a sensible relevance value.
     */
private int computeRelevance() {
    // see org.eclipse.jdt.internal.codeassist.RelevanceConstants
    final int R_DEFAULT = 0;
    final int R_INTERESTING = 5;
    final int R_CASE = 10;
    final int R_NON_RESTRICTED = 3;
    final int R_EXACT_NAME = 4;
    final int R_INLINE_TAG = 31;
    int base = R_DEFAULT + R_INTERESTING + R_NON_RESTRICTED;
    try {
        if (fContext instanceof DocumentTemplateContext) {
            DocumentTemplateContext templateContext = (DocumentTemplateContext) fContext;
            IDocument document = templateContext.getDocument();
            String content = document.get(fRegion.getOffset(), fRegion.getLength());
            if (content.length() > 0 && fTemplate.getName().startsWith(content))
                base += R_CASE;
            if (fTemplate.getName().equalsIgnoreCase(content))
                base += R_EXACT_NAME;
            if (fContext instanceof JavaDocContext)
                base += R_INLINE_TAG;
        }
    } catch (BadLocationException e) {
    // ignore - not a case sensitive match then
    }
    // see CompletionProposalCollector.computeRelevance
    // just under keywords, but better than packages
    final int TEMPLATE_RELEVANCE = 1;
    return base * 16 + TEMPLATE_RELEVANCE;
}
Also used : DocumentTemplateContext(org.eclipse.jface.text.templates.DocumentTemplateContext) JavaDocContext(org.eclipse.jdt.internal.corext.template.java.JavaDocContext) StyledString(org.eclipse.jface.viewers.StyledString) Point(org.eclipse.swt.graphics.Point) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 100 with IDocument

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

the class TemplateProposal method getAdditionalProposalInfo.

/*
	 * @see ICompletionProposal#getAdditionalProposalInfo()
	 */
public String getAdditionalProposalInfo() {
    try {
        fContext.setReadOnly(true);
        TemplateBuffer templateBuffer;
        try {
            templateBuffer = fContext.evaluate(fTemplate);
        } catch (TemplateException e) {
            return null;
        }
        IDocument document = new Document(templateBuffer.getString());
        IndentUtil.indentLines(document, new LineRange(0, document.getNumberOfLines()), null, null);
        StringBuffer buffer = new StringBuffer();
        HTMLPrinter.insertPageProlog(buffer, 0, JavadocFinder.getStyleSheet());
        HTMLPrinter.addParagraph(buffer, document.get());
        HTMLPrinter.addPageEpilog(buffer);
        return buffer.toString();
    } catch (BadLocationException e) {
        //			handleException(
        //					JavaPlugin.getActiveWorkbenchShell(), new CoreException(new Status(IStatus.ERROR, JavaPlugin.getPluginId(), IStatus.OK, "", e))); //$NON-NLS-1$
        JavaPlugin.log(e);
        return null;
    }
}
Also used : TemplateException(org.eclipse.jface.text.templates.TemplateException) TemplateBuffer(org.eclipse.jface.text.templates.TemplateBuffer) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) LineRange(org.eclipse.che.jface.text.source.LineRange) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException)

Aggregations

IDocument (org.eclipse.jface.text.IDocument)134 BadLocationException (org.eclipse.jface.text.BadLocationException)60 Document (org.eclipse.jface.text.Document)42 CoreException (org.eclipse.core.runtime.CoreException)17 TextEdit (org.eclipse.text.edits.TextEdit)17 IRegion (org.eclipse.jface.text.IRegion)16 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)15 Point (org.eclipse.swt.graphics.Point)13 ArrayList (java.util.ArrayList)12 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)12 TemplateBuffer (org.eclipse.jface.text.templates.TemplateBuffer)9 TemplateVariable (org.eclipse.jface.text.templates.TemplateVariable)9 MalformedTreeException (org.eclipse.text.edits.MalformedTreeException)9 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)8 Position (org.eclipse.jface.text.Position)8 TemplateException (org.eclipse.jface.text.templates.TemplateException)8 MultiTextEdit (org.eclipse.text.edits.MultiTextEdit)8 ITextFileBufferManager (org.eclipse.core.filebuffers.ITextFileBufferManager)7 IFile (org.eclipse.core.resources.IFile)7 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)7