Search in sources :

Example 1 with ContextTypeRegistry

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

the class TemplateValidator method checkParameters.

@Check
public void checkParameters(Variable variable) {
    Codetemplate template = EcoreUtil2.getContainerOfType(variable, Codetemplate.class);
    Codetemplates templates = EcoreUtil2.getContainerOfType(template, Codetemplates.class);
    if (templates != null && template != null) {
        Grammar language = templates.getLanguage();
        AbstractRule rule = template.getContext();
        ContextTypeIdHelper helper = languageRegistry.getContextTypeIdHelper(language);
        if (helper != null && rule != null && !rule.eIsProxy() && rule instanceof ParserRule) {
            String contextTypeId = helper.getId(rule);
            ContextTypeRegistry contextTypeRegistry = languageRegistry.getContextTypeRegistry(language);
            TemplateContextType contextType = contextTypeRegistry.getContextType(contextTypeId);
            if (contextType != null) {
                Iterator<TemplateVariableResolver> resolvers = Iterators.filter(contextType.resolvers(), TemplateVariableResolver.class);
                String type = variable.getType();
                if (type == null)
                    type = variable.getName();
                while (resolvers.hasNext()) {
                    final TemplateVariableResolver resolver = resolvers.next();
                    if (resolver.getType().equals(type)) {
                        IInspectableTemplateVariableResolver inspectableResolver = registry.toInspectableResolver(resolver);
                        if (inspectableResolver != null) {
                            inspectableResolver.validateParameters(variable, this);
                        }
                    }
                }
            }
        }
    }
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) Codetemplates(org.eclipse.xtext.ui.codetemplates.templates.Codetemplates) Codetemplate(org.eclipse.xtext.ui.codetemplates.templates.Codetemplate) ContextTypeRegistry(org.eclipse.jface.text.templates.ContextTypeRegistry) Grammar(org.eclipse.xtext.Grammar) AbstractRule(org.eclipse.xtext.AbstractRule) TemplateContextType(org.eclipse.jface.text.templates.TemplateContextType) ContextTypeIdHelper(org.eclipse.xtext.ui.editor.templates.ContextTypeIdHelper) IInspectableTemplateVariableResolver(org.eclipse.xtext.ui.codetemplates.ui.resolvers.IInspectableTemplateVariableResolver) IInspectableTemplateVariableResolver(org.eclipse.xtext.ui.codetemplates.ui.resolvers.IInspectableTemplateVariableResolver) TemplateVariableResolver(org.eclipse.jface.text.templates.TemplateVariableResolver) Check(org.eclipse.xtext.validation.Check)

Example 2 with ContextTypeRegistry

use of org.eclipse.jface.text.templates.ContextTypeRegistry in project liferay-ide by liferay.

the class NewLayoutTplWizard method getDefaultProvider.

@Override
protected IDataModelProvider getDefaultProvider() {
    LayoutTplUI defaultUI = LayoutTplUI.getDefault();
    TemplateStore templateStore = defaultUI.getTemplateStore();
    ContextTypeRegistry contextTypeRegistry = defaultUI.getTemplateContextRegistry();
    TemplateContextType contextType = contextTypeRegistry.getContextType(LayoutTplTemplateContextTypeIds.NEW);
    return new NewLayoutTplDataModelProvider() {

        @Override
        public IDataModelOperation getDefaultOperation() {
            return new AddLayoutTplOperation(getDataModel(), templateStore, contextType);
        }
    };
}
Also used : NewLayoutTplDataModelProvider(com.liferay.ide.layouttpl.core.operation.NewLayoutTplDataModelProvider) LayoutTplUI(com.liferay.ide.layouttpl.ui.LayoutTplUI) ContextTypeRegistry(org.eclipse.jface.text.templates.ContextTypeRegistry) TemplateStore(org.eclipse.jface.text.templates.persistence.TemplateStore) TemplateContextType(org.eclipse.jface.text.templates.TemplateContextType)

Example 3 with ContextTypeRegistry

use of org.eclipse.jface.text.templates.ContextTypeRegistry in project liferay-ide by liferay.

the class LiferayUIPlugin method _registerResolvers.

private void _registerResolvers() {
    ContextTypeRegistry templateContextRegistry = JavaPlugin.getDefault().getTemplateContextRegistry();
    Iterator<?> ctIter = templateContextRegistry.contextTypes();
    while (ctIter.hasNext()) {
        Object next = ctIter.next();
        if (next instanceof TemplateContextType) {
            TemplateContextType contextType = (TemplateContextType) next;
            if (contextType.getId().equals("java")) {
                contextType.addResolver(new ServiceClassNameResolver());
            }
        }
    }
}
Also used : ServiceClassNameResolver(com.liferay.ide.ui.templates.ServiceClassNameResolver) ContextTypeRegistry(org.eclipse.jface.text.templates.ContextTypeRegistry) TemplateContextType(org.eclipse.jface.text.templates.TemplateContextType)

Example 4 with ContextTypeRegistry

use of org.eclipse.jface.text.templates.ContextTypeRegistry in project liferay-ide by liferay.

the class ServiceXmlTemplateCompletinoProcessor method getContextType.

@Override
protected TemplateContextType getContextType(ITextViewer viewer, IRegion region) {
    TemplateContextType type = null;
    ContextTypeRegistry registry = getTemplateContextRegistry();
    if (registry != null) {
        type = registry.getContextType(ServiceXmlContextType.ID_SERVICE_XML_TAG);
    }
    return type;
}
Also used : ContextTypeRegistry(org.eclipse.jface.text.templates.ContextTypeRegistry) TemplateContextType(org.eclipse.jface.text.templates.TemplateContextType)

Example 5 with ContextTypeRegistry

use of org.eclipse.jface.text.templates.ContextTypeRegistry in project mylyn.docs by eclipse.

the class WikiTextTemplateAccess method getContextTypeRegistry.

public ContextTypeRegistry getContextTypeRegistry() {
    if (registry == null) {
        if (WikiTextUiPlugin.getDefault() != null) {
            ContributionContextTypeRegistry contributionRegistry = new ContributionContextTypeRegistry();
            contributionRegistry.addContextType(SourceTemplateContextType.ID);
            registry = contributionRegistry;
        } else {
            ContextTypeRegistry contextTypeRegistry = new ContextTypeRegistry();
            contextTypeRegistry.addContextType(new SourceTemplateContextType());
            registry = contextTypeRegistry;
        }
    }
    return registry;
}
Also used : ContributionContextTypeRegistry(org.eclipse.ui.editors.text.templates.ContributionContextTypeRegistry) ContributionContextTypeRegistry(org.eclipse.ui.editors.text.templates.ContributionContextTypeRegistry) ContextTypeRegistry(org.eclipse.jface.text.templates.ContextTypeRegistry)

Aggregations

ContextTypeRegistry (org.eclipse.jface.text.templates.ContextTypeRegistry)19 TemplateContextType (org.eclipse.jface.text.templates.TemplateContextType)17 TemplateVariableResolver (org.eclipse.jface.text.templates.TemplateVariableResolver)5 ContextTypeIdHelper (org.eclipse.xtext.ui.editor.templates.ContextTypeIdHelper)5 StyledString (org.eclipse.jface.viewers.StyledString)4 IInspectableTemplateVariableResolver (org.eclipse.xtext.ui.codetemplates.ui.resolvers.IInspectableTemplateVariableResolver)4 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)2 TemplateStore (org.eclipse.jface.text.templates.persistence.TemplateStore)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 NewLayoutTplDataModelProvider (com.liferay.ide.layouttpl.core.operation.NewLayoutTplDataModelProvider)1 LayoutTplUI (com.liferay.ide.layouttpl.ui.LayoutTplUI)1 NewVaadinPortletClassDataModelProvider (com.liferay.ide.portlet.vaadin.core.operation.NewVaadinPortletClassDataModelProvider)1 ServiceClassNameResolver (com.liferay.ide.ui.templates.ServiceClassNameResolver)1 JsonDocument (com.reprezen.swagedit.core.editor.JsonDocument)1 Model (com.reprezen.swagedit.core.model.Model)1 GitTemplateVariableResolver (org.eclipse.egit.ui.internal.variables.GitTemplateVariableResolver)1