Search in sources :

Example 1 with JavaDocContext

use of org.eclipse.jdt.internal.corext.template.java.JavaDocContext in project che by eclipse.

the class TemplateProposal method validate.

/*
	 * @see org.eclipse.jface.text.contentassist.ICompletionProposalExtension2#validate(org.eclipse.jface.text.IDocument, int, org.eclipse.jface.text.DocumentEvent)
	 */
public boolean validate(IDocument document, int offset, DocumentEvent event) {
    try {
        int replaceOffset = getReplaceOffset();
        if (offset >= replaceOffset) {
            String content = document.get(replaceOffset, offset - replaceOffset);
            String templateName = fTemplate.getName().toLowerCase();
            boolean valid = templateName.startsWith(content.toLowerCase());
            if (!valid && fContext instanceof JavaDocContext && templateName.startsWith("<")) {
                //$NON-NLS-1$
                valid = templateName.startsWith(content.toLowerCase(), 1);
            }
            return valid;
        }
    } catch (BadLocationException e) {
    // concurrent modification - ignore
    }
    return false;
}
Also used : JavaDocContext(org.eclipse.jdt.internal.corext.template.java.JavaDocContext) StyledString(org.eclipse.jface.viewers.StyledString) Point(org.eclipse.swt.graphics.Point) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 2 with JavaDocContext

use of org.eclipse.jdt.internal.corext.template.java.JavaDocContext 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)

Aggregations

JavaDocContext (org.eclipse.jdt.internal.corext.template.java.JavaDocContext)2 BadLocationException (org.eclipse.jface.text.BadLocationException)2 StyledString (org.eclipse.jface.viewers.StyledString)2 Point (org.eclipse.swt.graphics.Point)2 IDocument (org.eclipse.jface.text.IDocument)1 DocumentTemplateContext (org.eclipse.jface.text.templates.DocumentTemplateContext)1