protected boolean validate(Template template, TemplateContext context) { try { context.getContextType().validate(template.getPattern()); } catch(TemplateException e) { return false; } return true; }
private boolean canEvaluate(TemplateContext context, Template template) { String contextId= context.getContextType().getId(); Matcher wordSelectionMatcher= $_WORD_SELECTION_PATTERN.matcher(template.getPattern()); Matcher lineSelectionMatcher= $_LINE_SELECTION_PATTERN.matcher(template.getPattern()); if (JavaDocContextType.ID.equals(contextId)) { if (!template.matches("", contextId) || !lineSelectionMatcher.find() && !wordSelectionMatcher.find()) //$NON-NLS-1$ return false; } else { if (template.matches("", JavaDocContextType.ID) || !lineSelectionMatcher.find()) //$NON-NLS-1$ return false; } TemplateContextType contextType= JavaPlugin.getDefault().getTemplateContextRegistry().getContextType(template.getContextTypeId()); return contextType instanceof CompilationUnitContextType; }
private boolean canEvaluate(TemplateContext context, Template template) { String contextId= context.getContextType().getId(); Matcher wordSelectionMatcher= $_WORD_SELECTION_PATTERN.matcher(template.getPattern()); Matcher lineSelectionMatcher= $_LINE_SELECTION_PATTERN.matcher(template.getPattern()); if (JavaDocContextType.ID.equals(contextId)) { if (!template.matches("", contextId) || !lineSelectionMatcher.find() && !wordSelectionMatcher.find()) //$NON-NLS-1$ return false; } else { if (template.matches("", JavaDocContextType.ID) || !lineSelectionMatcher.find()) //$NON-NLS-1$ return false; } TemplateContextType contextType= JavaPlugin.getDefault().getTemplateContextRegistry().getContextType(template.getContextTypeId()); return contextType instanceof CompilationUnitContextType; }
@Override public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) { ITextSelection selection= (ITextSelection) viewer.getSelectionProvider().getSelection(); // adjust offset to end of normalized selection if (selection.getOffset() == offset) offset= selection.getOffset() + selection.getLength(); String prefix= extractPrefix(viewer, offset); Region region= new Region(offset - prefix.length(), prefix.length()); TemplateContext context= createContext(viewer, region); if (context == null) return new ICompletionProposal[0]; context.setVariable("selection", selection.getText()); // name of the selection variables {line, word}_selection //$NON-NLS-1$ Template[] templates= getTemplates(context.getContextType().getId()); List<ICompletionProposal> matches= new ArrayList<>(); for (Template template : templates) { try { context.getContextType().validate(template.getPattern()); } catch (TemplateException e) { continue; } if (template.matches(prefix, context.getContextType().getId())) matches.add(createProposal(template, context, (IRegion) region, getRelevance(template, prefix))); } Collections.sort(matches, fgProposalComparator); return matches.toArray(new ICompletionProposal[matches.size()]); }
@Override public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) { ITextSelection selection= (ITextSelection) viewer.getSelectionProvider().getSelection(); // adjust offset to end of normalized selection if (selection.getOffset() == offset) offset= selection.getOffset() + selection.getLength(); String prefix= extractPrefix(viewer, offset); Region region= new Region(offset - prefix.length(), prefix.length()); TemplateContext context= createContext(viewer, region); if (context == null) return new ICompletionProposal[0]; context.setVariable("selection", selection.getText()); // name of the selection variables {line, word}_selection //$NON-NLS-1$ Template[] templates= getTemplates(context.getContextType().getId()); List<ICompletionProposal> matches= new ArrayList<>(); for (int i= 0; i < templates.length; i++) { Template template= templates[i]; try { context.getContextType().validate(template.getPattern()); } catch (TemplateException e) { continue; } if (template.matches(prefix, context.getContextType().getId())) matches.add(createProposal(template, context, (IRegion) region, getRelevance(template, prefix))); } Collections.sort(matches, fgProposalComparator); return matches.toArray(new ICompletionProposal[matches.size()]); }
Template[] templates = getTemplates(context.getContextType().getId()); Template template = templates[i]; try { context.getContextType().validate(template.getPattern()); if (template.matches(prefix, context.getContextType().getId())) { matches.add(createProposal(template, context, (IRegion) region, getRelevance(template, prefix)));
String contextTypeId = context.getContextType().getId(); boolean isTargetContextType = contextTypeId.equals(TargetContextType.TARGET_CONTEXT_TYPE); if (isTargetContextType) { Template template = templates[i]; try { context.getContextType().validate(template.getPattern());
@Override protected void createTemplates(TemplateContext templateContext, ContentAssistContext context, ITemplateAcceptor acceptor) { TemplateContextType contextType = templateContext.getContextType(); Template[] templates = templateStore.getTemplates(contextType.getId()); for (Template template : templates) { if (!acceptor.canAcceptMoreTemplates()) return; if (validate(template, templateContext)) { acceptor.accept(createProposal(template, templateContext, context, getImage(template), getRelevance(template))); } } }
selectionContext.setVariable("text", selectionText); //$NON-NLS-1$ Template[] templates = getTemplates(context.getContextType().getId()); context.getContextType().validate(template.getPattern()); } catch (TemplateException e) { continue; if (!template.matches(prefix, context.getContextType().getId())) { continue;