diff options
author | Henrik Rentz-Reichert | 2019-08-16 08:52:40 +0000 |
---|---|---|
committer | Henrik Rentz-Reichert | 2019-08-16 13:01:53 +0000 |
commit | 5e3a5d12e1ef4618fb4677e1c7dc919f8c67ee70 (patch) | |
tree | 1a6d8b5421413e0d42c55b54b6510035bddc3785 | |
parent | 39770a85b966fb491193f45da4d743724b248c71 (diff) | |
download | org.eclipse.etrice-5e3a5d12e1ef4618fb4677e1c7dc919f8c67ee70.tar.gz org.eclipse.etrice-5e3a5d12e1ef4618fb4677e1c7dc919f8c67ee70.tar.xz org.eclipse.etrice-5e3a5d12e1ef4618fb4677e1c7dc919f8c67ee70.zip |
Bug 550141 - [room] improve implementation of scoping
Switched implementation to Xtend using polymorphic dispatching.
Change-Id: Ia328b2b4e8e996cd8c42c3c75cd057e1c998ad74
12 files changed, 338 insertions, 598 deletions
diff --git a/plugins/org.eclipse.etrice.core.genmodel/src/org/eclipse/etrice/core/genmodel/builder/Wiring.java b/plugins/org.eclipse.etrice.core.genmodel/src/org/eclipse/etrice/core/genmodel/builder/Wiring.java index e8cf70779..6c511eb9b 100644 --- a/plugins/org.eclipse.etrice.core.genmodel/src/org/eclipse/etrice/core/genmodel/builder/Wiring.java +++ b/plugins/org.eclipse.etrice.core.genmodel/src/org/eclipse/etrice/core/genmodel/builder/Wiring.java @@ -107,7 +107,7 @@ public class Wiring { rsize = ar.getMultiplicity(); } - ProtocolClass pc = roomHelpers.getProtocol(port); + ProtocolClass pc = roomHelpers.getRoomProtocol(port); boolean implicitMany = pc==null || pc.getCommType() == CommunicationType.DATA_DRIVEN; if (implicitMany) psize = -1; diff --git a/plugins/org.eclipse.etrice.core.room/META-INF/MANIFEST.MF b/plugins/org.eclipse.etrice.core.room/META-INF/MANIFEST.MF index 0fc9fa2b7..ebcdc7785 100644 --- a/plugins/org.eclipse.etrice.core.room/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.etrice.core.room/META-INF/MANIFEST.MF @@ -22,7 +22,8 @@ Require-Bundle: org.eclipse.etrice.core.common;bundle-version="2.0.0", org.eclipse.core.resources;bundle-version="3.7.100", org.eclipse.core.runtime;bundle-version="3.7.0", org.eclipse.etrice.core.genmodel.fsm;bundle-version="2.0.0", - org.eclipse.etrice.generator.base + org.eclipse.etrice.generator.base, + org.apache.commons.lang3;bundle-version="3.1.0" Import-Package: org.apache.log4j, org.eclipse.etrice.core.room Bundle-RequiredExecutionEnvironment: JavaSE-1.8 diff --git a/plugins/org.eclipse.etrice.core.room/build.gradle b/plugins/org.eclipse.etrice.core.room/build.gradle index 4a9ff8df0..db6367f5a 100644 --- a/plugins/org.eclipse.etrice.core.room/build.gradle +++ b/plugins/org.eclipse.etrice.core.room/build.gradle @@ -7,4 +7,7 @@ dependencies { compile "org.eclipse.xtend:org.eclipse.xtend.lib:$versions.xtext" compile "org.eclipse.platform:org.eclipse.core.runtime:$versions.core_runtime" compile "org.eclipse.xtext:org.eclipse.xtext:$versions.xtext" + + // https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 + compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.1' }
\ No newline at end of file diff --git a/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/room/util/RoomHelpers.java b/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/room/util/RoomHelpers.java index 901058f7d..e2f05dfdf 100644 --- a/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/room/util/RoomHelpers.java +++ b/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/room/util/RoomHelpers.java @@ -474,8 +474,8 @@ public class RoomHelpers extends FSMHelpers { * @return a list of all incoming {@link Message}s of this item */ public List<Message> getIncoming(InterfaceItem item) { - if (getProtocol(item)!=null) - return getAllMessages(getProtocol(item), !isConjugated(item)); + if (getRoomProtocol(item)!=null) + return getAllMessages(getRoomProtocol(item), !isConjugated(item)); else return Collections.emptyList(); } @@ -485,8 +485,8 @@ public class RoomHelpers extends FSMHelpers { * @return a list of all outgoing {@link Message}s of this item */ public List<Message> getOutgoing(InterfaceItem item) { - if (getProtocol(item)!=null) - return getAllMessages(getProtocol(item), isConjugated(item)); + if (getRoomProtocol(item)!=null) + return getAllMessages(getRoomProtocol(item), isConjugated(item)); else return Collections.emptyList(); } @@ -989,6 +989,21 @@ public class RoomHelpers extends FSMHelpers { return null; } + /** + * first container of type {@link StructureClass} + * @param obj + * @return StructureClass container + */ + public StructureClass getStructureClass(EObject obj) { + EObject ctx = obj.eContainer(); + while (!(ctx instanceof StructureClass) && ctx.eContainer() != null) + ctx = ctx.eContainer(); + if (ctx instanceof StructureClass) + return (StructureClass) ctx; + else + return null; + } + /** * @param obj an {@link EObject} * @return the {@link RoomClass} containing this object or null @@ -1334,7 +1349,7 @@ public class RoomHelpers extends FSMHelpers { * * @return the {@link ProtocolClass} of an {@link InterfaceItem} */ - public ProtocolClass getProtocol(InterfaceItem item) { + public ProtocolClass getRoomProtocol(InterfaceItem item) { GeneralProtocolClass pc = getGeneralProtocol(item); if (pc instanceof ProtocolClass) return (ProtocolClass) pc; @@ -1349,7 +1364,7 @@ public class RoomHelpers extends FSMHelpers { * @return {@code true} if the interface item is data driven (i.e. has a data driven {@link ProtocolClass} */ public boolean isDataDriven(InterfaceItem item) { - ProtocolClass pc = getProtocol(item); + ProtocolClass pc = getRoomProtocol(item); if (pc!=null && pc.getCommType()==CommunicationType.DATA_DRIVEN) return true; @@ -1507,6 +1522,21 @@ public class RoomHelpers extends FSMHelpers { return result; } + /** + * first container of type {@link ActorClass} + * @param obj + * @return ActorClass container + */ + public ActorContainerClass getActorContainerClass(EObject obj) { + EObject ctx = obj.eContainer(); + while (!(ctx instanceof ActorContainerClass) && ctx.eContainer() != null) + ctx = ctx.eContainer(); + if (ctx instanceof ActorContainerClass) + return (ActorContainerClass)ctx; + return + null; + } + /** * Returns a {@link RefPath} as string. * diff --git a/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/scoping/RoomScopeProvider.java b/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/scoping/RoomScopeProvider.java index 1e7b6c8ce..529945764 100644 --- a/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/scoping/RoomScopeProvider.java +++ b/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/scoping/RoomScopeProvider.java @@ -1,593 +1,28 @@ -/******************************************************************************* - * Copyright (c) 2010 protos software gmbh (http://www.protos.de). - * 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: - * Thomas Schuetz and Henrik Rentz-Reichert (initial contribution) - * - *******************************************************************************/ - +/* + * generated by Xtext + */ package org.eclipse.etrice.core.scoping; -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.List; - import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.EReference; -import org.eclipse.etrice.core.fsm.fSM.InSemanticsRule; -import org.eclipse.etrice.core.fsm.fSM.MessageFromIf; -import org.eclipse.etrice.core.fsm.fSM.OutSemanticsRule; -import org.eclipse.etrice.core.fsm.fSM.SemanticsRule; -import org.eclipse.etrice.core.fsm.scoping.FSMScopeProvider; -import org.eclipse.etrice.core.room.ActorClass; -import org.eclipse.etrice.core.room.ActorContainerClass; -import org.eclipse.etrice.core.room.ActorRef; -import org.eclipse.etrice.core.room.Binding; -import org.eclipse.etrice.core.room.BindingEndPoint; -import org.eclipse.etrice.core.room.CompoundProtocolClass; -import org.eclipse.etrice.core.room.ExternalPort; -import org.eclipse.etrice.core.room.InMessageHandler; -import org.eclipse.etrice.core.room.InterfaceItem; -import org.eclipse.etrice.core.room.LogicalSystem; -import org.eclipse.etrice.core.room.Message; -import org.eclipse.etrice.core.room.MessageHandler; -import org.eclipse.etrice.core.room.OutMessageHandler; -import org.eclipse.etrice.core.room.Port; -import org.eclipse.etrice.core.room.PortClass; -import org.eclipse.etrice.core.room.PortOperation; -import org.eclipse.etrice.core.room.ProtocolClass; -import org.eclipse.etrice.core.room.RefSAPoint; -import org.eclipse.etrice.core.room.RelaySAPoint; -import org.eclipse.etrice.core.room.SAP; -import org.eclipse.etrice.core.room.SPP; -import org.eclipse.etrice.core.room.SPPoint; -import org.eclipse.etrice.core.room.StructureClass; -import org.eclipse.etrice.core.room.SubProtocol; -import org.eclipse.etrice.core.room.SubSystemClass; -import org.eclipse.etrice.core.room.SubSystemRef; -import org.eclipse.etrice.core.room.util.RoomHelpers; -import org.eclipse.xtext.resource.EObjectDescription; -import org.eclipse.xtext.resource.IEObjectDescription; import org.eclipse.xtext.scoping.IScope; -import org.eclipse.xtext.scoping.impl.SimpleScope; import com.google.inject.Inject; - /** * This class contains custom scoping description. - * - * see : http://www.eclipse.org/Xtext/documentation/latest/xtext.html#scoping - * on how and when to use it - * + * + * See https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#scoping + * on how and when to use it. */ -public class RoomScopeProvider extends FSMScopeProvider { +public class RoomScopeProvider extends org.eclipse.etrice.core.fsm.scoping.FSMScopeProvider { @Inject - private RoomHelpers roomHelpers; - - /** - * first container of type {@link ActorClass} - * @param obj - * @return ActorClass container - */ - private ActorClass getActorClass(EObject obj) { - EObject ctx = obj.eContainer(); - while (!(ctx instanceof ActorClass) && ctx.eContainer()!=null) - ctx = ctx.eContainer(); - if (ctx instanceof ActorClass) - return (ActorClass) ctx; - - return null; - } - - /** - * first container of type {@link ActorClass} - * @param obj - * @return ActorClass container - */ - private ActorContainerClass getActorContainerClass(EObject obj) { - EObject ctx = obj.eContainer(); - while (!(ctx instanceof ActorContainerClass) && ctx.eContainer()!=null) - ctx = ctx.eContainer(); - if (ctx instanceof ActorContainerClass) - return (ActorContainerClass) ctx; - - return null; - } - - /** - * first container of type {@link StructureClass} - * @param obj - * @return StructureClass container - */ - private StructureClass getStructureClass(EObject obj) { - EObject ctx = obj.eContainer(); - while (!(ctx instanceof StructureClass) && ctx.eContainer()!=null) - ctx = ctx.eContainer(); - if (ctx instanceof StructureClass) - return (StructureClass) ctx; - - return null; - } - - /** - * return a list of base classes of an {@link ActorClass}, parent classes first. - * The list includes the class itself - * @param ac - * @return - */ - private LinkedList<ActorClass> getBaseClasses(ActorClass ac) { - LinkedList<ActorClass> classes = new LinkedList<ActorClass>(); - if (ac!=null) { - classes.addFirst(ac); - while (ac.getActorBase()!=null) { - if (ac==ac.getBase()) - // avoid endless loop - circularity in class hierarchy detected elsewhere - break; - - ac = ac.getActorBase(); - classes.addFirst(ac); - } - } - return classes; - } - - /** - * return a list of base classes of an {@link ProtocolClass}, parent classes first. - * The list includes the class itself - * @param pc - * @return - */ - private LinkedList<ProtocolClass> getBaseClasses(ProtocolClass pc) { - LinkedList<ProtocolClass> classes = new LinkedList<ProtocolClass>(); - classes.addFirst(pc); - while (pc.getBase()!=null) { - pc = pc.getBase(); - classes.addFirst(pc); - } - return classes; - } - - /** - * returns a flat list of Message scopes for a {@link MessageFromIf} - * @param mfi - the message from interface - * @param ref - not used - * @return a list of scopes - */ - public IScope scope_MessageFromIf_message(MessageFromIf mfi, EReference ref) { - final List<IEObjectDescription> scopes = new ArrayList<IEObjectDescription>(); - - InterfaceItem item = (InterfaceItem) mfi.getFrom(); - if (item!=null) { - ProtocolClass protocol = null; - boolean conjugated = false; - if (item instanceof Port && ((Port)item).getProtocol() instanceof ProtocolClass) { - protocol = (ProtocolClass) ((Port)item).getProtocol(); - conjugated = ((Port)item).isConjugated(); - } - else if (item instanceof SAP) { - protocol = ((SAP)item).getProtocol(); - conjugated = true; - } - else if (item instanceof SPP) { - protocol = ((SPP)item).getProtocol(); - conjugated = false; - } - - if (protocol!=null) - for (Message msg : conjugated?roomHelpers.getAllMessages(protocol,false):roomHelpers.getAllMessages(protocol,true)) { - scopes.add(EObjectDescription.create(msg.getName(), msg)); - } - } - - return new SimpleScope(IScope.NULLSCOPE, scopes); - } - - /** - * returns a flat list of Port scopes for a {@link MessageFromIf} - * @param mfi - the message from interface - * @param ref - not used - * @return a list of scopes - */ - public IScope scope_MessageFromIf_port(MessageFromIf mfi, EReference ref) { - final List<IEObjectDescription> scopes = new ArrayList<IEObjectDescription>(); - - ActorClass ac = getActorClass(mfi); - for (Port p : ac.getInternalPorts()) { - scopes.add(EObjectDescription.create(p.getName(), p)); - } - for (ExternalPort p : ac.getExternalPorts()) { - scopes.add(EObjectDescription.create(p.getInterfacePort().getName(), p.getInterfacePort())); - } - - return new SimpleScope(IScope.NULLSCOPE, scopes); - } - - /** - * returns a flat list of InterfaceItem scopes for a {@link MessageFromIf} - * @param mfi - the message from interface - * @param ref - not used - * @return a list of scopes - */ - public IScope scope_MessageFromIf_from(MessageFromIf mfi, EReference ref) { - final List<IEObjectDescription> scopes = new ArrayList<IEObjectDescription>(); - - ActorClass ac = getActorClass(mfi); - List<InterfaceItem> items = roomHelpers.getAllInterfaceItems(ac); - - for (InterfaceItem item : items) { - scopes.add(EObjectDescription.create(item.getName(), item)); - } - - return new SimpleScope(IScope.NULLSCOPE, scopes); - } - - /** - * returns a flat list of ActorRef scopes for a {@link BindingEndPoint} - * @param ep - the endpoint - * @param ref - not used - * @return a list of scopes - */ - public IScope scope_BindingEndPoint_actorRef(BindingEndPoint ep, EReference ref) { - final List<IEObjectDescription> scopes = new ArrayList<IEObjectDescription>(); - - StructureClass sc = getStructureClass(ep); - if (sc instanceof ActorClass) { - LinkedList<ActorClass> classes = getBaseClasses((ActorClass)sc); - for (ActorClass a : classes) { - for (ActorRef ar : a.getActorRefs()) { - scopes.add(EObjectDescription.create(ar.getName(), ar)); - } - } - } - else if (sc instanceof SubSystemClass){ - for (ActorRef ar : ((SubSystemClass) sc).getActorRefs()) { - scopes.add(EObjectDescription.create(ar.getName(), ar)); - } - } - else { - LogicalSystem ls = (LogicalSystem) sc; - for (SubSystemRef ssr : ls.getSubSystems()) { - scopes.add(EObjectDescription.create(ssr.getName(), ssr)); - } - } - - return new SimpleScope(IScope.NULLSCOPE, scopes); - } - - public IScope scope_BindingEndPoint_port(Binding bind, EReference ref) { - if(bind.getEndpoint1() != null){ - return scope_BindingEndPoint_port(bind.getEndpoint1(), ref); - } - - return IScope.NULLSCOPE; - } + private RoomScopeProviderDelegate delegate; - public IScope scope_BindingEndPoint_actorRef(Binding bind, EReference ref) { - if(bind.getEndpoint1() != null){ - return scope_BindingEndPoint_actorRef(bind.getEndpoint1(), ref); - } - - return IScope.NULLSCOPE; - } - - /** - * returns a flat list of Port scopes for a {@link BindingEndPoint} - * @param ep - the endpoint - * @param ref - not used - * @return a list of scopes - */ - public IScope scope_BindingEndPoint_port(BindingEndPoint ep, EReference ref) { - final List<IEObjectDescription> scopes = new ArrayList<IEObjectDescription>(); - - StructureClass sc = getStructureClass(ep); - - if (ep.getActorRef() == null){ - if (sc instanceof ActorClass) { - ActorClass ac = (ActorClass) sc; - // for all super classes (including this class) - LinkedList<ActorClass> classes = getBaseClasses(ac); - for (ActorClass a : classes) { - // collect internal and relay ports, i.e. - // structure ports not in interface (internal) - for (Port p : a.getInternalPorts()) { - scopes.add(EObjectDescription.create(p.getName(), p)); - } - // interface ports not in structure (relay) - for (Port p : a.getRelayPorts()) { - scopes.add(EObjectDescription.create(p.getName(), p)); - } - } - } - else if (sc instanceof SubSystemClass) { - SubSystemClass ssc = (SubSystemClass) sc; - for (Port p : ssc.getRelayPorts()) { - scopes.add(EObjectDescription.create(p.getName(), p)); - } - } - } - else { - // all ports in the sub actor's interface - if (ep.getActorRef() instanceof ActorRef) { - ActorClass ac = ((ActorRef)ep.getActorRef()).getType(); - LinkedList<ActorClass> classes = getBaseClasses(ac); - for (ActorClass a : classes) { - for (Port p : a.getInterfacePorts()) { - scopes.add(EObjectDescription.create(p.getName(), p)); - } - } - } - else { - SubSystemClass ssc = ((SubSystemRef)ep.getActorRef()).getType(); - for (Port p : ssc.getRelayPorts()) { - scopes.add(EObjectDescription.create(p.getName(), p)); - } - } - } - return new SimpleScope(IScope.NULLSCOPE, scopes); - } - - /** - * returns a flat list of SubProtocol scopes for a {@link BindingEndPoint} - * @param ep - the endpoint - * @param ref - not used - * @return a list of scopes - */ - public IScope scope_BindingEndPoint_sub(BindingEndPoint ep, EReference ref) { - final List<IEObjectDescription> scopes = new ArrayList<IEObjectDescription>(); - - if (ep.getPort()!=null) { - if (ep.getPort().getProtocol() instanceof CompoundProtocolClass) { - CompoundProtocolClass pc = (CompoundProtocolClass) ep.getPort().getProtocol(); - - for (SubProtocol sub : pc.getSubProtocols()) { - scopes.add(EObjectDescription.create(sub.getName(), sub)); - } - } - } - - return new SimpleScope(IScope.NULLSCOPE, scopes); - } - - /** - * returns a flat list of Message scopes for a {@link InSemanticsRule} - * @param sr - the semantics rule for incoming messages - * @param ref - not used - * @return a list of scopes - */ - public IScope scope_SemanticsRule_msg(SemanticsRule sr, EReference ref) { - final List<IEObjectDescription> scopes = new ArrayList<IEObjectDescription>(); - - ProtocolClass pc = roomHelpers.getProtocolClass(sr); - LinkedList<ProtocolClass> classes = getBaseClasses(pc); - for (ProtocolClass bpc : classes) { - if (sr instanceof InSemanticsRule) - for (Message m : bpc.getIncomingMessages()) { - scopes.add(EObjectDescription.create(m.getName(), m)); - } - if (sr instanceof OutSemanticsRule) - for (Message m : bpc.getOutgoingMessages()) { - scopes.add(EObjectDescription.create(m.getName(), m)); - } - } - - return new SimpleScope(IScope.NULLSCOPE, scopes); - } - - /** - * returns a flat list of ActorRef scopes for a {@link RefSAPoint} - * @param pt - * @param ref - * @return a list of scopes - */ - public IScope scope_RefSAPoint_ref(RefSAPoint pt, EReference ref) { - final List<IEObjectDescription> scopes = new ArrayList<IEObjectDescription>(); - - ActorContainerClass acc = getActorContainerClass(pt); - if (acc instanceof ActorClass) { - LinkedList<ActorClass> classes = getBaseClasses((ActorClass) acc); - for (ActorClass a : classes) { - for (ActorRef ar : a.getActorRefs()) { - scopes.add(EObjectDescription.create(ar.getName(), ar)); - } - } - } - else { - for (ActorRef ar : acc.getActorRefs()) { - scopes.add(EObjectDescription.create(ar.getName(), ar)); - } - } - - return new SimpleScope(IScope.NULLSCOPE, scopes); - } - - /** - * returns a flat list of SPP scopes for a {@link RelaySAPoint} - * @param pt - * @param ref - * @return a list of scopes - */ - public IScope scope_RelaySAPoint_relay(RelaySAPoint pt, EReference ref) { - final List<IEObjectDescription> scopes = new ArrayList<IEObjectDescription>(); - - ActorClass ac = getActorClass(pt); - LinkedList<ActorClass> classes = getBaseClasses(ac); - for (ActorClass a : classes) { - for (SPP spp : a.getServiceProvisionPoints()) { - scopes.add(EObjectDescription.create(spp.getName(), spp)); - } - } - - return new SimpleScope(IScope.NULLSCOPE, scopes); - } - - /** - * returns a flat list of ActorRef scopes for a {@link SPPoint} - * @param pt - * @param ref - * @return a list of scopes - */ - public IScope scope_SPPoint_actorRef(SPPoint pt, EReference ref) { - final List<IEObjectDescription> scopes = new ArrayList<IEObjectDescription>(); - - ActorContainerClass acc = getActorContainerClass(pt); - if (acc instanceof ActorClass) { - LinkedList<ActorClass> classes = getBaseClasses((ActorClass)acc); - for (ActorClass a : classes) { - for (ActorRef ar : a.getActorRefs()) { - scopes.add(EObjectDescription.create(ar.getName(), ar)); - } - } - } - else { - for (ActorRef ar : acc.getActorRefs()) { - scopes.add(EObjectDescription.create(ar.getName(), ar)); - } - } - - return new SimpleScope(IScope.NULLSCOPE, scopes); - } - - /** - * returns a flat list of SPP scopes for a {@link SPPoint} - * @param pt - * @param ref - * @return a list of scopes - */ - public IScope scope_SPPoint_service(SPPoint pt, EReference ref) { - final List<IEObjectDescription> scopes = new ArrayList<IEObjectDescription>(); - - if (pt.getRef()!=null) { - if (pt.getRef() instanceof ActorRef) { - ActorClass ac = ((ActorRef)pt.getRef()).getType(); - LinkedList<ActorClass> classes = getBaseClasses(ac); - for (ActorClass a : classes) { - for (SPP spp : a.getServiceProvisionPoints()) { - scopes.add(EObjectDescription.create(spp.getName(), spp)); - } - } - } - else if (pt.getRef() instanceof SubSystemRef) { - SubSystemClass ssc = ((SubSystemRef)pt.getRef()).getType(); - for (SPP spp : ssc.getServiceProvisionPoints()) { - scopes.add(EObjectDescription.create(spp.getName(), spp)); - } - } - } - - return new SimpleScope(IScope.NULLSCOPE, scopes); - } - - public IScope scope_MessageHandler_msg(MessageHandler handler, EReference ref) { - final List<IEObjectDescription> scopes = new ArrayList<IEObjectDescription>(); - - ProtocolClass pc = roomHelpers.getProtocolClass(handler); - if (pc!=null) { - if (handler instanceof InMessageHandler) - for (Message m : pc.getIncomingMessages()) { - scopes.add(EObjectDescription.create(m.getName(), m)); - } - if (handler instanceof OutMessageHandler) - for (Message m : pc.getOutgoingMessages()) { - scopes.add(EObjectDescription.create(m.getName(), m)); - } - } - - return new SimpleScope(IScope.NULLSCOPE, scopes); - } - - public IScope scope_PortOperation_sendsMsg(PortOperation op, EReference ref) { - final List<IEObjectDescription> scopes = new ArrayList<IEObjectDescription>(); - - PortClass pcls = (PortClass) op.eContainer(); - ProtocolClass pc = roomHelpers.getProtocolClass(op); - if (pc!=null) { - if (pcls==pc.getConjugated()) - for (Message m : pc.getIncomingMessages()) { - scopes.add(EObjectDescription.create(m.getName(), m)); - } - else - for (Message m : pc.getOutgoingMessages()) { - scopes.add(EObjectDescription.create(m.getName(), m)); - } - } - - return new SimpleScope(IScope.NULLSCOPE, scopes); - } - - /* - * we prefer loose scoping here and rely on validation for meaningful error messages - * - * returns a flat list of ActorClass scopes for a {@link ActorRef} - * @param ar - the actor reference - * @param ref - not used - * @return a list of scopes - */ -// public IScope scope_ActorRef_type(ActorRef ar, EReference ref) { -// ActorClass ac = getActorClass(ar); -// IScope scope = delegateGetScope(ar, ref); -// return new FilteringScope(scope, new ActorRefFilter(ac)); -// } - - /** - * returns a flat list of Port scopes for a {@link ExternalPort} - * @param ep - the external port - * @param ref - not used - * @return a list of scopes - */ - public IScope scope_ExternalPort_interfacePort(ExternalPort ep, EReference ref) { - final List<IEObjectDescription> scopes = new ArrayList<IEObjectDescription>(); - - ActorClass ac = getActorClass(ep); - for (Port ip : ac.getInterfacePorts()) { - scopes.add(EObjectDescription.create(ip.getName(), ip)); - } - - return new SimpleScope(IScope.NULLSCOPE, scopes); - } - /** - * returns a flat list of Port scopes for a {@link ExternalPort} - * @param ar - the external port - * @param ref - not used - * @return a list of scopes - */ -// public IScope scope_ActorInstance_segments(ActorInstance ai, EReference ref) { -// final List<IEObjectDescription> scopes = new ArrayList<IEObjectDescription>(); -// -// if (ai.getSegments().isEmpty()) { -// // context is my ActorContainerClass -// ActorContainerClass acc = getActorContainerClass(ai); -// for (ActorRef ar : acc.getActorRefs()) { -// scopes.add(EObjectDescription.create(ar.getName(), ar)); -// } -// } -// else { -// // context is actor class of last segment -// ActorClass ac = ai.getSegments().get(ai.getSegments().size()-1).getType(); -// for (ActorRef ar : ac.getActorRefs()) { -// scopes.add(EObjectDescription.create(ar.getName(), ar)); -// } -// } -// -// return new SimpleScope(IScope.NULLSCOPE, scopes); -// } - - /* - public IScope scope_ChoicePointCaseRef_case(ChoicePointCaseRef cr, EReference ref) { - final List<IEObjectDescription> scopes = new ArrayList<IEObjectDescription>(); - - if (cr.getCp()!=null) { - for (ChoicePointCase cas : cr.getCp().getCases()) { - scopes.add(EObjectDescription.create(cas.getName(), cas)); - } - } - return new SimpleScope(IScope.NULLSCOPE, scopes); - }*/ + @Override + public IScope getScope(EObject context, EReference reference) { + IScope scope = delegate.getScope(context, reference); + return scope!=null ? scope : super.getScope(context, reference); + } } diff --git a/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/scoping/RoomScopeProviderDelegate.xtend b/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/scoping/RoomScopeProviderDelegate.xtend new file mode 100644 index 000000000..a6b4bddc6 --- /dev/null +++ b/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/scoping/RoomScopeProviderDelegate.xtend @@ -0,0 +1,271 @@ +package org.eclipse.etrice.core.scoping + +import com.google.inject.Inject +import java.util.Collections +import org.apache.commons.lang3.tuple.MutablePair +import org.eclipse.emf.ecore.EObject +import org.eclipse.emf.ecore.EReference +import org.eclipse.etrice.core.fsm.fSM.FSMPackage +import org.eclipse.etrice.core.fsm.fSM.InSemanticsRule +import org.eclipse.etrice.core.fsm.fSM.MessageFromIf +import org.eclipse.etrice.core.fsm.fSM.OutSemanticsRule +import org.eclipse.etrice.core.fsm.fSM.SemanticsRule +import org.eclipse.etrice.core.room.ActorClass +import org.eclipse.etrice.core.room.ActorRef +import org.eclipse.etrice.core.room.BindingEndPoint +import org.eclipse.etrice.core.room.CompoundProtocolClass +import org.eclipse.etrice.core.room.ExternalPort +import org.eclipse.etrice.core.room.InMessageHandler +import org.eclipse.etrice.core.room.InterfaceItem +import org.eclipse.etrice.core.room.LogicalSystem +import org.eclipse.etrice.core.room.MessageHandler +import org.eclipse.etrice.core.room.OutMessageHandler +import org.eclipse.etrice.core.room.Port +import org.eclipse.etrice.core.room.PortClass +import org.eclipse.etrice.core.room.PortOperation +import org.eclipse.etrice.core.room.ProtocolClass +import org.eclipse.etrice.core.room.RefSAPoint +import org.eclipse.etrice.core.room.RelaySAPoint +import org.eclipse.etrice.core.room.RoomPackage +import org.eclipse.etrice.core.room.SAP +import org.eclipse.etrice.core.room.SPP +import org.eclipse.etrice.core.room.SPPoint +import org.eclipse.etrice.core.room.SubSystemClass +import org.eclipse.etrice.core.room.SubSystemRef +import org.eclipse.etrice.core.room.util.RoomHelpers +import org.eclipse.xtext.resource.EObjectDescription +import org.eclipse.xtext.resource.IEObjectDescription +import org.eclipse.xtext.scoping.IScope +import org.eclipse.xtext.scoping.impl.SimpleScope + +class RoomScopeProviderDelegate { + + @Inject + extension RoomHelpers + + def getScope(EObject context, EReference reference) { + context.scopeFor(reference) + } + + // the fall back method delegates to super + protected def dispatch IScope scopeFor(EObject obj, EReference ref) { + null + } + + protected def dispatch IScope scopeFor(MessageFromIf mfi, EReference ref) { + switch (ref) { + case FSMPackage.Literals.MESSAGE_FROM_IF__MESSAGE: { + // returns a flat list of Message scopes for a {@link MessageFromIf} + val InterfaceItem item = (mfi.from as InterfaceItem) + if (item !== null) { + val directedProtocol = new MutablePair => [ + // left is the protocol + // right is the conjugated or not + if (item instanceof Port && item.generalProtocol instanceof ProtocolClass) { + left = item.generalProtocol as ProtocolClass + right = item.conjugated + } else if (item instanceof SAP) { + left = item.protocol + right = true + } else if (item instanceof SPP) { + left = item.protocol + right = false + } + ] + if (directedProtocol.left !== null) { + return getAllMessages(directedProtocol.left, !directedProtocol.right).map[EObjectDescription.create(name, it)].toSimpleScope + } + } + } + /* + * TODO: this was scope_MessageFromIf_port + case FSMPackage.Literals.MESSAGE_FROM_IF__FROM: { + // returns a flat list of Port scopes for a {@link MessageFromIf} + val ActorClass ac=getActorClass(mfi) + for (Port p : ac.getInternalPorts()) { + scopes.add(EObjectDescription.create(p.getName(), p)) + } + for (ExternalPort p : ac.getExternalPorts()) { + scopes.add(EObjectDescription.create(p.getInterfacePort().getName(), p.getInterfacePort())) + } + } + */ + case FSMPackage.Literals.MESSAGE_FROM_IF__FROM: { + // returns a flat list of InterfaceItem scopes for a {@link MessageFromIf} + return getAllInterfaceItems(mfi.actorClass).map[EObjectDescription.create(name, it)].toSimpleScope + } + } + return emptyScope + } + + protected def dispatch IScope scopeFor(BindingEndPoint ep, EReference ref) { + switch (ref) { + case RoomPackage.Literals.BINDING_END_POINT__ACTOR_REF: { + // returns a flat list of ActorRef scopes for a {@link BindingEndPoint} + val sc = ep.structureClass + switch (sc) { + ActorClass: + return sc.classHierarchy.flatMap[actorRefs].map[EObjectDescription.create(name, it)].toSimpleScope + SubSystemClass: + return sc.actorRefs.map[EObjectDescription.create(name, it)].toSimpleScope + LogicalSystem: + return sc.subSystems.map[EObjectDescription.create(name, it)].toSimpleScope + } + } + case RoomPackage.Literals.BINDING_END_POINT__PORT: { + // returns a flat list of Port scopes for a {@link BindingEndPoint} + if (ep.actorRef === null) { + val sc = ep.structureClass + if (sc instanceof ActorClass) { + // for all super classes (including this class) + // collect internal and relay ports, i.e. + // structure ports not in interface (internal) + // interface ports not in structure (relay) + return sc + .classHierarchy + .map[(internalPorts + relayPorts) + .map[EObjectDescription.create(name, it)] + ] + .flatten.toSimpleScope + } else if (sc instanceof SubSystemClass) { + return sc.relayPorts.map[EObjectDescription.create(name, it)].toSimpleScope + } + } else { + // all ports in the sub actor's interface + val epref = ep.actorRef + switch (epref) { + ActorRef: + return epref.type.classHierarchy.flatMap[interfacePorts].map[EObjectDescription.create(name, it)].toSimpleScope + SubSystemRef: + return epref.type.relayPorts.map[EObjectDescription.create(name, it)].toSimpleScope + } + } + } + case RoomPackage.Literals.BINDING_END_POINT__SUB: { + // returns a flat list of SubProtocol scopes for a {@link BindingEndPoint} + if (ep.port !== null) { + if (ep.port.protocol instanceof CompoundProtocolClass) { + val pc = (ep.port.protocol as CompoundProtocolClass) + return pc.subProtocols.map[EObjectDescription.create(name, it)].toSimpleScope + } + } + } + } + return emptyScope + } + + /** + * returns a flat list of Message scopes for a {@link InSemanticsRule} + * @param sr - the semantics rule for incoming messages + * @param ref - not used + * @return a list of scopes + */ + protected def dispatch IScope scopeFor(SemanticsRule sr, EReference ref) { + val pc = sr.protocolClass + if (sr instanceof InSemanticsRule) { + return pc.classHierarchy.flatMap[incomingMessages].map[EObjectDescription.create(name, it)].toSimpleScope + } + else if (sr instanceof OutSemanticsRule) { + return pc.classHierarchy.flatMap[outgoingMessages].map[EObjectDescription.create(name, it)].toSimpleScope + } + return emptyScope + } + + /** + * returns a flat list of ActorRef scopes for a {@link RefSAPoint} + * @param pt + * @param ref + * @return a list of scopes + */ + protected def dispatch IScope scopeFor(RefSAPoint pt, EReference ref) { + val acc = pt.actorContainerClass + if (acc instanceof ActorClass) { + return acc.classHierarchy.flatMap[actorRefs].map[EObjectDescription.create(name, it)].toSimpleScope + } + else { + return acc.actorRefs.map[EObjectDescription.create(name, it)].toSimpleScope + } + } + + /** + * returns a flat list of SPP scopes for a {@link RelaySAPoint} + * @param pt + * @param ref + * @return a list of scopes + */ + protected def dispatch IScope scopeFor(RelaySAPoint pt, EReference ref) { + if (ref==RoomPackage.Literals.RELAY_SA_POINT__RELAY) { + return pt.actorClass.classHierarchy.flatMap[serviceProvisionPoints].map[EObjectDescription.create(name, it)].toSimpleScope + } + + return emptyScope + } + + protected def dispatch IScope scopeFor(SPPoint pt, EReference ref) { + switch (ref) { + case RoomPackage.Literals.SP_POINT__REF: { + // returns a flat list of ActorRef scopes for a {@link SPPoint} + val acc = pt.actorContainerClass + if (acc instanceof ActorClass) { + return acc.classHierarchy.flatMap[actorRefs].map[EObjectDescription.create(name, it)].toSimpleScope + } + else { + return acc.actorRefs.map[EObjectDescription.create(name, it)].toSimpleScope + } + } + case RoomPackage.Literals.SP_POINT__SERVICE: { + val sppref = pt.ref + if (sppref instanceof ActorRef) { + return sppref.type.classHierarchy.flatMap[serviceProvisionPoints].map[EObjectDescription.create(name, it)].toSimpleScope + } else if (sppref instanceof SubSystemRef) { + return sppref.type.serviceProvisionPoints.map[EObjectDescription.create(name, it)].toSimpleScope + } + } + } + return emptyScope + } + + protected def dispatch IScope scopeFor(MessageHandler handler, EReference ref) { + if (ref==RoomPackage.Literals.MESSAGE_HANDLER__MSG) { + val pc = handler.protocolClass + if (pc !== null) { + if (handler instanceof InMessageHandler) + return pc.incomingMessages.map[EObjectDescription.create(name, it)].toSimpleScope + else if (handler instanceof OutMessageHandler) + return pc.outgoingMessages.map[EObjectDescription.create(name, it)].toSimpleScope + } + } + + return emptyScope + } + + protected def dispatch IScope scopeFor(PortOperation op, EReference ref) { + val pcls = op.eContainer() as PortClass + val pc = op.protocolClass + if (pc !== null) { + if (pcls === pc.getConjugated()) { + return pc.incomingMessages.map[EObjectDescription.create(name, it)].toSimpleScope + } + else { + return pc.outgoingMessages.map[EObjectDescription.create(name, it)].toSimpleScope + } + } + return emptyScope + } + + protected def dispatch IScope scopeFor(ExternalPort ep, EReference ref) { + ep.actorClass.interfacePorts.map[EObjectDescription.create(name, it)].toSimpleScope + } + + /* + * two helper methods for scopes + */ + + protected def toSimpleScope(Iterable<IEObjectDescription> scopes) { + new SimpleScope(IScope.NULLSCOPE, scopes) + } + + protected def emptyScope() { + new SimpleScope(IScope.NULLSCOPE, Collections.emptyList) + } +} diff --git a/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/validation/RoomJavaValidator.java b/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/validation/RoomJavaValidator.java index 1e006c8ad..0324ea382 100644 --- a/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/validation/RoomJavaValidator.java +++ b/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/validation/RoomJavaValidator.java @@ -495,7 +495,7 @@ public class RoomJavaValidator extends AbstractRoomJavaValidator { //boolean synchronous = ac.getCommType() == ComponentCommunicationType.SYNCHRONOUS; for(InterfaceItem item : items){ - ProtocolClass pc = roomHelpers.getProtocol(item); + ProtocolClass pc = roomHelpers.getRoomProtocol(item); if (pc!=null) switch(pc.getCommType()){ case DATA_DRIVEN: @@ -679,7 +679,7 @@ public class RoomJavaValidator extends AbstractRoomJavaValidator { @Check public void checkMessageFromIf(MessageFromIf mfi){ if (mfi.getFrom() != null){ - ProtocolClass protocol = roomHelpers.getProtocol((InterfaceItem)mfi.getFrom()); + ProtocolClass protocol = roomHelpers.getRoomProtocol((InterfaceItem)mfi.getFrom()); if (protocol!=null && !protocol.eIsProxy()) { if (protocol.getCommType() != CommunicationType.EVENT_DRIVEN) error("port must have event driven protocol", mfi, FSMPackage.eINSTANCE.getMessageFromIf_From()); diff --git a/plugins/org.eclipse.etrice.dctools/src/org/eclipse/etrice/dctools/ast/DCLinker.xtend b/plugins/org.eclipse.etrice.dctools/src/org/eclipse/etrice/dctools/ast/DCLinker.xtend index 5f34c9683..7e81e56d4 100644 --- a/plugins/org.eclipse.etrice.dctools/src/org/eclipse/etrice/dctools/ast/DCLinker.xtend +++ b/plugins/org.eclipse.etrice.dctools/src/org/eclipse/etrice/dctools/ast/DCLinker.xtend @@ -250,14 +250,14 @@ class DCLinker implements IDCAstNodeVisitor { protected def void getCandidates(InterfaceItem ifItem, CandidateMap candidates) { // operations - ifItem.protocol.getAllOperations(!ifItem.conjugated).forEach[candidates.put(it.name, it)] + ifItem.roomProtocol.getAllOperations(!ifItem.conjugated).forEach[candidates.put(it.name, it)] // messages switch reference { case CP_BRANCH_TRANSITION__CONDITION, case GUARDED_TRANSITION__GUARD, case GUARD__GUARD: { - val pc = ifItem.protocol + val pc = ifItem.roomProtocol switch pc?.commType { case DATA_DRIVEN: if (!ifItem.conjugated) pc.allIncomingMessages.forEach[candidates.put(it.name, it)] @@ -266,7 +266,7 @@ class DCLinker implements IDCAstNodeVisitor { } } case owner.getContainerOfType(StateGraphItem)!==null: { - val pc = ifItem.protocol + val pc = ifItem.roomProtocol switch pc?.commType { case EVENT_DRIVEN: pc.getAllMessages(ifItem.conjugated).forEach[candidates.put(it.name, it)] diff --git a/plugins/org.eclipse.etrice.expressions.ui/src/org/eclipse/etrice/expressions/detailcode/DetailExpressionProvider.xtend b/plugins/org.eclipse.etrice.expressions.ui/src/org/eclipse/etrice/expressions/detailcode/DetailExpressionProvider.xtend index e48fb50d2..6ea712082 100644 --- a/plugins/org.eclipse.etrice.expressions.ui/src/org/eclipse/etrice/expressions/detailcode/DetailExpressionProvider.xtend +++ b/plugins/org.eclipse.etrice.expressions.ui/src/org/eclipse/etrice/expressions/detailcode/DetailExpressionProvider.xtend @@ -165,7 +165,7 @@ class DetailExpressionProvider implements IDetailExpressionProvider { // everything that contains RefableType val refableContainers = switch cls { ActorClass: - cls.allInterfaceItems.map[protocol].filterNull.toHashSet.map[classHierarchy].flatten + cls.attributes + cls.operations + cls.allInterfaceItems.map[roomProtocol].filterNull.toHashSet.map[classHierarchy].flatten + cls.attributes + cls.operations ProtocolClass: #[cls] + cls.classHierarchy DataClass: @@ -231,7 +231,7 @@ class DetailExpressionProvider implements IDetailExpressionProvider { switch obj : ctx.data { Port case obj.multiplicity == 1/* fall through */, - SAP: scope += obj.protocol.getAllOperations(!obj.conjugated).map[createExprFeature] + SAP: scope += obj.roomProtocol.getAllOperations(!obj.conjugated).map[createExprFeature] } switch obj : ctx.data { InterfaceItem: @@ -266,7 +266,7 @@ class DetailExpressionProvider implements IDetailExpressionProvider { case CP_BRANCH_TRANSITION__CONDITION, case GUARDED_TRANSITION__GUARD, case GUARD__GUARD: { - val pc = ifItem.protocol + val pc = ifItem.roomProtocol switch pc?.commType { case DATA_DRIVEN: if (!ifItem.conjugated) scope += pc.allIncomingMessages.map[createExprFeature] @@ -275,7 +275,7 @@ class DetailExpressionProvider implements IDetailExpressionProvider { } } case owner.isInContainment(StateGraphItem): { - val pc = ifItem.protocol + val pc = ifItem.roomProtocol switch pc?.commType { case EVENT_DRIVEN: scope += pc.getAllMessages(ifItem.conjugated).map[createExprFeature] diff --git a/plugins/org.eclipse.etrice.expressions.ui/src/org/eclipse/etrice/expressions/ui/contentassist/DetailExpressionProposalConfig.xtend b/plugins/org.eclipse.etrice.expressions.ui/src/org/eclipse/etrice/expressions/ui/contentassist/DetailExpressionProposalConfig.xtend index cd477f60b..48c27afce 100644 --- a/plugins/org.eclipse.etrice.expressions.ui/src/org/eclipse/etrice/expressions/ui/contentassist/DetailExpressionProposalConfig.xtend +++ b/plugins/org.eclipse.etrice.expressions.ui/src/org/eclipse/etrice/expressions/ui/contentassist/DetailExpressionProposalConfig.xtend @@ -102,7 +102,7 @@ class DetailExpressionProposalConfig{ Attribute: typedInfo = data?.type?.type?.name InterfaceItem: - typedInfo = roomHelpers.getProtocol(data)?.name + typedInfo = roomHelpers.getRoomProtocol(data)?.name // RuntimeMethodExpressionData case feature.id == RuntimeDetailExpressionProvider.RT_METHOD_GET_REPLICATION: // typedInfo = 'int' VarDecl: { diff --git a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/dialogs/PortMessageSelectionDialog.java b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/dialogs/PortMessageSelectionDialog.java index dec8856f6..d27e685c6 100644 --- a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/dialogs/PortMessageSelectionDialog.java +++ b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/dialogs/PortMessageSelectionDialog.java @@ -117,7 +117,7 @@ public class PortMessageSelectionDialog extends FormDialog implements ISelection pairs.add(new MsgItemPair(item, msg, true)); } } - if (roomHelpers.getProtocol(item).getCommType()==CommunicationType.DATA_DRIVEN) { + if (roomHelpers.getRoomProtocol(item).getCommType()==CommunicationType.DATA_DRIVEN) { List<Message> in = roomHelpers.getMessageListDeep(item, false); for (Message msg : in) { if (!msg.isPriv()) diff --git a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/dialogs/TransitionPropertyDialog.java b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/dialogs/TransitionPropertyDialog.java index 2108cfb8e..51f11bf16 100644 --- a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/dialogs/TransitionPropertyDialog.java +++ b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/dialogs/TransitionPropertyDialog.java @@ -128,7 +128,7 @@ public class TransitionPropertyDialog extends AbstractMemberAwarePropertyDialog RoomHelpers roomHelpers = SupportUtil.getInstance().getRoomHelpers(); for(InterfaceItem item : roomHelpers.getAllInterfaceItems(ac)){ - ProtocolClass pc = roomHelpers.getProtocol(item); + ProtocolClass pc = roomHelpers.getRoomProtocol(item); if(pc != null && pc.getCommType() == CommunicationType.EVENT_DRIVEN) interfaceItems.add(item); } |