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;
}
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;
}
Aggregations