| /** |
| * |
| * 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 v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * Christophe Loetz (Loetz GmbH&Co.KG) - initial implementation |
| * |
| * |
| * This copyright notice shows up in the generated Java code |
| * |
| */ |
| |
| package org.eclipse.osbp.xtext.action.scoping |
| |
| import org.eclipse.xtext.xbase.annotations.typesystem.XbaseWithAnnotationsBatchScopeProvider |
| import org.eclipse.emf.ecore.EObject |
| import org.eclipse.emf.ecore.EReference |
| import org.eclipse.osbp.xtext.action.ActionDSLPackage |
| import org.eclipse.xtext.resource.IEObjectDescription |
| import org.eclipse.xtext.scoping.impl.MapBasedScope |
| import org.eclipse.osbp.xtext.action.ActionButton |
| import org.eclipse.osbp.xtext.functionlibrarydsl.FunctionLibraryGroup |
| import org.eclipse.xtext.resource.EObjectDescription |
| import org.eclipse.xtext.scoping.Scopes |
| import org.eclipse.osbp.xtext.messagedsl.MessageItem |
| |
| class ActionScopeProvider extends XbaseWithAnnotationsBatchScopeProvider { |
| |
| override getScope(EObject context, EReference reference) { |
| if (reference == ActionDSLPackage.Literals.ACTION_BUTTON__CANEXECUTE) { |
| return getScope_ActionButtonCanExecute(context as ActionButton, reference) |
| } |
| else if (reference == ActionDSLPackage.Literals.ACTION_BUTTON__EXECUTEPARAMETER) { |
| return getScope_ActionButtonExecuteParameter(context as ActionButton, reference) |
| } |
| // else if (reference == ActionDSLPackage.Literals._ACTION_BUTTON__MESSAGE) { |
| // return getScope_ActionButtonMessage(context as ActionButton, reference) |
| // } |
| return super.getScope(context, reference) |
| } |
| |
| def getScope_ActionButtonCanExecute(ActionButton context, EReference reference) { |
| var parentScope = super.getScope(context, reference) |
| var result = <EObject>newArrayList |
| for(function : (context.group as FunctionLibraryGroup).functions) { |
| if (function.params == null || function.params.size == 0) { |
| var ofType = function.oftype.simpleName |
| if("boolean".equals(ofType)) { |
| result.add(function) |
| } |
| } |
| } |
| return Scopes::scopeFor(result, parentScope) |
| } |
| |
| def getScope_ActionButtonExecuteParameter(ActionButton context, EReference reference) { |
| var parentScope = super.getScope(context, reference) |
| var result = <EObject>newArrayList |
| for(function : (context.group as FunctionLibraryGroup).functions) { |
| if (function.params == null || function.params.size == 0) { |
| result.add(function) |
| } |
| } |
| return Scopes::scopeFor(result, parentScope) |
| } |
| |
| def getScope_ActionButtonMessage(ActionButton context, EReference reference) { |
| var parentScope = super.getScope(context, reference) |
| var elements = parentScope.allElements |
| for (element : elements){ |
| var elementname = element.name |
| println('''elementname: «elementname»''') |
| } |
| var result = <EObject>newArrayList |
| var message = (context.message as MessageItem) |
| var EObject eObj = message.eContainer |
| if (message != null) { |
| result.add(message) |
| } |
| return Scopes::scopeFor(result, parentScope) |
| } |
| |
| } |