/** * 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()); }
/** * 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 TemplateBuffer translate(Template template) throws TemplateException { return translate(template.getPattern()); }
@Override public TemplateBuffer translate(Template template) throws TemplateException { return translate(template.getPattern()); }
/** * Update the pattern viewer to show the current template. * <p> * Subclasses can extend this method to update their own pattern viewer. * </p> * * @param template the template */ protected void updatePatternViewer(Template template) { String pattern= template != null ? template.getPattern() : ""; //$NON-NLS-1$ fPatternViewer.getDocument().set(pattern); }
protected boolean validate(Template template, TemplateContext context) { try { context.getContextType().validate(template.getPattern()); } catch(TemplateException e) { return false; } return true; }
/** * Update the pattern viewer to show the current template. * <p> * Subclasses can extend this method to update their own pattern viewer. * </p> * * @param template the template */ protected void updatePatternViewer(Template template) { String pattern= template != null ? template.getPattern() : ""; //$NON-NLS-1$ fPatternViewer.getDocument().set(pattern); }
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; }
/** * 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()); }
/** * 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()); }
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(); } }
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(); } }
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(); } }
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; }
/** * Updates the pattern viewer. */ void updateViewerInput() { Template template = getSelectedTemplate(); if (template != null) { fPatternViewer.getDocument().set(template.getPattern()); } else { fPatternViewer.getDocument().set(""); //$NON-NLS-1$ } } }
protected void updateSourceViewerInput(List<Object> selection) { if (fPatternViewer == null || fPatternViewer.getTextWidget().isDisposed()) { return; } if (selection.size() == 1 && selection.get(0) instanceof TemplatePersistenceData) { TemplatePersistenceData data= (TemplatePersistenceData) selection.get(0); Template template= data.getTemplate(); TemplateContextType type= JavaPlugin.getDefault().getCodeTemplateContextRegistry().getContextType(template.getContextTypeId()); fTemplateProcessor.setContextType(type); fPatternViewer.getDocument().set(template.getPattern()); } else { fPatternViewer.getDocument().set(""); //$NON-NLS-1$ } }
/** * Updates the pattern viewer. */ protected void updateViewerInput() { IStructuredSelection selection= (IStructuredSelection) fTableViewer.getSelection(); if (selection.size() == 1) { TemplatePersistenceData data= (TemplatePersistenceData) selection.getFirstElement(); Template template= data.getTemplate(); fPatternViewer.getDocument().set(template.getPattern()); } else { fPatternViewer.getDocument().set(""); //$NON-NLS-1$ } }
/** * Updates the pattern viewer. */ protected void updateViewerInput() { IStructuredSelection selection = fTableViewer.getStructuredSelection(); if (selection.size() == 1) { TemplatePersistenceData data= (TemplatePersistenceData) selection.getFirstElement(); Template template= data.getTemplate(); fPatternViewer.getDocument().set(template.getPattern()); } else { fPatternViewer.getDocument().set(""); //$NON-NLS-1$ } }
/** * Updates the pattern viewer. */ protected void updateViewerInput() { IStructuredSelection selection= (IStructuredSelection) fTableViewer.getSelection(); if (selection.size() == 1) { TemplatePersistenceData data= (TemplatePersistenceData) selection.getFirstElement(); Template template= data.getTemplate(); fPatternViewer.getDocument().set(template.getPattern()); } else { fPatternViewer.getDocument().set(""); //$NON-NLS-1$ } }
private TemplateBuffer createTemplateBuffer(Template template) throws BadLocationException, TemplateException { String lineDelimiter = TextUtilities.getDefaultLineDelimiter(getDocument()); IDocument document = new Document(template.getPattern()); convertLineDelimiters(document, lineDelimiter); TemplateTranslator translator = new TemplateTranslator(); TemplateBuffer buffer = translator.translate(document.get()); getContextType().resolve(buffer, this); return buffer; }