Search in sources :

Example 6 with TemplateTranslator

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

the class CodeTemplateContext method evaluate.

/*
	 * @see org.eclipse.jdt.internal.corext.template.TemplateContext#evaluate(org.eclipse.jdt.internal.corext.template.Template)
	 */
@Override
public TemplateBuffer evaluate(Template template) throws BadLocationException, TemplateException {
    // test that all variables are defined
    Iterator<TemplateVariableResolver> iterator = getContextType().resolvers();
    while (iterator.hasNext()) {
        TemplateVariableResolver var = iterator.next();
        if (var instanceof CodeTemplateContextType.CodeTemplateVariableResolver) {
            //$NON-NLS-1$ //$NON-NLS-2$
            Assert.isNotNull(getVariable(var.getType()), "Variable " + var.getType() + "not defined");
        }
    }
    if (!canEvaluate(template))
        return null;
    String pattern = changeLineDelimiter(template.getPattern(), fLineDelimiter);
    TemplateTranslator translator = new TemplateTranslator();
    TemplateBuffer buffer = translator.translate(pattern);
    getContextType().resolve(buffer, this);
    return buffer;
}
Also used : TemplateBuffer(org.eclipse.jface.text.templates.TemplateBuffer) TemplateVariableResolver(org.eclipse.jface.text.templates.TemplateVariableResolver) TemplateTranslator(org.eclipse.jface.text.templates.TemplateTranslator)

Example 7 with TemplateTranslator

use of org.eclipse.jface.text.templates.TemplateTranslator in project KaiZen-OpenAPI-Editor by RepreZen.

the class SwaggerTemplateContext method evaluateForDisplay.

/**
     * @since 2.3
     */
public TemplateBuffer evaluateForDisplay(Template template) throws BadLocationException, TemplateException {
    if (!canEvaluate(template))
        return null;
    TemplateTranslator translator = new TemplateTranslator();
    TemplateBuffer buffer = translator.translate(template);
    getContextType().resolve(buffer, this);
    return buffer;
}
Also used : TemplateBuffer(org.eclipse.jface.text.templates.TemplateBuffer) TemplateTranslator(org.eclipse.jface.text.templates.TemplateTranslator)

Aggregations

TemplateTranslator (org.eclipse.jface.text.templates.TemplateTranslator)7 TemplateBuffer (org.eclipse.jface.text.templates.TemplateBuffer)6 IJavaProject (org.eclipse.jdt.core.IJavaProject)2 TemplateVariableResolver (org.eclipse.jface.text.templates.TemplateVariableResolver)2 MultiVariable (org.eclipse.jdt.internal.ui.text.template.contentassist.MultiVariable)1 BadLocationException (org.eclipse.jface.text.BadLocationException)1 IRegion (org.eclipse.jface.text.IRegion)1 TemplateException (org.eclipse.jface.text.templates.TemplateException)1 TemplateVariableType (org.eclipse.jface.text.templates.TemplateVariableType)1