use of org.eclipse.jface.text.templates.Template in project flux by eclipse.
the class StubUtility method getTypeBody.
/**
* Don't use this method directly, use CodeGeneration.
*
* @param templateID the template id of the type body to get. Valid id's are
* {@link CodeTemplateContextType#CLASSBODY_ID},
* {@link CodeTemplateContextType#INTERFACEBODY_ID},
* {@link CodeTemplateContextType#ENUMBODY_ID},
* {@link CodeTemplateContextType#ANNOTATIONBODY_ID},
* @param cu the compilation unit to which the template is added
* @param typeName the type name
* @param lineDelim the line delimiter to use
* @return return the type body template or <code>null</code>
* @throws CoreException thrown if the template could not be evaluated
*/
public static String getTypeBody(String templateID, ICompilationUnit cu, String typeName, String lineDelim) throws CoreException {
if (!VALID_TYPE_BODY_TEMPLATES.contains(templateID)) {
// $NON-NLS-1$
throw new IllegalArgumentException("Invalid code template ID: " + templateID);
}
Template template = getCodeTemplate(templateID, cu.getJavaProject());
if (template == null) {
return null;
}
CodeTemplateContext context = new CodeTemplateContext(template.getContextTypeId(), cu.getJavaProject(), lineDelim);
context.setCompilationUnitVariables(cu);
context.setVariable(CodeTemplateContextType.TYPENAME, typeName);
return evaluateTemplate(context, template);
}
use of org.eclipse.jface.text.templates.Template in project flux by eclipse.
the class StubUtility method getFileComment.
/*
* Don't use this method directly, use CodeGeneration.
* @see org.eclipse.jdt.ui.CodeGeneration#getFileComment(ICompilationUnit, String)
*/
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);
}
use of org.eclipse.jface.text.templates.Template in project flux by eclipse.
the class StubUtility method getCatchBodyContent.
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);
}
use of org.eclipse.jface.text.templates.Template in project flux by eclipse.
the class StubUtility method getGetterMethodBodyContent.
/*
* Don't use this method directly, use CodeGeneration.
*/
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);
}
use of org.eclipse.jface.text.templates.Template in project flux by eclipse.
the class StubUtility method getFieldComment.
/*
* Don't use this method directly, use CodeGeneration.
*/
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);
}
Aggregations