| /** |
| * Copyright (c) 2011, 2018 - 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 |
| * |
| * generated by Xtext 2.11.0 |
| */ |
| package org.eclipse.osbp.xtext.signal.ui.contentassist; |
| |
| import com.google.inject.Inject; |
| import java.net.MalformedURLException; |
| import java.net.URL; |
| import java.nio.file.Paths; |
| import org.eclipse.emf.common.util.EList; |
| import org.eclipse.emf.ecore.EObject; |
| import org.eclipse.jface.text.contentassist.ICompletionProposal; |
| import org.eclipse.jface.viewers.StyledString; |
| import org.eclipse.osbp.xtext.basic.ui.contentassist.BasicDSLProposalProviderHelper; |
| import org.eclipse.osbp.xtext.datainterchange.DataInterchange; |
| import org.eclipse.osbp.xtext.signal.SignalDatainterchange; |
| import org.eclipse.osbp.xtext.signal.SignalDefinition; |
| import org.eclipse.osbp.xtext.signal.SignalFunction; |
| import org.eclipse.osbp.xtext.signal.SignalScheduler; |
| import org.eclipse.osbp.xtext.signal.SignalTask; |
| import org.eclipse.osbp.xtext.signal.SignalWatcher; |
| import org.eclipse.osbp.xtext.signal.ui.SignalDSLDocumentationTranslator; |
| import org.eclipse.osbp.xtext.signal.ui.contentassist.AbstractSignalDSLProposalProvider; |
| import org.eclipse.osbp.xtext.signal.ui.contentassist.DirectoryNameTextApplier; |
| 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.lib.Exceptions; |
| |
| @SuppressWarnings("all") |
| public class SignalDSLProposalProvider extends AbstractSignalDSLProposalProvider { |
| private final String APPLYON = "applyon"; |
| |
| @Inject |
| private TerminalsProposalProvider provider; |
| |
| @Inject |
| private BasicDSLProposalProviderHelper providerHelper; |
| |
| @Override |
| protected StyledString getKeywordDisplayString(final Keyword keyword) { |
| return BasicDSLProposalProviderHelper.getKeywordDisplayString(keyword, |
| SignalDSLDocumentationTranslator.instance()); |
| } |
| |
| /** |
| * This override will enable 1 length non letter characters as keyword. |
| */ |
| @Override |
| protected boolean isKeywordWorthyToPropose(final Keyword keyword) { |
| return true; |
| } |
| |
| @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); |
| } |
| |
| public void directoryPickerProposal(final EObject model, final ContentAssistContext context, final ICompletionProposalAcceptor acceptor) { |
| ICompletionProposal _createCompletionProposal = this.createCompletionProposal("Select directory...", context); |
| ConfigurableCompletionProposal dirName = ((ConfigurableCompletionProposal) _createCompletionProposal); |
| if ((dirName != null)) { |
| DirectoryNameTextApplier applier = new DirectoryNameTextApplier(); |
| applier.setContext(context); |
| dirName.setTextApplier(applier); |
| } |
| acceptor.accept(dirName); |
| } |
| |
| /** |
| * This method decided which proposals will be valid. |
| */ |
| @Override |
| protected boolean isValidProposal(final String proposal, final String prefix, final ContentAssistContext context) { |
| boolean result = super.isValidProposal(proposal, prefix, context); |
| EObject _currentModel = context.getCurrentModel(); |
| if ((_currentModel instanceof SignalWatcher)) { |
| EObject _currentModel_1 = context.getCurrentModel(); |
| result = this.isValidProposalForSignalWatchers(proposal, prefix, ((SignalWatcher) _currentModel_1), result); |
| } else { |
| EObject _currentModel_2 = context.getCurrentModel(); |
| if ((_currentModel_2 instanceof SignalDatainterchange)) { |
| EObject _currentModel_3 = context.getCurrentModel(); |
| result = this.isValidProposalSignalDatainterchange(proposal, prefix, ((SignalDatainterchange) _currentModel_3), result); |
| } |
| } |
| return result; |
| } |
| |
| public boolean isValidProposalSignalDatainterchange(final String proposal, final String prefix, final SignalDatainterchange interchange, final boolean result) { |
| boolean _equals = proposal.equals(this.APPLYON); |
| if (_equals) { |
| EObject signal = interchange.eContainer(); |
| if ((signal instanceof SignalWatcher)) { |
| if (((((SignalWatcher)signal).getDefaultInterchange() != null) || this.basedInterchangeDefined(((SignalWatcher)signal).getTasks()))) { |
| return false; |
| } |
| } else { |
| if ((signal instanceof SignalScheduler)) { |
| return false; |
| } |
| } |
| } |
| return result; |
| } |
| |
| private boolean isValidProposalForSignalWatchers(final String proposal, final String prefix, final SignalWatcher watcher, final boolean result) { |
| if ((((watcher != null) && (watcher.getTasks() != null)) && (!watcher.getTasks().isEmpty()))) { |
| boolean _equals = proposal.equals(this.APPLYON); |
| if (_equals) { |
| DataInterchange _defaultInterchange = watcher.getDefaultInterchange(); |
| boolean _tripleNotEquals = (_defaultInterchange != null); |
| if (_tripleNotEquals) { |
| return false; |
| } |
| if ((this.basedInterchangeDefined(watcher.getTasks()) && (watcher.getDefaultInterchange() == null))) { |
| return false; |
| } |
| } |
| } |
| return result; |
| } |
| |
| public boolean basedInterchangeDefined(final EList<SignalTask> tasks) { |
| for (final SignalTask task : tasks) { |
| if ((task instanceof SignalDatainterchange)) { |
| boolean _isBaseinterchange = ((SignalDatainterchange)task).isBaseinterchange(); |
| if (_isBaseinterchange) { |
| return true; |
| } |
| } |
| } |
| return false; |
| } |
| |
| public URL getDirectoryURL(final String directory) { |
| try { |
| return new URL(directory); |
| } catch (final Throwable _t) { |
| if (_t instanceof MalformedURLException) { |
| final MalformedURLException e1 = (MalformedURLException)_t; |
| if ((e1.getMessage().startsWith("unknown protocol") || e1.getMessage().startsWith("no protocol"))) { |
| try { |
| return Paths.get(directory).toUri().toURL(); |
| } catch (final Throwable _t_1) { |
| if (_t_1 instanceof MalformedURLException) { |
| final MalformedURLException e2 = (MalformedURLException)_t_1; |
| return null; |
| } else { |
| throw Exceptions.sneakyThrow(_t_1); |
| } |
| } |
| } |
| } else { |
| throw Exceptions.sneakyThrow(_t); |
| } |
| } |
| return null; |
| } |
| |
| public DataInterchange baseInterchange(final SignalDefinition signal) { |
| if ((signal instanceof SignalWatcher)) { |
| DataInterchange _defaultInterchange = ((SignalWatcher)signal).getDefaultInterchange(); |
| boolean _tripleNotEquals = (_defaultInterchange != null); |
| if (_tripleNotEquals) { |
| return ((SignalWatcher)signal).getDefaultInterchange(); |
| } else { |
| if (((((SignalWatcher)signal).getTasks() != null) && (!((SignalWatcher)signal).getTasks().isEmpty()))) { |
| EList<SignalTask> _tasks = ((SignalWatcher)signal).getTasks(); |
| for (final SignalTask task : _tasks) { |
| if ((task instanceof SignalDatainterchange)) { |
| boolean _isBaseinterchange = ((SignalDatainterchange)task).isBaseinterchange(); |
| if (_isBaseinterchange) { |
| return ((SignalDatainterchange)task).getDataRef(); |
| } |
| } |
| } |
| } |
| } |
| } |
| return null; |
| } |
| |
| public int definedBaseInterchangeCount(final SignalDefinition signal) { |
| int count = 0; |
| EList<SignalTask> _tasks = signal.getTasks(); |
| for (final SignalTask task : _tasks) { |
| if ((task instanceof SignalDatainterchange)) { |
| boolean _isBaseinterchange = ((SignalDatainterchange)task).isBaseinterchange(); |
| if (_isBaseinterchange) { |
| count++; |
| } |
| } |
| } |
| return count; |
| } |
| |
| public SignalDatainterchange definedBaseInterchange(final SignalDefinition signal) { |
| EList<SignalTask> _tasks = signal.getTasks(); |
| for (final SignalTask task : _tasks) { |
| if ((task instanceof SignalDatainterchange)) { |
| boolean _isBaseinterchange = ((SignalDatainterchange)task).isBaseinterchange(); |
| if (_isBaseinterchange) { |
| return ((SignalDatainterchange)task); |
| } |
| } |
| } |
| return null; |
| } |
| |
| public int taskCount(final SignalDefinition signal, final boolean interchange) { |
| int count = 0; |
| EList<SignalTask> _tasks = signal.getTasks(); |
| for (final SignalTask task : _tasks) { |
| if (interchange) { |
| if ((task instanceof SignalDatainterchange)) { |
| count++; |
| } |
| } else { |
| if ((task instanceof SignalFunction)) { |
| count++; |
| } |
| } |
| } |
| return count; |
| } |
| |
| @Override |
| public void complete_INT(final EObject model, final RuleCall ruleCall, final ContentAssistContext context, final ICompletionProposalAcceptor acceptor) { |
| this.provider.complete_INT(model, ruleCall, context, acceptor); |
| } |
| |
| @Override |
| public void complete_TRANSLATABLEID(final EObject model, final RuleCall ruleCall, final ContentAssistContext context, final ICompletionProposalAcceptor acceptor) { |
| this.provider.complete_ID(model, ruleCall, context, acceptor); |
| } |
| |
| @Override |
| public void complete_TRANSLATABLESTRING(final EObject model, final RuleCall ruleCall, final ContentAssistContext context, final ICompletionProposalAcceptor acceptor) { |
| this.provider.complete_STRING(model, ruleCall, context, acceptor); |
| } |
| |
| @Override |
| public void complete_STRING(final EObject model, final RuleCall ruleCall, final ContentAssistContext context, final ICompletionProposalAcceptor acceptor) { |
| this.provider.complete_STRING(model, ruleCall, context, acceptor); |
| } |
| } |