use of org.eclipse.jface.text.templates.TemplateContextType in project che 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) {
JavaPlugin.log(e);
type = null;
}
return type;
}
use of org.eclipse.jface.text.templates.TemplateContextType in project che by eclipse.
the class TemplateCompletionProposalComputer method createTemplateEngine.
private static TemplateEngine createTemplateEngine(ContextTypeRegistry templateContextRegistry, String contextTypeId) {
TemplateContextType contextType = templateContextRegistry.getContextType(contextTypeId);
Assert.isNotNull(contextType);
return new TemplateEngine(contextType);
}
use of org.eclipse.jface.text.templates.TemplateContextType in project che by eclipse.
the class JavaPlugin method getTemplateContextRegistry.
/**
* Returns the template context type registry for the java plug-in.
*
* @return the template context type registry for the java plug-in
* @since 3.0
*/
public synchronized ContextTypeRegistry getTemplateContextRegistry() {
if (fContextTypeRegistry == null) {
ContributionContextTypeRegistry registry = new ContributionContextTypeRegistry(ID_CU_EDITOR);
TemplateContextType all_contextType = registry.getContextType(JavaContextType.ID_ALL);
((AbstractJavaContextType) all_contextType).initializeContextTypeResolvers();
registerJavaContext(registry, JavaContextType.ID_MEMBERS, all_contextType);
registerJavaContext(registry, JavaContextType.ID_STATEMENTS, all_contextType);
// registerJavaContext(registry, SWTContextType.ID_ALL, all_contextType);
// all_contextType= registry.getContextType(SWTContextType.ID_ALL);
//
// registerJavaContext(registry, SWTContextType.ID_MEMBERS, all_contextType);
// registerJavaContext(registry, SWTContextType.ID_STATEMENTS, all_contextType);
fContextTypeRegistry = registry;
}
return fContextTypeRegistry;
}
use of org.eclipse.jface.text.templates.TemplateContextType in project xtext-eclipse by eclipse.
the class DefaultTemplateProposalProvider method createTemplates.
@Override
protected void createTemplates(TemplateContext templateContext, ContentAssistContext context, ITemplateAcceptor acceptor) {
TemplateContextType contextType = templateContext.getContextType();
Template[] templates = templateStore.getTemplates(contextType.getId());
for (Template template : templates) {
if (!acceptor.canAcceptMoreTemplates())
return;
if (validate(template, templateContext)) {
acceptor.accept(createProposal(template, templateContext, context, getImage(template), getRelevance(template)));
}
}
}
use of org.eclipse.jface.text.templates.TemplateContextType in project xtext-eclipse by eclipse.
the class DefaultTemplateProposalProvider method getContextTypes.
@Override
protected TemplateContextType[] getContextTypes(final ContentAssistContext context) {
final Set<TemplateContextType> result = Sets.newLinkedHashSet();
IFollowElementAcceptor acceptor = createFollowElementAcceptor(result);
List<AbstractElement> grammarElements = context.getFirstSetGrammarElements();
for (AbstractElement element : grammarElements) acceptor.accept(element);
return result.toArray(new TemplateContextType[result.size()]);
}
Aggregations