Search in sources :

Example 81 with Template

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);
}
Also used : CodeTemplateContext(org.eclipse.jdt.internal.corext.template.java.CodeTemplateContext) Template(org.eclipse.jface.text.templates.Template)

Example 82 with 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);
}
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 83 with 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);
}
Also used : CodeTemplateContext(org.eclipse.jdt.internal.corext.template.java.CodeTemplateContext) Template(org.eclipse.jface.text.templates.Template)

Example 84 with 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);
}
Also used : CodeTemplateContext(org.eclipse.jdt.internal.corext.template.java.CodeTemplateContext) Template(org.eclipse.jface.text.templates.Template)

Example 85 with 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);
}
Also used : CodeTemplateContext(org.eclipse.jdt.internal.corext.template.java.CodeTemplateContext) Template(org.eclipse.jface.text.templates.Template)

Aggregations

Template (org.eclipse.jface.text.templates.Template)158 CodeTemplateContext (org.eclipse.jdt.internal.corext.template.java.CodeTemplateContext)27 TemplateBuffer (org.eclipse.jface.text.templates.TemplateBuffer)22 TemplateException (org.eclipse.jface.text.templates.TemplateException)21 TemplateContext (org.eclipse.jface.text.templates.TemplateContext)19 IDocument (org.eclipse.jface.text.IDocument)18 Document (org.eclipse.jface.text.Document)17 ArrayList (java.util.ArrayList)15 BadLocationException (org.eclipse.jface.text.BadLocationException)15 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)15 TemplateContextType (org.eclipse.jface.text.templates.TemplateContextType)14 TemplatePersistenceData (org.eclipse.jface.text.templates.persistence.TemplatePersistenceData)13 TemplateStore (org.eclipse.jface.text.templates.persistence.TemplateStore)12 CoreException (org.eclipse.core.runtime.CoreException)11 Region (org.eclipse.jface.text.Region)11 DocumentTemplateContext (org.eclipse.jface.text.templates.DocumentTemplateContext)11 ISubReference (org.eclipse.titan.designer.AST.ISubReference)11 IRegion (org.eclipse.jface.text.IRegion)10 ITextSelection (org.eclipse.jface.text.ITextSelection)10 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)10