//walk backwards to find the beginning of the word we are replacing
int beginning= offset;
if (viewer.getDocument() instanceof HdlDocument) {
HdlDocument doc = (HdlDocument) viewer.getDocument();
String indentationstring = VerilogPlugin.getIndentationString();
String eol = TextUtilities.getDefaultLineDelimiter(doc);
while (beginning > 0) {
try{
char ch= doc.getChar(beginning - 1);
if (!Character.isJavaIdentifierPart(ch))
break;
beginning--;
}
catch (BadLocationException e)
{
//empty list
return results;
}
}
Region region= new Region(beginning, offset-beginning);
String prefix=null;
try{
prefix=doc.get(beginning, offset-beginning);
}
catch (BadLocationException e)
{
//empty list
return results;
}
//get a list of templates
String contextString=getTemplateContextString(context);
TemplateContextType contextType=VerilogPlugin.getPlugin().getContextTypeRegistry().getContextType(contextString);
Template[] templates= VerilogPlugin.getPlugin().getTemplateStore().getTemplates(contextType.getId());
DocumentTemplateContext documnetTemplateContext= new DocumentTemplateContext(contextType, doc, region.getOffset(), region.getLength());
//find a matching template
for (int i= 0; i < templates.length; i++) {
Template template= templates[i];
String pattern = template.getPattern();
pattern = pattern.replace("\t", indentationstring);
pattern = pattern.replace("\r", "");
pattern = pattern.replace("\n", eol);
template.setPattern(pattern);
try {
contextType.validate(template.getPattern());
} catch (TemplateException e) {
continue;
}
if (template.matches(prefix, contextType.getId()) && template.getName().startsWith(prefix)){
String indent = doc.getIndentString(offset);
template = new TemplateWithIndent(template, indent);
HdlTemplateProposal hdlTemplateProposal=new HdlTemplateProposal(template,
documnetTemplateContext,
region,
getTemplateImage(template),