/** * Adds a context type to the registry. If there already is a context type * with the same ID registered, it is replaced. * * @param contextType the context type to add */ public void addContextType(TemplateContextType contextType) { fContextTypes.put(contextType.getId(), contextType); }
/** * Adds a context type to the registry. If there already is a context type * with the same ID registered, it is replaced. * * @param contextType the context type to add */ public void addContextType(TemplateContextType contextType) { fContextTypes.put(contextType.getId(), contextType); }
private boolean isActiveContext(TemplateContextType contextType) { return fActiveTypes == null || fActiveTypes.contains(contextType.getId()); }
private boolean isActiveContext(TemplateContextType contextType) { return fActiveTypes == null || fActiveTypes.contains(contextType.getId()); }
@Override public Object[] getChildren(Object parentElement) { if (parentElement instanceof TemplatePersistenceData) return new Object[0]; else if (parentElement instanceof TemplateContextType) { TemplateContextType contextType= (TemplateContextType) parentElement; return getTemplates(contextType.getId()); } return null; }
@Override public boolean equals(Object obj) { if (obj == null || !(obj instanceof TemplateContextType)) return false; if (obj == this) return true; TemplateContextType contextType = (TemplateContextType) obj; return getId().equals(contextType.getId()); }
@Override public Object[] getChildren(Object parentElement) { if (parentElement instanceof TemplatePersistenceData) return new Object[0]; else if (parentElement instanceof TemplateContextType) { TemplateContextType contextType= (TemplateContextType) parentElement; return getTemplates(contextType.getId()); } return null; }
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()); }
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 int compareTo(TemplateContextType templateContextType) { int result = getName().compareTo(templateContextType.getName()); if (result == 0) { return getId().compareTo(templateContextType.getId()); } return result; }
@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; }
/** * Returns the context id for the given item which is either a template or a context type. * * @param item the item * @return the context type id */ private String getContextId(Object item) { String contextId; if (item instanceof TemplatePersistenceData) contextId= ((TemplatePersistenceData) item).getTemplate().getContextTypeId(); else contextId= ((TemplateContextType) item).getId(); return contextId; }
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; }
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; }
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; }
/** * Stores the collapse state of a context node. */ private void storeCollapseState() { TreeItem[] items= fTreeViewer.getTree().getItems(); for (int i= 0; i < items.length; i++) { fPreferenceStore.setValue(CONTEXT_COLLAPSE_PREF_ID + ((TemplateContextType) items[i].getData()).getId(), !items[i].getExpanded()); } }
/** * Stores the collapse state of a context node. */ private void storeCollapseState() { TreeItem[] items= fTreeViewer.getTree().getItems(); for (int i= 0; i < items.length; i++) { fPreferenceStore.setValue(CONTEXT_COLLAPSE_PREF_ID + ((TemplateContextType) items[i].getData()).getId(), !items[i].getExpanded()); } }
private void add() { Iterator it= fContextTypeRegistry.contextTypes(); if (it.hasNext()) { Template template= new Template("", "", ((TemplateContextType) it.next()).getId(), "", true); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ Template newTemplate= editTemplate(template, false, true); if (newTemplate != null) { TemplatePersistenceData data= new TemplatePersistenceData(newTemplate, true); fTemplateStore.add(data); fTableViewer.refresh(); fTableViewer.setChecked(data, true); fTableViewer.setSelection(new StructuredSelection(data)); } } }
@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))); } } }