| /** |
| * Copyright (c) 2011, 2016 - Loetz GmbH&Co.KG (69115 Heidelberg, Germany) |
| * |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License 2.0 |
| * which accompanies this distribution, and is available at |
| * https://www.eclipse.org/legal/epl-2.0/ |
| * |
| * SPDX-License-Identifier: EPL-2.0 |
| * |
| * Contributors: |
| * Christophe Loetz (Loetz GmbH&Co.KG) - initial implementation |
| * |
| * |
| * This copyright notice shows up in the generated Java code |
| */ |
| package org.eclipse.osbp.xtext.messagedsl.ui.contentassist; |
| |
| import com.google.inject.Inject; |
| import java.util.TreeMap; |
| import java.util.function.BiConsumer; |
| import java.util.function.Consumer; |
| import org.eclipse.emf.ecore.EObject; |
| import org.eclipse.jface.viewers.StyledString; |
| import org.eclipse.osbp.xtext.basic.ui.contentassist.BasicDSLProposalProviderHelper; |
| import org.eclipse.osbp.xtext.messagedsl.MessageItem; |
| import org.eclipse.osbp.xtext.messagedsl.MessageParameter; |
| import org.eclipse.osbp.xtext.messagedsl.ParameterTypeEnum; |
| import org.eclipse.osbp.xtext.messagedsl.ui.MessageDslUiDocumentationTranslator; |
| import org.eclipse.osbp.xtext.messagedsl.ui.contentassist.AbstractMessageDslProposalProvider; |
| import org.eclipse.osbp.xtext.messagedsl.ui.contentassist.InsideStringConfigurableCompletionProposal; |
| import org.eclipse.swt.graphics.Image; |
| import org.eclipse.swt.graphics.Point; |
| import org.eclipse.xtend2.lib.StringConcatenation; |
| import org.eclipse.xtext.Assignment; |
| import org.eclipse.xtext.Keyword; |
| import org.eclipse.xtext.RuleCall; |
| import org.eclipse.xtext.common.ui.contentassist.TerminalsProposalProvider; |
| import org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal; |
| import org.eclipse.xtext.ui.editor.contentassist.ContentAssistContext; |
| import org.eclipse.xtext.ui.editor.contentassist.ICompletionProposalAcceptor; |
| import org.eclipse.xtext.xbase.jvmmodel.JvmTypesBuilder; |
| import org.eclipse.xtext.xbase.lib.Extension; |
| |
| /** |
| * see https://eclipse.org/Xtext/documentation/304_ide_concepts.html#content-assist on how to customize content assistant |
| */ |
| @SuppressWarnings("all") |
| public class MessageDslProposalProvider extends AbstractMessageDslProposalProvider { |
| @Inject |
| private TerminalsProposalProvider provider; |
| |
| @Inject |
| private BasicDSLProposalProviderHelper providerHelper; |
| |
| /** |
| * @see BasicDSLProposalProviderHelper#getKeywordDisplayString(Keyword, BasicDSLUiTranslator) |
| * @param keyword the keyword to get the displayed string for |
| * @return the displayed string |
| */ |
| @Override |
| protected StyledString getKeywordDisplayString(final Keyword keyword) { |
| return BasicDSLProposalProviderHelper.getKeywordDisplayString(keyword, MessageDslUiDocumentationTranslator.instance()); |
| } |
| |
| /** |
| * This override will enable 1 length non letter characters as keyword. |
| */ |
| @Override |
| protected boolean isKeywordWorthyToPropose(final Keyword keyword) { |
| return true; |
| } |
| |
| /** |
| * convenience API to build and initialize JVM types and their members. |
| */ |
| @Inject |
| @Extension |
| private JvmTypesBuilder _jvmTypesBuilder; |
| |
| @Override |
| public void complete_QualifiedName(final EObject model, final RuleCall ruleCall, final ContentAssistContext context, final ICompletionProposalAcceptor acceptor) { |
| this.providerHelper.complete_PackageName(model, ruleCall, context, acceptor, this); |
| } |
| |
| /** |
| * see also {@link org.eclipse.osbp.xtext.messagedsl.common.Message.prepareMessage()} |
| */ |
| @Override |
| public void completeMessageText_Text(final EObject model, final Assignment assignment, final ContentAssistContext context, final ICompletionProposalAcceptor acceptor) { |
| super.completeMessageText_Text(model, assignment, context, acceptor); |
| final TreeMap<String, String> available = new TreeMap<String, String>(); |
| final TreeMap<String, String> used = new TreeMap<String, String>(); |
| final Image image = ((Image) null); |
| final String document = context.getViewer().getDocument().get().replace("\\\"", "\'\'"); |
| final int formatoffset = context.getReplaceRegion().getOffset(); |
| final int nextquote = document.indexOf("\"", (formatoffset + 1)); |
| final String replaceRegion = document.substring(formatoffset, (nextquote + 1)); |
| final Consumer<MessageParameter> _function = new Consumer<MessageParameter>() { |
| @Override |
| public void accept(final MessageParameter parameter) { |
| ParameterTypeEnum _oftype = parameter.getOftype(); |
| if (_oftype != null) { |
| switch (_oftype) { |
| case BOOLEAN: |
| StringConcatenation _builder = new StringConcatenation(); |
| _builder.append("%%"); |
| String _name = parameter.getName(); |
| _builder.append(_name); |
| _builder.append("%%"); |
| final String proposal = _builder.toString(); |
| StringConcatenation _builder_1 = new StringConcatenation(); |
| _builder_1.append(proposal); |
| _builder_1.append(" (boolean) "); |
| String _documentation = MessageDslProposalProvider.this._jvmTypesBuilder.getDocumentation(parameter); |
| _builder_1.append(_documentation); |
| final String displayString = _builder_1.toString(); |
| boolean _contains = replaceRegion.contains(proposal); |
| if (_contains) { |
| StringConcatenation _builder_2 = new StringConcatenation(); |
| _builder_2.append("used: "); |
| _builder_2.append(displayString); |
| used.put(proposal, _builder_2.toString()); |
| } else { |
| available.put(proposal, displayString); |
| } |
| break; |
| case INTEGER: |
| StringConcatenation _builder_3 = new StringConcatenation(); |
| _builder_3.append("%%"); |
| String _name_1 = parameter.getName(); |
| _builder_3.append(_name_1); |
| _builder_3.append("%%"); |
| final String proposal_1 = _builder_3.toString(); |
| StringConcatenation _builder_4 = new StringConcatenation(); |
| _builder_4.append(proposal_1); |
| _builder_4.append(" (int) "); |
| String _documentation_1 = MessageDslProposalProvider.this._jvmTypesBuilder.getDocumentation(parameter); |
| _builder_4.append(_documentation_1); |
| final String displayString_1 = _builder_4.toString(); |
| boolean _contains_1 = replaceRegion.contains(proposal_1); |
| if (_contains_1) { |
| StringConcatenation _builder_5 = new StringConcatenation(); |
| _builder_5.append("used: "); |
| _builder_5.append(displayString_1); |
| used.put(proposal_1, _builder_5.toString()); |
| } else { |
| available.put(proposal_1, displayString_1); |
| } |
| break; |
| case DOUBLE: |
| StringConcatenation _builder_6 = new StringConcatenation(); |
| _builder_6.append("%%"); |
| String _name_2 = parameter.getName(); |
| _builder_6.append(_name_2); |
| _builder_6.append("%%"); |
| final String proposal_2 = _builder_6.toString(); |
| StringConcatenation _builder_7 = new StringConcatenation(); |
| _builder_7.append(proposal_2); |
| _builder_7.append(" (double) "); |
| String _documentation_2 = MessageDslProposalProvider.this._jvmTypesBuilder.getDocumentation(parameter); |
| _builder_7.append(_documentation_2); |
| final String displayString_2 = _builder_7.toString(); |
| boolean _contains_2 = replaceRegion.contains(proposal_2); |
| if (_contains_2) { |
| StringConcatenation _builder_8 = new StringConcatenation(); |
| _builder_8.append("used: "); |
| _builder_8.append(displayString_2); |
| used.put(proposal_2, _builder_8.toString()); |
| } else { |
| available.put(proposal_2, displayString_2); |
| } |
| break; |
| case STRING: |
| StringConcatenation _builder_9 = new StringConcatenation(); |
| _builder_9.append("%%"); |
| String _name_3 = parameter.getName(); |
| _builder_9.append(_name_3); |
| _builder_9.append("%%"); |
| final String proposal_3 = _builder_9.toString(); |
| StringConcatenation _builder_10 = new StringConcatenation(); |
| _builder_10.append(proposal_3); |
| _builder_10.append(" (String) "); |
| String _documentation_3 = MessageDslProposalProvider.this._jvmTypesBuilder.getDocumentation(parameter); |
| _builder_10.append(_documentation_3); |
| final String displayString_3 = _builder_10.toString(); |
| boolean _contains_3 = replaceRegion.contains(proposal_3); |
| if (_contains_3) { |
| StringConcatenation _builder_11 = new StringConcatenation(); |
| _builder_11.append("used: "); |
| _builder_11.append(displayString_3); |
| used.put(proposal_3, _builder_11.toString()); |
| } else { |
| available.put(proposal_3, displayString_3); |
| } |
| break; |
| case CLASS: |
| { |
| StringConcatenation _builder_12 = new StringConcatenation(); |
| _builder_12.append("%%"); |
| String _name_4 = parameter.getName(); |
| _builder_12.append(_name_4); |
| _builder_12.append(".canonicalName%%"); |
| final String proposal_4 = _builder_12.toString(); |
| StringConcatenation _builder_13 = new StringConcatenation(); |
| _builder_13.append(proposal_4); |
| _builder_13.append(" (canonical name for Class) "); |
| String _documentation_4 = MessageDslProposalProvider.this._jvmTypesBuilder.getDocumentation(parameter); |
| _builder_13.append(_documentation_4); |
| final String displayString_4 = _builder_13.toString(); |
| boolean _contains_4 = replaceRegion.contains(proposal_4); |
| if (_contains_4) { |
| StringConcatenation _builder_14 = new StringConcatenation(); |
| _builder_14.append("used: "); |
| _builder_14.append(displayString_4); |
| used.put(proposal_4, _builder_14.toString()); |
| } else { |
| available.put(proposal_4, displayString_4); |
| } |
| } |
| { |
| StringConcatenation _builder_12 = new StringConcatenation(); |
| _builder_12.append("%%"); |
| String _name_4 = parameter.getName(); |
| _builder_12.append(_name_4); |
| _builder_12.append(".simpleName%%"); |
| final String proposal_4 = _builder_12.toString(); |
| StringConcatenation _builder_13 = new StringConcatenation(); |
| _builder_13.append(proposal_4); |
| _builder_13.append(" (simple name for Class) "); |
| String _documentation_4 = MessageDslProposalProvider.this._jvmTypesBuilder.getDocumentation(parameter); |
| _builder_13.append(_documentation_4); |
| final String displayString_4 = _builder_13.toString(); |
| boolean _contains_4 = replaceRegion.contains(proposal_4); |
| if (_contains_4) { |
| StringConcatenation _builder_14 = new StringConcatenation(); |
| _builder_14.append("used: "); |
| _builder_14.append(displayString_4); |
| used.put(proposal_4, _builder_14.toString()); |
| } else { |
| available.put(proposal_4, displayString_4); |
| } |
| } |
| break; |
| case OBJECT: |
| { |
| StringConcatenation _builder_12 = new StringConcatenation(); |
| _builder_12.append("%%"); |
| String _name_4 = parameter.getName(); |
| _builder_12.append(_name_4); |
| _builder_12.append(".canonicalName%%"); |
| final String proposal_4 = _builder_12.toString(); |
| StringConcatenation _builder_13 = new StringConcatenation(); |
| _builder_13.append(proposal_4); |
| _builder_13.append(" (canonical name for Object) "); |
| String _documentation_4 = MessageDslProposalProvider.this._jvmTypesBuilder.getDocumentation(parameter); |
| _builder_13.append(_documentation_4); |
| final String displayString_4 = _builder_13.toString(); |
| boolean _contains_4 = replaceRegion.contains(proposal_4); |
| if (_contains_4) { |
| StringConcatenation _builder_14 = new StringConcatenation(); |
| _builder_14.append("used: "); |
| _builder_14.append(displayString_4); |
| used.put(proposal_4, _builder_14.toString()); |
| } else { |
| available.put(proposal_4, displayString_4); |
| } |
| } |
| { |
| StringConcatenation _builder_12 = new StringConcatenation(); |
| _builder_12.append("%%"); |
| String _name_4 = parameter.getName(); |
| _builder_12.append(_name_4); |
| _builder_12.append(".simpleName%%"); |
| final String proposal_4 = _builder_12.toString(); |
| StringConcatenation _builder_13 = new StringConcatenation(); |
| _builder_13.append(proposal_4); |
| _builder_13.append(" (simple name for Object) "); |
| String _documentation_4 = MessageDslProposalProvider.this._jvmTypesBuilder.getDocumentation(parameter); |
| _builder_13.append(_documentation_4); |
| final String displayString_4 = _builder_13.toString(); |
| boolean _contains_4 = replaceRegion.contains(proposal_4); |
| if (_contains_4) { |
| StringConcatenation _builder_14 = new StringConcatenation(); |
| _builder_14.append("used: "); |
| _builder_14.append(displayString_4); |
| used.put(proposal_4, _builder_14.toString()); |
| } else { |
| available.put(proposal_4, displayString_4); |
| } |
| } |
| break; |
| case EXCEPTION: |
| { |
| StringConcatenation _builder_12 = new StringConcatenation(); |
| _builder_12.append("%%"); |
| String _name_4 = parameter.getName(); |
| _builder_12.append(_name_4); |
| _builder_12.append(".canonicalName%%"); |
| final String proposal_4 = _builder_12.toString(); |
| StringConcatenation _builder_13 = new StringConcatenation(); |
| _builder_13.append(proposal_4); |
| _builder_13.append(" (canonical name for Exception) "); |
| String _documentation_4 = MessageDslProposalProvider.this._jvmTypesBuilder.getDocumentation(parameter); |
| _builder_13.append(_documentation_4); |
| final String displayString_4 = _builder_13.toString(); |
| boolean _contains_4 = replaceRegion.contains(proposal_4); |
| if (_contains_4) { |
| StringConcatenation _builder_14 = new StringConcatenation(); |
| _builder_14.append("used: "); |
| _builder_14.append(displayString_4); |
| used.put(proposal_4, _builder_14.toString()); |
| } else { |
| available.put(proposal_4, displayString_4); |
| } |
| } |
| { |
| StringConcatenation _builder_12 = new StringConcatenation(); |
| _builder_12.append("%%"); |
| String _name_4 = parameter.getName(); |
| _builder_12.append(_name_4); |
| _builder_12.append(".simpleName%%"); |
| final String proposal_4 = _builder_12.toString(); |
| StringConcatenation _builder_13 = new StringConcatenation(); |
| _builder_13.append(proposal_4); |
| _builder_13.append(" (simple name for Exception) "); |
| String _documentation_4 = MessageDslProposalProvider.this._jvmTypesBuilder.getDocumentation(parameter); |
| _builder_13.append(_documentation_4); |
| final String displayString_4 = _builder_13.toString(); |
| boolean _contains_4 = replaceRegion.contains(proposal_4); |
| if (_contains_4) { |
| StringConcatenation _builder_14 = new StringConcatenation(); |
| _builder_14.append("used: "); |
| _builder_14.append(displayString_4); |
| used.put(proposal_4, _builder_14.toString()); |
| } else { |
| available.put(proposal_4, displayString_4); |
| } |
| } |
| { |
| StringConcatenation _builder_12 = new StringConcatenation(); |
| _builder_12.append("%%"); |
| String _name_4 = parameter.getName(); |
| _builder_12.append(_name_4); |
| _builder_12.append(".localizedMessage%%"); |
| final String proposal_4 = _builder_12.toString(); |
| StringConcatenation _builder_13 = new StringConcatenation(); |
| _builder_13.append(proposal_4); |
| _builder_13.append(" (localized message for Exception) "); |
| String _documentation_4 = MessageDslProposalProvider.this._jvmTypesBuilder.getDocumentation(parameter); |
| _builder_13.append(_documentation_4); |
| final String displayString_4 = _builder_13.toString(); |
| boolean _contains_4 = replaceRegion.contains(proposal_4); |
| if (_contains_4) { |
| StringConcatenation _builder_14 = new StringConcatenation(); |
| _builder_14.append("used: "); |
| _builder_14.append(displayString_4); |
| used.put(proposal_4, _builder_14.toString()); |
| } else { |
| available.put(proposal_4, displayString_4); |
| } |
| } |
| { |
| StringConcatenation _builder_12 = new StringConcatenation(); |
| _builder_12.append("%%"); |
| String _name_4 = parameter.getName(); |
| _builder_12.append(_name_4); |
| _builder_12.append(".localizedDetailMessage%%"); |
| final String proposal_4 = _builder_12.toString(); |
| StringConcatenation _builder_13 = new StringConcatenation(); |
| _builder_13.append(proposal_4); |
| _builder_13.append(" (localized detail message for Exception) "); |
| String _documentation_4 = MessageDslProposalProvider.this._jvmTypesBuilder.getDocumentation(parameter); |
| _builder_13.append(_documentation_4); |
| final String displayString_4 = _builder_13.toString(); |
| boolean _contains_4 = replaceRegion.contains(proposal_4); |
| if (_contains_4) { |
| StringConcatenation _builder_14 = new StringConcatenation(); |
| _builder_14.append("used: "); |
| _builder_14.append(displayString_4); |
| used.put(proposal_4, _builder_14.toString()); |
| } else { |
| available.put(proposal_4, displayString_4); |
| } |
| } |
| { |
| StringConcatenation _builder_12 = new StringConcatenation(); |
| _builder_12.append("%%"); |
| String _name_4 = parameter.getName(); |
| _builder_12.append(_name_4); |
| _builder_12.append(".localizedSimpleDetailMessage%%"); |
| final String proposal_4 = _builder_12.toString(); |
| StringConcatenation _builder_13 = new StringConcatenation(); |
| _builder_13.append(proposal_4); |
| _builder_13.append(" (localized simple detail message for Exception) "); |
| String _documentation_4 = MessageDslProposalProvider.this._jvmTypesBuilder.getDocumentation(parameter); |
| _builder_13.append(_documentation_4); |
| final String displayString_4 = _builder_13.toString(); |
| boolean _contains_4 = replaceRegion.contains(proposal_4); |
| if (_contains_4) { |
| StringConcatenation _builder_14 = new StringConcatenation(); |
| _builder_14.append("used: "); |
| _builder_14.append(displayString_4); |
| used.put(proposal_4, _builder_14.toString()); |
| } else { |
| available.put(proposal_4, displayString_4); |
| } |
| } |
| { |
| StringConcatenation _builder_12 = new StringConcatenation(); |
| _builder_12.append("%%"); |
| String _name_4 = parameter.getName(); |
| _builder_12.append(_name_4); |
| _builder_12.append(".stackTrace%%"); |
| final String proposal_4 = _builder_12.toString(); |
| StringConcatenation _builder_13 = new StringConcatenation(); |
| _builder_13.append(proposal_4); |
| _builder_13.append(" (stack trace for Exception) "); |
| String _documentation_4 = MessageDslProposalProvider.this._jvmTypesBuilder.getDocumentation(parameter); |
| _builder_13.append(_documentation_4); |
| final String displayString_4 = _builder_13.toString(); |
| boolean _contains_4 = replaceRegion.contains(proposal_4); |
| if (_contains_4) { |
| StringConcatenation _builder_14 = new StringConcatenation(); |
| _builder_14.append("used: "); |
| _builder_14.append(displayString_4); |
| used.put(proposal_4, _builder_14.toString()); |
| } else { |
| available.put(proposal_4, displayString_4); |
| } |
| } |
| break; |
| default: |
| break; |
| } |
| } |
| } |
| }; |
| ((MessageItem) model).getParameters().forEach(_function); |
| final BiConsumer<String, String> _function_1 = new BiConsumer<String, String>() { |
| @Override |
| public void accept(final String proposal, final String displayString) { |
| StyledString _styledString = new StyledString(displayString); |
| acceptor.accept(MessageDslProposalProvider.this.doCreateInStringProposal(proposal, _styledString, image, |
| MessageDslProposalProvider.this.getPriorityHelper().getDefaultPriority(), context)); |
| } |
| }; |
| available.forEach(_function_1); |
| final BiConsumer<String, String> _function_2 = new BiConsumer<String, String>() { |
| @Override |
| public void accept(final String proposal, final String displayString) { |
| StyledString _styledString = new StyledString(displayString); |
| acceptor.accept(MessageDslProposalProvider.this.doCreateInStringProposal(proposal, _styledString, image, |
| MessageDslProposalProvider.this.getPriorityHelper().getDefaultPriority(), context)); |
| } |
| }; |
| used.forEach(_function_2); |
| } |
| |
| private ConfigurableCompletionProposal doCreateInStringProposal(final String proposal, final StyledString displayString, final Image image, final int priority, final ContentAssistContext context) { |
| final Point selectedRange = context.getViewer().getSelectedRange(); |
| final int replacementOffset = selectedRange.x; |
| final int replacementLength = selectedRange.y; |
| int _length = proposal.length(); |
| final InsideStringConfigurableCompletionProposal result = new InsideStringConfigurableCompletionProposal(proposal, replacementOffset, replacementLength, _length, image, displayString, null, null); |
| result.setPriority(priority); |
| result.setMatcher(context.getMatcher()); |
| result.setReplaceContextLength(context.getReplaceContextLength()); |
| return result; |
| } |
| |
| @Override |
| public void complete_ID(final EObject model, final RuleCall ruleCall, final ContentAssistContext context, final ICompletionProposalAcceptor acceptor) { |
| this.provider.complete_ID(model, ruleCall, context, acceptor); |
| } |
| } |