@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); }
private String getContextId() { if (fContextCombo != null && !fContextCombo.isDisposed()) { String name= fContextCombo.getText(); for (int i= 0; i < fContextTypes.length; i++) { if (name.equals(fContextTypes[i][1])) { return fContextTypes[i][0]; } } } return fOriginalTemplate.getContextTypeId(); }
private String getContextId() { if (fContextCombo != null && !fContextCombo.isDisposed()) { String name= fContextCombo.getText(); for (int i= 0; i < fContextTypes.length; i++) { if (name.equals(fContextTypes[i][1])) { return fContextTypes[i][0]; } } } return fOriginalTemplate.getContextTypeId(); }
protected String getContextId() { if (fContextCombo != null && !fContextCombo.isDisposed()) { String name= fContextCombo.getText(); for (int i= 0; i < fContextTypes.length; i++) { if (name.equals(fContextTypes[i][1])) { return fContextTypes[i][0]; } } } return fTemplate.getContextTypeId(); }
private TemplatePersistenceData[] getTemplates(String contextId) { List<TemplatePersistenceData> templateList= new ArrayList<>(); TemplatePersistenceData[] datas= getTemplateStore().getTemplateData(false); for (int i= 0; i < datas.length; i++) { if (datas[i].isEnabled() && datas[i].getTemplate().getContextTypeId().equals(contextId)) templateList.add(datas[i]); } return templateList .toArray(new TemplatePersistenceData[templateList.size()]); }
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 getContextName() { String result; if (fContextCombo != null && !fContextCombo.isDisposed()) { result = fContextCombo.getText(); } else { String contextId = fTemplate.getContextTypeId(); result = fContextTypeRegistry.getContextType(contextId).getName(); } if (result.startsWith("Keyword ")) result = result.substring("Keyword ".length()); return result; }
@Override public Object getParent(Object element) { if (element instanceof TemplatePersistenceData) { TemplatePersistenceData templateData= (TemplatePersistenceData) element; return getContextTypeRegistry().getContextType( templateData.getTemplate().getContextTypeId()); } return null; }
@Override protected boolean isValidTemplate(IDocument document, Template template, int offset, int length) { String[] contextIds= getContextTypeIds(document, offset); for (int i= 0; i < contextIds.length; i++) { if (contextIds[i].equals(template.getContextTypeId())) { DocumentTemplateContext context= getContext(document, template, offset, length); return context.canEvaluate(template) || isTemplateAllowed(context, template); } } return false; }
@Override public Object getParent(Object element) { if (element instanceof TemplatePersistenceData) { TemplatePersistenceData templateData= (TemplatePersistenceData) element; return getContextTypeRegistry().getContextType( templateData.getTemplate().getContextTypeId()); } return null; }
/** * 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()); }
public static String getGetterMethodBodyContent(IJavaProject project, String destTypeName, String methodName, String fieldName, String lineDelimiter) throws CoreException { String templateName= CodeTemplateContextType.GETTERSTUB_ID; Template template= getCodeTemplate(templateName, project); if (template == null) { return null; } CodeTemplateContext context= new CodeTemplateContext(template.getContextTypeId(), project, lineDelimiter); context.setVariable(CodeTemplateContextType.ENCLOSING_METHOD, methodName); context.setVariable(CodeTemplateContextType.ENCLOSING_TYPE, destTypeName); context.setVariable(CodeTemplateContextType.FIELD, fieldName); return evaluateTemplate(context, template); }
public static String getFieldComment(ICompilationUnit cu, String typeName, String fieldName, String lineDelimiter) throws CoreException { Template template= getCodeTemplate(CodeTemplateContextType.FIELDCOMMENT_ID, cu.getJavaProject()); if (template == null) { return null; } CodeTemplateContext context= new CodeTemplateContext(template.getContextTypeId(), cu.getJavaProject(), lineDelimiter); context.setCompilationUnitVariables(cu); context.setVariable(CodeTemplateContextType.FIELD_TYPE, typeName); context.setVariable(CodeTemplateContextType.FIELD, fieldName); return evaluateTemplate(context, template); }
public static void setCodeTemplate(String templateId, String pattern, IJavaProject project) { TemplateStore codeTemplateStore= JavaPlugin.getDefault().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); }
public static String getFieldComment(ICompilationUnit cu, String typeName, String fieldName, String lineDelimiter) throws CoreException { Template template= getCodeTemplate(CodeTemplateContextType.FIELDCOMMENT_ID, cu.getJavaProject()); if (template == null) { return null; } CodeTemplateContext context= new CodeTemplateContext(template.getContextTypeId(), cu.getJavaProject(), lineDelimiter); context.setCompilationUnitVariables(cu); context.setVariable(CodeTemplateContextType.FIELD_TYPE, typeName); context.setVariable(CodeTemplateContextType.FIELD, fieldName); return evaluateTemplate(context, template); }
public static String getFieldComment(ICompilationUnit cu, String typeName, String fieldName, String lineDelimiter) throws CoreException { Template template= getCodeTemplate(CodeTemplateContextType.FIELDCOMMENT_ID, cu.getJavaProject()); if (template == null) { return null; } CodeTemplateContext context= new CodeTemplateContext(template.getContextTypeId(), cu.getJavaProject(), lineDelimiter); context.setCompilationUnitVariables(cu); context.setVariable(CodeTemplateContextType.FIELD_TYPE, typeName); context.setVariable(CodeTemplateContextType.FIELD, fieldName); return evaluateTemplate(context, template); }
public static String getCatchBodyContent(ICompilationUnit cu, String exceptionType, String variableName, String enclosingType, String enclosingMethod, String lineDelimiter) throws CoreException { Template template= getCodeTemplate(CodeTemplateContextType.CATCHBLOCK_ID, cu.getJavaProject()); if (template == null) { return null; } CodeTemplateContext context= new CodeTemplateContext(template.getContextTypeId(), cu.getJavaProject(), lineDelimiter); context.setVariable(CodeTemplateContextType.ENCLOSING_TYPE, enclosingType); context.setVariable(CodeTemplateContextType.ENCLOSING_METHOD, enclosingMethod); context.setVariable(CodeTemplateContextType.EXCEPTION_TYPE, exceptionType); context.setVariable(CodeTemplateContextType.EXCEPTION_VAR, variableName); return evaluateTemplate(context, template); }
public static String getFileComment(ICompilationUnit cu, String lineDelimiter) throws CoreException { Template template= getCodeTemplate(CodeTemplateContextType.FILECOMMENT_ID, cu.getJavaProject()); if (template == null) { return null; } IJavaProject project= cu.getJavaProject(); CodeTemplateContext context= new CodeTemplateContext(template.getContextTypeId(), project, lineDelimiter); context.setCompilationUnitVariables(cu); context.setVariable(CodeTemplateContextType.TYPENAME, JavaCore.removeJavaLikeExtension(cu.getElementName())); return evaluateTemplate(context, template); }
public static String getFileComment(ICompilationUnit cu, String lineDelimiter) throws CoreException { Template template= getCodeTemplate(CodeTemplateContextType.FILECOMMENT_ID, cu.getJavaProject()); if (template == null) { return null; } IJavaProject project= cu.getJavaProject(); CodeTemplateContext context= new CodeTemplateContext(template.getContextTypeId(), project, lineDelimiter); context.setCompilationUnitVariables(cu); context.setVariable(CodeTemplateContextType.TYPENAME, JavaCore.removeJavaLikeExtension(cu.getElementName())); return evaluateTemplate(context, template); }
public static String getFileComment(ICompilationUnit cu, String lineDelimiter) throws CoreException { Template template= getCodeTemplate(CodeTemplateContextType.FILECOMMENT_ID, cu.getJavaProject()); if (template == null) { return null; } IJavaProject project= cu.getJavaProject(); CodeTemplateContext context= new CodeTemplateContext(template.getContextTypeId(), project, lineDelimiter); context.setCompilationUnitVariables(cu); context.setVariable(CodeTemplateContextType.TYPENAME, JavaCore.removeJavaLikeExtension(cu.getElementName())); return evaluateTemplate(context, template); }