Search in sources :

Example 21 with TemplateVariableResolver

use of org.eclipse.jface.text.templates.TemplateVariableResolver in project webtools.sourceediting by eclipse.

the class TestTemplateContextTypeXSL method testXMLEncodingVariableAvailable.

@Test
public void testXMLEncodingVariableAvailable() throws Exception {
    TemplateContextTypeXSL contextType = new TemplateContextTypeXSL();
    Iterator<TemplateVariableResolver> variables = contextType.resolvers();
    while (variables.hasNext()) {
        TemplateVariableResolver resolver = variables.next();
        if (resolver.getType().equals("encoding")) {
            return;
        }
    }
    fail("Encoding Selection variable resolver was not found.");
}
Also used : TemplateContextTypeXSL(org.eclipse.wst.xsl.ui.internal.templates.TemplateContextTypeXSL) TemplateVariableResolver(org.eclipse.jface.text.templates.TemplateVariableResolver)

Example 22 with TemplateVariableResolver

use of org.eclipse.jface.text.templates.TemplateVariableResolver in project eclipse.jdt.ls 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 23 with TemplateVariableResolver

use of org.eclipse.jface.text.templates.TemplateVariableResolver 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 24 with TemplateVariableResolver

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

the class ContributionContextTypeRegistry method createContextType.

/**
 * Tries to create a context type given an id. Contributions to the
 * <code>org.eclipse.ui.editors.templates</code> extension point are
 * searched for the given identifier and the specified context type
 * instantiated if it is found. Any contributed
 * {@link org.eclipse.jface.text.templates.TemplateVariableResolver}s
 * are also instantiated and added to the context type.
 *
 * @param id the id for the context type as specified in XML
 * @return the instantiated and configured context type, or
 *         <code>null</code> if it is not found or cannot be instantiated
 */
public static TemplateContextType createContextType(String id) {
    Assert.isNotNull(id);
    IConfigurationElement[] extensions = getTemplateExtensions();
    TemplateContextType type;
    try {
        type = createContextType(extensions, id);
        if (type != null) {
            TemplateVariableResolver[] resolvers = createResolvers(extensions, id);
            for (int i = 0; i < resolvers.length; i++) type.addResolver(resolvers[i]);
        }
    } catch (CoreException e) {
        // EditorsPlugin.log(e);
        type = null;
    }
    return type;
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) TemplateContextType(org.eclipse.jface.text.templates.TemplateContextType) TemplateVariableResolver(org.eclipse.jface.text.templates.TemplateVariableResolver)

Example 25 with TemplateVariableResolver

use of org.eclipse.jface.text.templates.TemplateVariableResolver in project xtext-eclipse by eclipse.

the class CodetemplatesProposalProvider method completeVariable_Type.

@Override
public void completeVariable_Type(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
    if ((mode & NORMAL) != 0) {
        super.completeVariable_Name(model, assignment, context, acceptor);
        TemplateData data = new TemplateData(model);
        if (data.doCreateProposals()) {
            ContextTypeIdHelper helper = languageRegistry.getContextTypeIdHelper(data.language);
            if (helper != null) {
                String contextTypeId = helper.getId(data.rule);
                ContextTypeRegistry contextTypeRegistry = languageRegistry.getContextTypeRegistry(data.language);
                TemplateContextType contextType = contextTypeRegistry.getContextType(contextTypeId);
                if (contextType != null) {
                    Iterator<TemplateVariableResolver> resolvers = Iterators.filter(contextType.resolvers(), TemplateVariableResolver.class);
                    while (resolvers.hasNext()) {
                        TemplateVariableResolver resolver = resolvers.next();
                        String type = resolver.getType();
                        StyledString displayString = new StyledString(type).append(" - " + resolver.getDescription(), StyledString.QUALIFIER_STYLER);
                        acceptor.accept(createCompletionProposal(type, displayString, null, context));
                    }
                }
            }
        }
    }
}
Also used : ContextTypeRegistry(org.eclipse.jface.text.templates.ContextTypeRegistry) StyledString(org.eclipse.jface.viewers.StyledString) StyledString(org.eclipse.jface.viewers.StyledString) TemplateContextType(org.eclipse.jface.text.templates.TemplateContextType) ContextTypeIdHelper(org.eclipse.xtext.ui.editor.templates.ContextTypeIdHelper) IInspectableTemplateVariableResolver(org.eclipse.xtext.ui.codetemplates.ui.resolvers.IInspectableTemplateVariableResolver) TemplateVariableResolver(org.eclipse.jface.text.templates.TemplateVariableResolver)

Aggregations

TemplateVariableResolver (org.eclipse.jface.text.templates.TemplateVariableResolver)28 TemplateContextTypeXSL (org.eclipse.wst.xsl.ui.internal.templates.TemplateContextTypeXSL)10 TemplateContextType (org.eclipse.jface.text.templates.TemplateContextType)9 CoreException (org.eclipse.core.runtime.CoreException)5 ContextTypeRegistry (org.eclipse.jface.text.templates.ContextTypeRegistry)5 ContextTypeIdHelper (org.eclipse.xtext.ui.editor.templates.ContextTypeIdHelper)5 TemplateBuffer (org.eclipse.jface.text.templates.TemplateBuffer)4 IInspectableTemplateVariableResolver (org.eclipse.xtext.ui.codetemplates.ui.resolvers.IInspectableTemplateVariableResolver)4 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)3 TemplateTranslator (org.eclipse.jface.text.templates.TemplateTranslator)3 StyledString (org.eclipse.jface.viewers.StyledString)3 IStatus (org.eclipse.core.runtime.IStatus)2 Status (org.eclipse.core.runtime.Status)2 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)2 Grammar (org.eclipse.xtext.Grammar)2 Codetemplate (org.eclipse.xtext.ui.codetemplates.templates.Codetemplate)2 Codetemplates (org.eclipse.xtext.ui.codetemplates.templates.Codetemplates)2 Variable (org.eclipse.xtext.ui.codetemplates.templates.Variable)2 ConfigurableCompletionProposal (org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal)2 ArrayList (java.util.ArrayList)1