Search in sources :

Example 36 with Template

use of org.eclipse.jface.text.templates.Template in project che by eclipse.

the class StubUtility method getCompilationUnitContent.

public static String getCompilationUnitContent(ICompilationUnit cu, String packDecl, String fileComment, String typeComment, String typeContent, String lineDelimiter) throws CoreException {
    Template template = getCodeTemplate(CodeTemplateContextType.NEWTYPE_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.PACKAGE_DECLARATION, packDecl);
    //$NON-NLS-1$
    context.setVariable(CodeTemplateContextType.TYPE_COMMENT, typeComment != null ? typeComment : "");
    //$NON-NLS-1$
    context.setVariable(CodeTemplateContextType.FILE_COMMENT, fileComment != null ? fileComment : "");
    context.setVariable(CodeTemplateContextType.TYPE_DECLARATION, typeContent);
    context.setVariable(CodeTemplateContextType.TYPENAME, JavaCore.removeJavaLikeExtension(cu.getElementName()));
    String[] fullLine = { CodeTemplateContextType.PACKAGE_DECLARATION, CodeTemplateContextType.FILE_COMMENT, CodeTemplateContextType.TYPE_COMMENT };
    return evaluateTemplate(context, template, fullLine);
}
Also used : CodeTemplateContext(org.eclipse.jdt.internal.corext.template.java.CodeTemplateContext) IJavaProject(org.eclipse.jdt.core.IJavaProject) Template(org.eclipse.jface.text.templates.Template)

Example 37 with Template

use of org.eclipse.jface.text.templates.Template in project flux by eclipse.

the class StubUtility method getCompilationUnitContent.

public static String getCompilationUnitContent(ICompilationUnit cu, String packDecl, String fileComment, String typeComment, String typeContent, String lineDelimiter) throws CoreException {
    Template template = getCodeTemplate(CodeTemplateContextType.NEWTYPE_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.PACKAGE_DECLARATION, packDecl);
    //$NON-NLS-1$
    context.setVariable(CodeTemplateContextType.TYPE_COMMENT, typeComment != null ? typeComment : "");
    //$NON-NLS-1$
    context.setVariable(CodeTemplateContextType.FILE_COMMENT, fileComment != null ? fileComment : "");
    context.setVariable(CodeTemplateContextType.TYPE_DECLARATION, typeContent);
    context.setVariable(CodeTemplateContextType.TYPENAME, JavaCore.removeJavaLikeExtension(cu.getElementName()));
    String[] fullLine = { CodeTemplateContextType.PACKAGE_DECLARATION, CodeTemplateContextType.FILE_COMMENT, CodeTemplateContextType.TYPE_COMMENT };
    return evaluateTemplate(context, template, fullLine);
}
Also used : CodeTemplateContext(org.eclipse.jdt.internal.corext.template.java.CodeTemplateContext) IJavaProject(org.eclipse.jdt.core.IJavaProject) Template(org.eclipse.jface.text.templates.Template)

Aggregations

Template (org.eclipse.jface.text.templates.Template)37 CodeTemplateContext (org.eclipse.jdt.internal.corext.template.java.CodeTemplateContext)28 BadLocationException (org.eclipse.jface.text.BadLocationException)7 IDocument (org.eclipse.jface.text.IDocument)7 CoreException (org.eclipse.core.runtime.CoreException)6 Document (org.eclipse.jface.text.Document)6 TemplateBuffer (org.eclipse.jface.text.templates.TemplateBuffer)6 TemplateException (org.eclipse.jface.text.templates.TemplateException)6 TemplateVariable (org.eclipse.jface.text.templates.TemplateVariable)6 IJavaProject (org.eclipse.jdt.core.IJavaProject)4 IOException (java.io.IOException)2 DocumentBuilder (javax.xml.parsers.DocumentBuilder)2 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 TemplatePersistenceData (org.eclipse.che.jface.text.templates.persistence.TemplatePersistenceData)2 ITypeParameter (org.eclipse.jdt.core.ITypeParameter)2 SingleVariableDeclaration (org.eclipse.jdt.core.dom.SingleVariableDeclaration)2 TypeParameter (org.eclipse.jdt.core.dom.TypeParameter)2 Position (org.eclipse.jface.text.Position)2 Region (org.eclipse.jface.text.Region)2