Search in sources :

Example 1 with DocumentTemplateContext

use of org.eclipse.jface.text.templates.DocumentTemplateContext in project che by eclipse.

the class TemplateProposal method getReplaceEndOffset.

/**
	 * Returns the end offset of the range in the document that will be replaced
	 * by applying this template.
	 *
	 * @return the end offset of the range in the document that will be replaced
	 *         by applying this template
	 */
protected final int getReplaceEndOffset() {
    int end;
    if (fContext instanceof DocumentTemplateContext) {
        DocumentTemplateContext docContext = (DocumentTemplateContext) fContext;
        end = docContext.getEnd();
    } else {
        end = fRegion.getOffset() + fRegion.getLength();
    }
    return end;
}
Also used : DocumentTemplateContext(org.eclipse.jface.text.templates.DocumentTemplateContext) Point(org.eclipse.swt.graphics.Point)

Example 2 with DocumentTemplateContext

use of org.eclipse.jface.text.templates.DocumentTemplateContext in project eclipse.platform.text by eclipse.

the class TemplateVariablesWordSelectionTest method setUp.

@Before
public void setUp() {
    fTranslator = new TemplateTranslator();
    fType = new TemplateContextType();
    fType.addResolver(new GlobalTemplateVariables.WordSelection());
    fContext = new DocumentTemplateContext(fType, new Document(), 0, 0);
}
Also used : DocumentTemplateContext(org.eclipse.jface.text.templates.DocumentTemplateContext) GlobalTemplateVariables(org.eclipse.jface.text.templates.GlobalTemplateVariables) Document(org.eclipse.jface.text.Document) TemplateContextType(org.eclipse.jface.text.templates.TemplateContextType) TemplateTranslator(org.eclipse.jface.text.templates.TemplateTranslator) Before(org.junit.Before)

Example 3 with DocumentTemplateContext

use of org.eclipse.jface.text.templates.DocumentTemplateContext 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 4 with DocumentTemplateContext

use of org.eclipse.jface.text.templates.DocumentTemplateContext in project che by eclipse.

the class TemplateProposal method getReplaceOffset.

/**
	 * Returns the offset of the range in the document that will be replaced by
	 * applying this template.
	 *
	 * @return the offset of the range in the document that will be replaced by
	 *         applying this template
	 */
protected final int getReplaceOffset() {
    int start;
    if (fContext instanceof DocumentTemplateContext) {
        DocumentTemplateContext docContext = (DocumentTemplateContext) fContext;
        start = docContext.getStart();
    } else {
        start = fRegion.getOffset();
    }
    return start;
}
Also used : DocumentTemplateContext(org.eclipse.jface.text.templates.DocumentTemplateContext) Point(org.eclipse.swt.graphics.Point)

Example 5 with DocumentTemplateContext

use of org.eclipse.jface.text.templates.DocumentTemplateContext in project eclipse.platform.text by eclipse.

the class GlobalTemplateVariablesDateTest method setUp.

@Before
public void setUp() {
    fTranslator = new TemplateTranslator();
    fType = new TemplateContextType();
    fType.addResolver(new GlobalTemplateVariables.Date());
    fContext = new DocumentTemplateContext(fType, new Document(), 0, 0);
}
Also used : DocumentTemplateContext(org.eclipse.jface.text.templates.DocumentTemplateContext) GlobalTemplateVariables(org.eclipse.jface.text.templates.GlobalTemplateVariables) Document(org.eclipse.jface.text.Document) TemplateContextType(org.eclipse.jface.text.templates.TemplateContextType) TemplateTranslator(org.eclipse.jface.text.templates.TemplateTranslator) Before(org.junit.Before)

Aggregations

DocumentTemplateContext (org.eclipse.jface.text.templates.DocumentTemplateContext)5 Point (org.eclipse.swt.graphics.Point)3 Document (org.eclipse.jface.text.Document)2 GlobalTemplateVariables (org.eclipse.jface.text.templates.GlobalTemplateVariables)2 TemplateContextType (org.eclipse.jface.text.templates.TemplateContextType)2 TemplateTranslator (org.eclipse.jface.text.templates.TemplateTranslator)2 Before (org.junit.Before)2 JavaDocContext (org.eclipse.jdt.internal.corext.template.java.JavaDocContext)1 BadLocationException (org.eclipse.jface.text.BadLocationException)1 IDocument (org.eclipse.jface.text.IDocument)1 StyledString (org.eclipse.jface.viewers.StyledString)1