| /** |
| * |
| * 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.scoping |
| |
| import org.eclipse.emf.ecore.EObject |
| import org.eclipse.emf.ecore.EReference |
| import org.eclipse.osbp.xtext.datainterchange.DataInterchangeGroup |
| import org.eclipse.osbp.xtext.functionlibrarydsl.FunctionLibraryActionGroup |
| import org.eclipse.osbp.xtext.signal.SignalActionTypeEnum |
| import org.eclipse.osbp.xtext.signal.SignalDSLPackage |
| 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.SignalWatcher |
| import org.eclipse.xtext.scoping.Scopes |
| |
| /** |
| * This class contains custom scoping description. |
| * |
| * See https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#scoping |
| * on how and when to use it. |
| */ |
| class SignalDSLScopeProvider extends AbstractSignalDSLScopeProvider { |
| |
| override getScope(EObject context, EReference reference) { |
| if (reference == SignalDSLPackage.Literals.SIGNAL_DATAINTERCHANGE__DATA_REF) { |
| return getScope_DataInterchanges(context, reference) |
| } |
| else if (reference == SignalDSLPackage.Literals.SIGNAL_FUNCTION__SUPPORT_INTERCHANGE) { |
| return getScope_AllowedDataInterchangesForSupportedFile((context as SignalFunction), reference) |
| } |
| else if (reference == SignalDSLPackage.Literals.SIGNAL_WATCHER__DEFAULT_INTERCHANGE) { |
| return getScope_AllowedInterchangesForDefault((context as SignalDefinition), reference) |
| } |
| else if (reference == SignalDSLPackage.Literals.SIGNAL_FUNCTION__DO_EXECUTE_FUNCTION) { |
| return getScope_DoExecuteFunctions((context as SignalFunction).group, reference) |
| } |
| else { |
| super.getScope(context, reference) |
| } |
| } |
| |
| def getScope_DataInterchanges(EObject context, EReference reference) { |
| var result = <EObject>newArrayList |
| if (context !== null) { |
| var signal = context.eContainer |
| var group = null as DataInterchangeGroup |
| if(signal instanceof SignalWatcher){ |
| group = signal.interchangegroup |
| } |
| else if(signal instanceof SignalScheduler){ |
| group = signal.interchangegroup |
| } |
| for(value : group.datInts){ |
| result.add(value) |
| } |
| } |
| return Scopes::scopeFor(result) |
| } |
| def getScope_AllowedInterchangesForDefault(SignalDefinition signal, EReference reference) { |
| var result = <EObject>newArrayList |
| if(signal !== null ){ |
| var group = signal.interchangegroup |
| for(value : group.datInts){ |
| result.add(value) |
| } |
| return Scopes::scopeFor(result) |
| } |
| } |
| |
| def getScope_AllowedDataInterchangesForSupportedFile(SignalFunction function, EReference reference) { |
| var result = <EObject>newArrayList |
| if (function !== null) { |
| var signal = function.eContainer |
| if(signal instanceof SignalDefinition){ |
| if(signal.tasks !== null && !signal.tasks.empty){ |
| for(task : signal.tasks){ |
| if(task instanceof SignalDatainterchange){ |
| if(function.onExportFile && task.actionType.equals(SignalActionTypeEnum.DATAEXPORT)){ |
| result.add(task.dataRef) |
| } |
| else if(function.onImportFile && task.actionType.equals(SignalActionTypeEnum.DATAIMPORT)){ |
| result.add(task.dataRef) |
| } |
| } |
| } |
| } |
| } |
| } |
| return Scopes::scopeFor(result) |
| } |
| |
| def getScope_AllowedDefaultDataInterchanges(FunctionLibraryActionGroup group, EReference reference) { |
| var result = <EObject>newArrayList |
| if (group !== null) { |
| for(function : group.executes){ |
| result.add(function) |
| } |
| } |
| return Scopes::scopeFor(result) |
| } |
| def getScope_DoExecuteFunctions(FunctionLibraryActionGroup group, EReference reference) { |
| var result = <EObject>newArrayList |
| if (group !== null) { |
| for(function : group.executes){ |
| result.add(function) |
| } |
| } |
| return Scopes::scopeFor(result) |
| } |
| } |