use of org.eclipse.jface.text.templates.TemplateVariableResolver in project che by eclipse.
the class ContributionContextTypeRegistry method createResolver.
private static TemplateVariableResolver createResolver(IConfigurationElement element) throws CoreException {
try {
String type = element.getAttribute(TYPE);
if (type != null) {
TemplateVariableResolver resolver = (TemplateVariableResolver) element.createExecutableExtension(CLASS);
resolver.setType(type);
String desc = element.getAttribute(DESCRIPTION);
//$NON-NLS-1$
resolver.setDescription(desc == null ? "" : desc);
return resolver;
}
} catch (ClassCastException e) {
//$NON-NLS-1$
throw new CoreException(new Status(IStatus.ERROR, "org.eclipse.ui.editors", IStatus.OK, "extension does not implement " + TemplateVariableResolver.class.getName(), e));
}
return null;
}
use of org.eclipse.jface.text.templates.TemplateVariableResolver 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.TemplateVariableResolver 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.TemplateVariableResolver in project eclipse.platform.text by eclipse.
the class ContributionContextTypeRegistry method createResolver.
private static TemplateVariableResolver createResolver(IConfigurationElement element) throws CoreException {
try {
String type = element.getAttribute(TYPE);
if (type != null) {
TemplateVariableResolver resolver = (TemplateVariableResolver) element.createExecutableExtension(CLASS);
if (resolver.getType() != null) {
// $NON-NLS-1$
throw new CoreException(new Status(IStatus.ERROR, EditorsUI.PLUGIN_ID, IStatus.OK, resolver.getClass() + "() must call super() and not set the variable's type", null));
}
resolver.setType(type);
if (resolver.getDescription() != null) {
// $NON-NLS-1$
throw new CoreException(new Status(IStatus.ERROR, EditorsUI.PLUGIN_ID, IStatus.OK, resolver.getClass() + "() must call super() and not set the variable's description", null));
}
String desc = element.getAttribute(DESCRIPTION);
// $NON-NLS-1$
resolver.setDescription(desc == null ? "" : desc);
return resolver;
}
} catch (ClassCastException e) {
// $NON-NLS-1$
throw new CoreException(new Status(IStatus.ERROR, EditorsUI.PLUGIN_ID, IStatus.OK, "extension does not implement " + TemplateVariableResolver.class.getName(), e));
}
return null;
}
use of org.eclipse.jface.text.templates.TemplateVariableResolver in project eclipse.platform.text by eclipse.
the class TemplateVariableProcessor method computeCompletionProposals.
@Override
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int documentOffset) {
if (fContextType == null)
return null;
List<TemplateVariableProposal> proposals = new ArrayList<>();
String text = viewer.getDocument().get();
int start = getStart(text, documentOffset);
int end = documentOffset;
String string = text.substring(start, end);
String prefix = (string.length() >= 2) ? string.substring(2) : null;
int offset = start;
int length = end - start;
for (Iterator<TemplateVariableResolver> iterator = fContextType.resolvers(); iterator.hasNext(); ) {
TemplateVariableResolver variable = iterator.next();
if (prefix == null || variable.getType().startsWith(prefix))
proposals.add(new TemplateVariableProposal(variable, offset, length, viewer));
}
Collections.sort(proposals, fgTemplateVariableProposalComparator);
return proposals.toArray(new ICompletionProposal[proposals.size()]);
}
Aggregations