Java源码示例:org.eclipse.xtext.ui.editor.contentassist.ITemplateAcceptor
示例1
@Override
public void createTemplates(ContentAssistContext context, ITemplateAcceptor acceptor) {
if (!acceptor.canAcceptMoreTemplates())
return;
TemplateContext[] templateContexts = createTemplateContexts(context);
if (templateContexts == null || templateContexts.length == 0)
return;
ITemplateAcceptor nullSafe = new NullSafeTemplateAcceptor(acceptor);
for(TemplateContext templateContext: templateContexts) {
if (!nullSafe.canAcceptMoreTemplates())
return;
templateContext.setVariable("selection", context.getSelectedText()); // name of the selection variables {line, word}_selection //$NON-NLS-1$
createTemplates(templateContext, context, nullSafe);
}
}
示例2
@Override
protected void createTemplates(final TemplateContext templateContext, final ContentAssistContext context, final ITemplateAcceptor acceptor) {
if (templateContext.getContextType().getId().equals("com.avaloq.tools.ddk.checkcfg.CheckCfg.ConfiguredCheck")) { //$NON-NLS-1$
addConfiguredCheckTemplates(templateContext, context, acceptor);
return;
} else if (templateContext.getContextType().getId().equals("com.avaloq.tools.ddk.checkcfg.CheckCfg.kw_catalog")) { //$NON-NLS-1$
addCatalogConfigurations(templateContext, context, 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)));
}
}
}
示例3
@Override
protected void createTemplates(final TemplateContext templateContext, final ContentAssistContext context,
final ITemplateAcceptor acceptor) {
// Disabling for comments (see Issue 786)
final EObject grammarElement = context.getCurrentNode().getGrammarElement();
if (grammarElement == ga.getML_COMMENTRule()) { return; }
if (grammarElement == ga.getSL_COMMENTRule()) { return; }
// TemplateContextType contextType = templateContext.getContextType();
final Template[] templates = store.getTemplates();
for (final Template template : templates) {
if (!acceptor.canAcceptMoreTemplates()) { return; }
if (validate(template, templateContext)) {
acceptor.accept(
createProposal(template, templateContext, context, getImage(template), getRelevance(template)));
}
}
}
示例4
@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)));
}
}
}
示例5
/**
* Adds the populated check configuration.
*
* @param templateContext
* the template context
* @param context
* the context
* @param acceptor
* the acceptor
*/
@SuppressWarnings("all")
private void addCatalogConfigurations(final TemplateContext templateContext, final ContentAssistContext context, final ITemplateAcceptor acceptor) {
final String templateName = "Add all registered catalogs"; //$NON-NLS-1$
final String templateDescription = "configures all missing catalogs"; //$NON-NLS-1$
final String contextTypeId = templateContext.getContextType().getId();
if (context.getRootModel() instanceof CheckConfiguration) {
final CheckConfiguration conf = (CheckConfiguration) context.getRootModel();
List<IEObjectDescription> allElements = Lists.newArrayList(scopeProvider.getScope(conf, CheckcfgPackage.Literals.CONFIGURED_CATALOG__CATALOG).getAllElements());
StringBuilder builder = new StringBuilder();
for (IEObjectDescription description : allElements) {
if (description.getEObjectOrProxy() instanceof CheckCatalog) {
CheckCatalog catalog = (CheckCatalog) description.getEObjectOrProxy();
if (catalog.eIsProxy()) {
catalog = (CheckCatalog) EcoreUtil.resolve(catalog, conf);
}
if (isCatalogConfigured(conf, catalog)) {
continue;
} else if (allElements.indexOf(description) > 0) {
builder.append(Strings.newLine());
}
final String catalogName = qualifiedNameValueConverter.toString(description.getQualifiedName().toString());
builder.append("catalog ").append(catalogName).append(" {}").append(Strings.newLine()); //$NON-NLS-1$ //$NON-NLS-2$
}
}
if (builder.length() > 0) {
builder.append("${cursor}"); //$NON-NLS-1$
Template t = new Template(templateName, templateDescription, contextTypeId, builder.toString(), true);
TemplateProposal tp = createProposal(t, templateContext, context, images.forConfiguredCatalog(), getRelevance(t));
acceptor.accept(tp);
}
}
}
示例6
/**
* Adds template proposals for all checks which may be referenced in current catalog configuration. Only proposals for checks
* which have not yet been configured are provided.
*
* @param templateContext
* the template context
* @param context
* the context
* @param acceptor
* the acceptor
*/
private void addConfiguredCheckTemplates(final TemplateContext templateContext, final ContentAssistContext context, final ITemplateAcceptor acceptor) { // NOPMD
ConfiguredCatalog configuredCatalog = EcoreUtil2.getContainerOfType(context.getCurrentModel(), ConfiguredCatalog.class);
Iterable<String> alreadyConfiguredCheckNames = Iterables.filter(Iterables.transform(configuredCatalog.getCheckConfigurations(), new Function<ConfiguredCheck, String>() {
@Override
public String apply(final ConfiguredCheck from) {
if (from.getCheck() != null) {
return from.getCheck().getName();
}
return null;
}
}), Predicates.notNull());
final CheckCatalog catalog = configuredCatalog.getCatalog();
for (final Check check : catalog.getAllChecks()) {
// create a template on the fly
final String checkName = check.getName();
if (!Iterables.contains(alreadyConfiguredCheckNames, checkName)) {
// check if referenced check has configurable parameters
final StringJoiner paramsJoiner = new StringJoiner(", ", " (", ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
paramsJoiner.setEmptyValue(""); //$NON-NLS-1$
for (final FormalParameter param : check.getFormalParameters()) {
final String paramName = param.getName();
final Object defaultValue = interpreter.evaluate(param.getRight()).getResult();
final String valuePlaceholder = helper.createLiteralValuePattern(paramName, defaultValue);
paramsJoiner.add(paramName + " = " + valuePlaceholder); //$NON-NLS-1$
}
final String severity = (catalog.isFinal() || check.isFinal()) ? "default " : "${default:Enum('SeverityKind')} "; //$NON-NLS-1$ //$NON-NLS-2$
final String description = "Configures the check \"" + check.getLabel() + "\""; //$NON-NLS-1$ //$NON-NLS-2$
final String contextTypeId = "com.avaloq.tools.ddk.checkcfg.CheckCfg.ConfiguredCheck." + checkName; //$NON-NLS-1$
final String pattern = severity + qualifiedNameValueConverter.toString(checkName) + paramsJoiner + "${cursor}"; //$NON-NLS-1$
Template t = new Template(checkName, description, contextTypeId, pattern, true);
TemplateProposal tp = createProposal(t, templateContext, context, images.forConfiguredCheck(check.getDefaultSeverity()), getRelevance(t));
acceptor.accept(tp);
}
}
}
示例7
@Override
protected void createTemplates(TemplateContext templateContext, ContentAssistContext context,
ITemplateAcceptor acceptor) {
super.createTemplates(templateContext, context, acceptor);
String id = helper.getId(gaccess.getFeatureConfigurationRule());
if (templateContext.getContextType().getId().equals(id)) {
createFeatureConfigurationTemplates(templateContext, context, acceptor);
}
}
示例8
private void createFeatureConfigurationTemplates(TemplateContext templateContext, ContentAssistContext context,
ITemplateAcceptor acceptor) {
GeneratorModel model = (GeneratorModel) EcoreUtil2.getRootContainer(context.getCurrentModel());
Optional<IGeneratorDescriptor> generatorDescriptor = GeneratorExtensions
.getGeneratorDescriptor(model.getGeneratorId());
if (!generatorDescriptor.isPresent()) {
return;
}
Iterable<ILibraryDescriptor> libraryDescriptor = LibraryExtensions
.getLibraryDescriptors(generatorDescriptor.get().getLibraryIDs());
for (ILibraryDescriptor desc : libraryDescriptor) {
ResourceSet set = new ResourceSetImpl();
Resource resource = set.getResource(desc.getURI(), true);
FeatureTypeLibrary lib = (FeatureTypeLibrary) resource.getContents().get(0);
EList<FeatureType> types = lib.getTypes();
for (FeatureType featureType : types) {
Template template = new Template(featureType.getName() + " feature",
"Creates feature " + featureType.getName(), featureType.getName(),
creator.createProposal(featureType,
desc.createFeatureValueProvider(GenmodelActivator.getInstance()
.getInjector(GenmodelActivator.ORG_YAKINDU_SCT_GENERATOR_GENMODEL_SGEN)),
context.getCurrentModel()),
false);
TemplateProposal proposal = createProposal(template, templateContext, context, getImage(template),
getRelevance(template));
acceptor.accept(proposal);
}
}
}
示例9
public NullSafeTemplateAcceptor(ITemplateAcceptor delegate) {
super();
setDelegate(delegate);
}
示例10
protected abstract void createTemplates(TemplateContext templateContext, ContentAssistContext context, ITemplateAcceptor acceptor);