/** * Creates a copy of a template. * * @param template the template to copy */ public Template(Template template) { this(template.getName(), template.getDescription(), template.getContextTypeId(), template.getPattern(), template.isAutoInsertable()); }
/** * Moves the selected template from one context to another. * * @param templates an array of template data * @param contextId the contextId * */ private void moveTemplates(TemplatePersistenceData[] templates, String contextId) { for (int i= 0; i < templates.length; i++) { Template t= templates[i].getTemplate(); templates[i].setTemplate(new Template(t.getName(), t.getDescription(), contextId, t .getPattern(), t.isAutoInsertable())); } saveTemplateStore(); fTreeViewer.setSelection(new StructuredSelection(templates), 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; }
public String getColumnText(Object element, int columnIndex) { Template template = (Template) element; switch (columnIndex) { case 0 : return template.getName(); case 1 : return template.getDescription(); default : return ""; //$NON-NLS-1$ } } }
private static boolean isSimilar(Template t, Template orig, boolean isCodeTemplates) { return orig.getName().equals(t.getName()) && orig.getContextTypeId().equals(t.getContextTypeId()) && (isCodeTemplates || orig.getDescription().equals(t.getDescription())); // only use description for templates (for, while...) }
/** * Only to be used by tests * * @param templateId the template id * @param pattern the new pattern * @param project not used */ public static void setCodeTemplate(String templateId, String pattern, IJavaProject project) { TemplateStoreCore codeTemplateStore= JavaManipulation.getCodeTemplateStore(); TemplatePersistenceData data= codeTemplateStore.getTemplateData(templateId); Template orig= data.getTemplate(); Template copy= new Template(orig.getName(), orig.getDescription(), orig.getContextTypeId(), pattern, true); data.setTemplate(copy); }
@Override protected void okPressed() { String name= fNameText == null ? fTemplate.getName() : fNameText.getText(); boolean isAutoInsertable= fAutoInsertCheckbox != null && fAutoInsertCheckbox.getSelection(); fTemplate= new Template(name, fDescriptionText.getText(), getContextId(), getPattern(), isAutoInsertable); super.okPressed(); }
/** * Translates a template to a <code>TemplateBuffer</code>. <code>null</code> is returned if * there was an error. <code>getErrorMessage()</code> retrieves the associated error message. * * @param template the template to translate. * @return returns the template buffer corresponding to the string * @see #getErrorMessage() * @throws TemplateException if translation failed */ public TemplateBuffer translate(Template template) throws TemplateException { return parse(template.getPattern()); }
@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; }
protected String validateTemplate(Template template) { TemplateContextType type= fRegistry.getContextType(template.getContextTypeId()); if (type == null) { return "Unknown context type: " + template.getContextTypeId(); //$NON-NLS-1$ } try { type.validate(template.getPattern()); return null; } catch (TemplateException e) { return e.getMessage(); } }
Template template = templates[i]; try { context.getContextType().validate(template.getPattern()); if (template.matches(prefix, contextTypeId) || (isTargetContextType && template.matches(prefix, TaskContextType.TASK_CONTEXT_TYPE))) { matches.add(createProposal(template, context, (IRegion) region, getRelevance(template, prefix)));
for (Template template : templates) { try { context.getContextType().validate(template.getPattern()); } catch (TemplateException e) { continue; if (!template.matches(prefix, context.getContextType().getId())) { continue; if (template.getName().startsWith(prefix) || selectionBasedMatch) {
protected boolean validate(Template template, ContentAssistContext context) { boolean result = context.getMatcher().isCandidateMatchingPrefix(template.getName(), context.getPrefix()); if (result) { try { String pattern = template.getPattern(); if (proposalConflictHelper.existsConflict(pattern, context)) { result = false; } } catch(Exception e) { result = false; } } return result; }
@Override protected Image getImage(Template template) { String contextId= template.getContextTypeId(); if (SWTContextType.ID_ALL.equals(contextId) || SWTContextType.ID_STATEMENTS.equals(contextId) || SWTContextType.ID_MEMBERS.equals(contextId)) return JavaPluginImages.get(JavaPluginImages.IMG_OBJS_SWT_TEMPLATE); return JavaPluginImages.get(JavaPluginImages.IMG_OBJS_TEMPLATE); }
@Override public Object getParent(TreeListDialogField<String> field, Object element) { if (element instanceof TemplatePersistenceData) { TemplatePersistenceData data= (TemplatePersistenceData) element; if (data.getTemplate().getName().endsWith(CodeTemplateContextType.COMMENT_SUFFIX)) { return COMMENT_NODE; } return CODE_NODE; } return null; }
public Template createTemplate(IJavaProject project) { return new Template(this.name(), this.preferenceId, this.contextType, this.defaultContent, false); } }
public boolean isAutoInsertable() { if (isSelectionTemplate()) return false; return fTemplate.isAutoInsertable(); }
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; }
/** * Returns whether the receiver represents a custom template, i.e. is either * a user-added template or a contributed template that has been modified. * * @return <code>true</code> if the contained template is a custom * template and cannot be reconstructed from the contributed * templates */ public boolean isCustom() { return fId == null || fIsDeleted || fOriginalIsEnabled != fCustomIsEnabled || !fOriginalTemplate.equals(fCustomTemplate); }