private boolean hasCompatibleContextType(Template template) { String key= getKey(); if (template.matches(key, getContextType().getId())) return true; if (fCompatibleContextTypeIds == null) return false; Iterator<String> iter= fCompatibleContextTypeIds.iterator(); while (iter.hasNext()) { if (template.matches(key, iter.next())) return true; } return false; }
/** * @param prefix The prefix to match against. * @param contextTypeId The current context type id to match against. * @return Returns true if the the contextTypeId matches the templates * context type and the prefix matches the template name. */ public boolean matches(String prefix, String contextTypeId) { if (!super.matches(prefix, contextTypeId)) { return false; } String templateName = getName().toLowerCase(); if (templateName.startsWith(prefix.toLowerCase())) { return true; } return false; } }
private boolean hasCompatibleContextType(Template template) { String key= getKey(); if (template.matches(key, getContextType().getId())) return true; if (fCompatibleContextTypeIds == null) return false; Iterator<String> iter= fCompatibleContextTypeIds.iterator(); while (iter.hasNext()) { if (template.matches(key, iter.next())) return true; } return false; }
public boolean canEvaluate(Template template) { String key= getKey(); if (fForceEvaluation) return true; return template.matches(key, getContextType().getId()) && (key.length() != 0) && template.getName().toLowerCase().startsWith(key.toLowerCase()); }
public boolean canEvaluate(Template template) { if (fForceEvaluation) return true; String key= getKey(); return template.matches(key, getContextType().getId()) && key.length() != 0 && template.getName().toLowerCase().startsWith(key.toLowerCase()); }
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 boolean canEvaluate(Template template) { if (!template.getContextTypeId().equals(getContextType().getId())) return false; if (fForceEvaluation) return true; String key= getKey().toLowerCase(); if (template.matches(key, getContextType().getId()) && key.length() != 0) { String templateName= template.getName().toLowerCase(); return JavaCore.ENABLED.equals(JavaCore.getOption(JavaCore.CODEASSIST_SUBSTRING_MATCH)) ? templateName.contains(key) : templateName.startsWith(key); } return false; }
@Override public boolean canEvaluate(Template template) { if (!template.getContextTypeId().equals(getContextType().getId())) return false; if (fForceEvaluation) return true; String key= getKey().toLowerCase(); if (template.matches(key, getContextType().getId()) && key.length() != 0) { String templateName= template.getName().toLowerCase(); return JavaCore.ENABLED.equals(JavaCore.getOption(JavaCore.CODEASSIST_SUBSTRING_MATCH)) ? templateName.contains(key) : templateName.startsWith(key); } return false; }
public boolean canEvaluate(Template template) { if (getContextType() instanceof GenericSQLContextType) { String key = getKey(); String[] types = ((GenericSQLContextType) getContextType()).getIds(); for (int i = 0; i < types.length; i++) { if (template.matches(getKey(), types[i])) { return true; } } return false; } return super.canEvaluate(template); }
@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()]); }
@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()]); }
continue; if (template.matches(prefix, context.getContextType().getId())) { matches.add(createProposal(template, context, (IRegion) region, getRelevance(template, prefix)));
continue; if (!template.matches(prefix, context.getContextType().getId())) { continue;