Search in sources :

Example 1 with TemplateVariableType

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

the class JavaContext method evaluate.

/*
	 * @see TemplateContext#evaluate(Template template)
	 */
@Override
public TemplateBuffer evaluate(Template template) throws BadLocationException, TemplateException {
    clear();
    if (!canEvaluate(template))
        throw new TemplateException(JavaTemplateMessages.Context_error_cannot_evaluate);
    TemplateTranslator translator = new TemplateTranslator() {

        @Override
        protected TemplateVariable createVariable(TemplateVariableType type, String name, int[] offsets) {
            //				TemplateVariableResolver resolver= getContextType().getResolver(type.getName());
            //				return resolver.createVariable();
            MultiVariable variable = new JavaVariable(type, name, offsets);
            fVariables.put(name, variable);
            return variable;
        }
    };
    TemplateBuffer buffer = translator.translate(template);
    getContextType().resolve(buffer, this);
    rewriteImports();
    //		IPreferenceStore prefs = JavaPlugin.getDefault().getPreferenceStore();
    //prefs.getBoolean(PreferenceConstants.TEMPLATES_USE_CODEFORMATTER);
    boolean useCodeFormatter = true;
    IJavaProject project = getJavaProject();
    JavaFormatter formatter = new JavaFormatter(TextUtilities.getDefaultLineDelimiter(getDocument()), getIndentation(), useCodeFormatter, project);
    formatter.format(buffer, this);
    clear();
    return buffer;
}
Also used : TemplateVariableType(org.eclipse.jface.text.templates.TemplateVariableType) IJavaProject(org.eclipse.jdt.core.IJavaProject) TemplateException(org.eclipse.jface.text.templates.TemplateException) MultiVariable(org.eclipse.jdt.internal.ui.text.template.contentassist.MultiVariable) TemplateBuffer(org.eclipse.jface.text.templates.TemplateBuffer) TemplateTranslator(org.eclipse.jface.text.templates.TemplateTranslator)

Aggregations

IJavaProject (org.eclipse.jdt.core.IJavaProject)1 MultiVariable (org.eclipse.jdt.internal.ui.text.template.contentassist.MultiVariable)1 TemplateBuffer (org.eclipse.jface.text.templates.TemplateBuffer)1 TemplateException (org.eclipse.jface.text.templates.TemplateException)1 TemplateTranslator (org.eclipse.jface.text.templates.TemplateTranslator)1 TemplateVariableType (org.eclipse.jface.text.templates.TemplateVariableType)1