use of org.eclipse.jface.text.templates.TemplateContextType in project xtext-eclipse by eclipse.
the class AdvancedTemplatesPreferencePage method updateViewerInput.
@Override
protected void updateViewerInput() {
IStructuredSelection selection = (IStructuredSelection) getTableViewer().getSelection();
if (selection.size() == 1) {
TemplatePersistenceData data = (TemplatePersistenceData) selection.getFirstElement();
Template template = data.getTemplate();
String name = template.getName();
TemplateContextType contextType = getContextTypeRegistry().getContextType(template.getContextTypeId());
if (contextType != null) {
String prefix = "templates for " + grammarAccess.getGrammar().getName() + "'" + name + "'" + " for " + getContextTypeForGrammar(contextType) + ">>";
String editablePart = template.getPattern();
String suffix = "";
partialEditor.updateModel(prefix, editablePart, suffix);
} else {
partialEditor.updateModel("", template.getPattern(), "");
}
} else {
partialEditor.updateModel("", "", "");
}
}
use of org.eclipse.jface.text.templates.TemplateContextType 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);
}
}
}
}
}
}
}
use of org.eclipse.jface.text.templates.TemplateContextType in project eclipse.platform.text by eclipse.
the class ContributionContextTypeRegistry method addContextType.
/**
* Tries to create a context type given an id. If there is already a context
* type registered under the given id, nothing happens. Otherwise,
* 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.
*
* @param id the id for the context type as specified in XML
*/
public void addContextType(String id) {
Assert.isNotNull(id);
if (getContextType(id) != null)
return;
TemplateContextType type = createContextType(id);
if (type != null)
addContextType(type);
}
use of org.eclipse.jface.text.templates.TemplateContextType in project eclipse.platform.text 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;
}
use of org.eclipse.jface.text.templates.TemplateContextType in project eclipse.platform.text by eclipse.
the class TemplateVariablesWordSelectionTest method setUp.
@Before
public void setUp() {
fTranslator = new TemplateTranslator();
fType = new TemplateContextType();
fType.addResolver(new GlobalTemplateVariables.WordSelection());
fContext = new DocumentTemplateContext(fType, new Document(), 0, 0);
}
Aggregations