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