Added filtering to textual syntax for content-assist

Change-Id: I93cc2f6dd7fbbcd8d4187e53441be344dec11e6a
Signed-off-by: Ernesto Posse <eposse@gmail.com>
diff --git a/models/samples/ComputerSystem/expected_src/CMakeLists.txt b/models/samples/ComputerSystem/expected_src/CMakeLists.txt
index dd281e1..71cb2da 100644
--- a/models/samples/ComputerSystem/expected_src/CMakeLists.txt
+++ b/models/samples/ComputerSystem/expected_src/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Generated 2016-08-30 09:40:58
+# Generated 2016-08-31 13:17:35
 
 cmake_minimum_required(VERSION 2.8.7)
 set(TARGET TopMain)
@@ -17,7 +17,7 @@
 include(${UMLRTS_ROOT}/build/buildenv.cmake)
 
 # model sources
-set(SRCS TopMain.cc Computer.cc Resource.cc ResourceManager.cc WordProcessorApp.cc USBProtocol.cc AppControl.cc User.cc USBDeviceDriver.cc USBStorageDriver.cc USBPrinterDriver.cc Application.cc LocalPrinter.cc ExtMassStorage.cc OSCommand.cc ComputerSystem.cc Top.cc TopControllers.cc )
+set(SRCS TopMain.cc Computer.cc Resource.cc ResourceManager.cc WordProcessorApp.cc USBProtocol.cc USBDeviceDriver.cc USBPrinterDriver.cc USBStorageDriver.cc LocalPrinter.cc ExtMassStorage.cc AppControl.cc User.cc Application.cc OSCommand.cc ComputerSystem.cc Top.cc TopControllers.cc )
 
 # specify target
 add_executable(${TARGET} ${SRCS})
diff --git a/models/samples/ComputerSystem/expected_src/ExtMassStorage.cc b/models/samples/ComputerSystem/expected_src/ExtMassStorage.cc
index beea3f7..2560094 100644
--- a/models/samples/ComputerSystem/expected_src/ExtMassStorage.cc
+++ b/models/samples/ComputerSystem/expected_src/ExtMassStorage.cc
@@ -13,10 +13,10 @@
 
 Capsule_ExtMassStorage::Capsule_ExtMassStorage( const UMLRTCapsuleClass * cd, UMLRTSlot * st, const UMLRTCommsPort * * border, const UMLRTCommsPort * * internal, bool isStat )
 : UMLRTCapsule( NULL, cd, st, border, internal, isStat )
-, currentState( SPECIAL_INTERNAL_STATE_UNVISITED )
 , usbPort( borderPorts[borderport_usbPort] )
 , usbClass( MassStorage )
 , savingData( false )
+, currentState( SPECIAL_INTERNAL_STATE_UNVISITED )
 {
     stateNames[Connected] = "Connected";
     stateNames[Disconnected] = "Disconnected";
@@ -24,6 +24,37 @@
 }
 
 
+
+
+
+
+void Capsule_ExtMassStorage::bindPort( bool isBorder, int portId, int index )
+{
+    if( isBorder )
+        switch( portId )
+        {
+        case borderport_usbPort:
+            UMLRTFrameService::sendBoundUnbound( borderPorts, borderport_usbPort, index, true );
+            break;
+        }
+}
+
+void Capsule_ExtMassStorage::unbindPort( bool isBorder, int portId, int index )
+{
+    if( isBorder )
+        switch( portId )
+        {
+        case borderport_usbPort:
+            UMLRTFrameService::sendBoundUnbound( borderPorts, borderport_usbPort, index, false );
+            UMLRTFrameService::disconnectPort( borderPorts[borderport_usbPort], index );
+            break;
+        }
+}
+
+
+
+
+
 void Capsule_ExtMassStorage::inject( const UMLRTMessage & message )
 {
     msg = &message;
@@ -308,37 +339,6 @@
 }
 
 
-
-
-
-void Capsule_ExtMassStorage::bindPort( bool isBorder, int portId, int index )
-{
-    if( isBorder )
-        switch( portId )
-        {
-        case borderport_usbPort:
-            UMLRTFrameService::sendBoundUnbound( borderPorts, borderport_usbPort, index, true );
-            break;
-        }
-}
-
-void Capsule_ExtMassStorage::unbindPort( bool isBorder, int portId, int index )
-{
-    if( isBorder )
-        switch( portId )
-        {
-        case borderport_usbPort:
-            UMLRTFrameService::sendBoundUnbound( borderPorts, borderport_usbPort, index, false );
-            UMLRTFrameService::disconnectPort( borderPorts[borderport_usbPort], index );
-            break;
-        }
-}
-
-
-
-
-
-
 static const UMLRTCommsPortRole portroles_border[] = 
 {
     {
diff --git a/models/samples/ComputerSystem/expected_src/ExtMassStorage.hh b/models/samples/ComputerSystem/expected_src/ExtMassStorage.hh
index 4ba6f88..615167a 100644
--- a/models/samples/ComputerSystem/expected_src/ExtMassStorage.hh
+++ b/models/samples/ComputerSystem/expected_src/ExtMassStorage.hh
@@ -19,11 +19,31 @@
 {
 public:
     Capsule_ExtMassStorage( const UMLRTCapsuleClass * cd, UMLRTSlot * st, const UMLRTCommsPort * * border, const UMLRTCommsPort * * internal, bool isStat );
+protected:
+    UMLRTLogProtocol_baserole log;
+    USBProtocol::Base usbPort;
+public:
+    enum BorderPortId
+    {
+        borderport_usbPort,
+        borderport_log
+    };
+    enum PartId
+    {
+    };
     enum PortId
     {
         port_log,
         port_usbPort
     };
+    virtual void bindPort( bool isBorder, int portId, int index );
+    virtual void unbindPort( bool isBorder, int portId, int index );
+protected:
+    USBDeviceClasses usbClass;
+    bool connectionStatus;
+    bool savingData;
+    long lineCount;
+public:
     virtual void inject( const UMLRTMessage & message );
     virtual void initialize( const UMLRTMessage & message );
     const char * getCurrentStateString() const;
@@ -56,25 +76,6 @@
     State choice_____connected_( const UMLRTMessage * msg );
     State state_____Connected( const UMLRTMessage * msg );
     State state_____Disconnected( const UMLRTMessage * msg );
-protected:
-    UMLRTLogProtocol_baserole log;
-    USBProtocol::Base usbPort;
-public:
-    enum BorderPortId
-    {
-        borderport_usbPort,
-        borderport_log
-    };
-    enum PartId
-    {
-    };
-    virtual void bindPort( bool isBorder, int portId, int index );
-    virtual void unbindPort( bool isBorder, int portId, int index );
-protected:
-    USBDeviceClasses usbClass;
-    bool connectionStatus;
-    bool savingData;
-    long lineCount;
 };
 extern const UMLRTCapsuleClass ExtMassStorage;
 
diff --git a/models/samples/ComputerSystem/expected_src/LocalPrinter.cc b/models/samples/ComputerSystem/expected_src/LocalPrinter.cc
index aee01e2..2644275 100644
--- a/models/samples/ComputerSystem/expected_src/LocalPrinter.cc
+++ b/models/samples/ComputerSystem/expected_src/LocalPrinter.cc
@@ -13,10 +13,10 @@
 
 Capsule_LocalPrinter::Capsule_LocalPrinter( const UMLRTCapsuleClass * cd, UMLRTSlot * st, const UMLRTCommsPort * * border, const UMLRTCommsPort * * internal, bool isStat )
 : UMLRTCapsule( NULL, cd, st, border, internal, isStat )
-, currentState( SPECIAL_INTERNAL_STATE_UNVISITED )
 , usbPort( borderPorts[borderport_usbPort] )
 , usbClass( Printer )
 , printingData( false )
+, currentState( SPECIAL_INTERNAL_STATE_UNVISITED )
 {
     stateNames[Connected] = "Connected";
     stateNames[Disconnected] = "Disconnected";
@@ -24,6 +24,36 @@
 }
 
 
+
+
+
+
+void Capsule_LocalPrinter::bindPort( bool isBorder, int portId, int index )
+{
+    if( isBorder )
+        switch( portId )
+        {
+        case borderport_usbPort:
+            UMLRTFrameService::sendBoundUnbound( borderPorts, borderport_usbPort, index, true );
+            break;
+        }
+}
+
+void Capsule_LocalPrinter::unbindPort( bool isBorder, int portId, int index )
+{
+    if( isBorder )
+        switch( portId )
+        {
+        case borderport_usbPort:
+            UMLRTFrameService::sendBoundUnbound( borderPorts, borderport_usbPort, index, false );
+            UMLRTFrameService::disconnectPort( borderPorts[borderport_usbPort], index );
+            break;
+        }
+}
+
+
+
+
 void Capsule_LocalPrinter::inject( const UMLRTMessage & message )
 {
     msg = &message;
@@ -301,36 +331,6 @@
 }
 
 
-
-
-
-void Capsule_LocalPrinter::bindPort( bool isBorder, int portId, int index )
-{
-    if( isBorder )
-        switch( portId )
-        {
-        case borderport_usbPort:
-            UMLRTFrameService::sendBoundUnbound( borderPorts, borderport_usbPort, index, true );
-            break;
-        }
-}
-
-void Capsule_LocalPrinter::unbindPort( bool isBorder, int portId, int index )
-{
-    if( isBorder )
-        switch( portId )
-        {
-        case borderport_usbPort:
-            UMLRTFrameService::sendBoundUnbound( borderPorts, borderport_usbPort, index, false );
-            UMLRTFrameService::disconnectPort( borderPorts[borderport_usbPort], index );
-            break;
-        }
-}
-
-
-
-
-
 static const UMLRTCommsPortRole portroles_border[] = 
 {
     {
diff --git a/models/samples/ComputerSystem/expected_src/LocalPrinter.hh b/models/samples/ComputerSystem/expected_src/LocalPrinter.hh
index 39c899c..1d38e5b 100644
--- a/models/samples/ComputerSystem/expected_src/LocalPrinter.hh
+++ b/models/samples/ComputerSystem/expected_src/LocalPrinter.hh
@@ -19,11 +19,30 @@
 {
 public:
     Capsule_LocalPrinter( const UMLRTCapsuleClass * cd, UMLRTSlot * st, const UMLRTCommsPort * * border, const UMLRTCommsPort * * internal, bool isStat );
+protected:
+    UMLRTLogProtocol_baserole log;
+    USBProtocol::Base usbPort;
+public:
+    enum BorderPortId
+    {
+        borderport_usbPort,
+        borderport_log
+    };
+    enum PartId
+    {
+    };
     enum PortId
     {
         port_log,
         port_usbPort
     };
+    virtual void bindPort( bool isBorder, int portId, int index );
+    virtual void unbindPort( bool isBorder, int portId, int index );
+protected:
+    USBDeviceClasses usbClass;
+    bool connectionStatus;
+    bool printingData;
+public:
     virtual void inject( const UMLRTMessage & message );
     virtual void initialize( const UMLRTMessage & message );
     const char * getCurrentStateString() const;
@@ -56,24 +75,6 @@
     State choice_____Connected_( const UMLRTMessage * msg );
     State state_____Connected( const UMLRTMessage * msg );
     State state_____Disconnected( const UMLRTMessage * msg );
-protected:
-    UMLRTLogProtocol_baserole log;
-    USBProtocol::Base usbPort;
-public:
-    enum BorderPortId
-    {
-        borderport_usbPort,
-        borderport_log
-    };
-    enum PartId
-    {
-    };
-    virtual void bindPort( bool isBorder, int portId, int index );
-    virtual void unbindPort( bool isBorder, int portId, int index );
-protected:
-    USBDeviceClasses usbClass;
-    bool connectionStatus;
-    bool printingData;
 };
 extern const UMLRTCapsuleClass LocalPrinter;
 
diff --git a/models/samples/ComputerSystem/expected_src/MakefileTop.mk b/models/samples/ComputerSystem/expected_src/MakefileTop.mk
index e3907f8..f6ac320 100644
--- a/models/samples/ComputerSystem/expected_src/MakefileTop.mk
+++ b/models/samples/ComputerSystem/expected_src/MakefileTop.mk
@@ -29,7 +29,7 @@
 LD_LIBS:=$(foreach i, $(LD_LIBS), $(LD_LIB)$i)
 LD_PATHS:=$(foreach i, $(LD_PATHS), $(LD_LIBPATH)$i)
 
-SRCS = TopMain.cc Computer.cc Resource.cc ResourceManager.cc WordProcessorApp.cc USBProtocol.cc AppControl.cc User.cc USBDeviceDriver.cc USBStorageDriver.cc USBPrinterDriver.cc Application.cc LocalPrinter.cc ExtMassStorage.cc OSCommand.cc ComputerSystem.cc Top.cc TopControllers.cc 
+SRCS = TopMain.cc Computer.cc Resource.cc ResourceManager.cc WordProcessorApp.cc USBProtocol.cc USBDeviceDriver.cc USBPrinterDriver.cc USBStorageDriver.cc LocalPrinter.cc ExtMassStorage.cc AppControl.cc User.cc Application.cc OSCommand.cc ComputerSystem.cc Top.cc TopControllers.cc 
 OBJS = $(subst $(CC_EXT),$(OBJ_EXT),$(SRCS))
 
 MAIN = TopMain$(EXE_EXT)
diff --git a/models/tests/executable/PingPong/expected_src/CMakeLists.txt b/models/tests/executable/PingPong/expected_src/CMakeLists.txt
index 5560403..93fac21 100644
--- a/models/tests/executable/PingPong/expected_src/CMakeLists.txt
+++ b/models/tests/executable/PingPong/expected_src/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Generated 2016-08-30 10:40:30
+# Generated 2016-08-31 13:18:28
 
 cmake_minimum_required(VERSION 2.8.7)
 set(TARGET TopMain)
diff --git a/plugins/xtumlrt/common/org.eclipse.papyrusrt.xtumlrt.util/META-INF/MANIFEST.MF b/plugins/xtumlrt/common/org.eclipse.papyrusrt.xtumlrt.util/META-INF/MANIFEST.MF
index 40862c6..55d33c2 100644
--- a/plugins/xtumlrt/common/org.eclipse.papyrusrt.xtumlrt.util/META-INF/MANIFEST.MF
+++ b/plugins/xtumlrt/common/org.eclipse.papyrusrt.xtumlrt.util/META-INF/MANIFEST.MF
@@ -9,6 +9,7 @@
  org.eclipse.emf.ecore;bundle-version="2.12.0",
  org.eclipse.uml2.uml;bundle-version="5.2.0",
  org.eclipse.papyrusrt.xtumlrt.common.model;bundle-version="0.7.2",
+ org.eclipse.papyrusrt.xtumlrt.statemach.ext.model;bundle-version="0.7.2",
  org.eclipse.papyrusrt.xtumlrt.umlrt.model;bundle-version="0.7.2",
  org.eclipse.papyrusrt.umlrt.profile;bundle-version="0.7.2",
  org.eclipse.core.runtime;bundle-version="3.12.0"
diff --git a/plugins/xtumlrt/common/org.eclipse.papyrusrt.xtumlrt.util/src/org/eclipse/papyrusrt/xtumlrt/util/GeneralUtil.xtend b/plugins/xtumlrt/common/org.eclipse.papyrusrt.xtumlrt.util/src/org/eclipse/papyrusrt/xtumlrt/util/GeneralUtil.xtend
index 3818002..feaec81 100644
--- a/plugins/xtumlrt/common/org.eclipse.papyrusrt.xtumlrt.util/src/org/eclipse/papyrusrt/xtumlrt/util/GeneralUtil.xtend
+++ b/plugins/xtumlrt/common/org.eclipse.papyrusrt.xtumlrt.util/src/org/eclipse/papyrusrt/xtumlrt/util/GeneralUtil.xtend
@@ -47,4 +47,28 @@
         eobj.name
     }
 
+    static def <T> Iterable<T> longestCommonPrefix( Iterable<T> l1, Iterable<T> l2 )
+    {
+        val prefix = newArrayList
+        var i = 0
+        while (l1.get(i) == l2.get(i))
+        {
+            prefix.add(l1.get(i))
+            i++
+        }
+        prefix
+    }
+
+    static def longestCommonPrefix( String s1, String s2 )
+    {
+        val prefix = new StringBuilder
+        var i = 0
+        while (s1.charAt(i) == s2.charAt(i))
+        {
+            prefix.append(s1.charAt(i))
+            i++
+        }
+        prefix.toString
+    }
+
 }
\ No newline at end of file
diff --git a/plugins/xtumlrt/common/org.eclipse.papyrusrt.xtumlrt.util/src/org/eclipse/papyrusrt/xtumlrt/util/XTUMLRTStateMachineUtil.xtend b/plugins/xtumlrt/common/org.eclipse.papyrusrt.xtumlrt.util/src/org/eclipse/papyrusrt/xtumlrt/util/XTUMLRTStateMachineUtil.xtend
index 1bb1d80..108344e 100644
--- a/plugins/xtumlrt/common/org.eclipse.papyrusrt.xtumlrt.util/src/org/eclipse/papyrusrt/xtumlrt/util/XTUMLRTStateMachineUtil.xtend
+++ b/plugins/xtumlrt/common/org.eclipse.papyrusrt.xtumlrt.util/src/org/eclipse/papyrusrt/xtumlrt/util/XTUMLRTStateMachineUtil.xtend
@@ -27,6 +27,10 @@
 import static extension org.eclipse.papyrusrt.xtumlrt.util.GeneralUtil.*
 import static extension org.eclipse.papyrusrt.xtumlrt.util.XTUMLRTUtil.*
 import java.util.List
+import org.eclipse.papyrusrt.xtumlrt.common.ActionCode
+import org.eclipse.papyrusrt.xtumlrt.statemachext.EntryAction
+import org.eclipse.papyrusrt.xtumlrt.statemachext.ExitAction
+import org.eclipse.papyrusrt.xtumlrt.statemachext.TransitionAction
 
 class XTUMLRTStateMachineUtil
 {
@@ -319,6 +323,36 @@
             null
     }
 
+    static dispatch def State getOwnerState( EntryAction action )
+    {
+        if (action !== null
+            && action.owner !== null
+            && action.owner instanceof State)
+            action.owner as State
+        else
+            null
+    }
+
+    static dispatch def State getOwnerState( ExitAction action )
+    {
+        if (action !== null
+            && action.owner !== null
+            && action.owner instanceof State)
+            action.owner as State
+        else
+            null
+    }
+
+    static dispatch def State getOwnerState( TransitionAction action )
+    {
+        if (action !== null
+            && action.owner !== null
+            && action.owner instanceof ActionChain)
+            action.owner.ownerState
+        else
+            null
+    }
+
     static dispatch def State getOwnerState( ActionChain actionChain )
     {
         if (actionChain !== null 
@@ -346,6 +380,52 @@
             null
     }
 
+    static def StateMachine getOwnerStateMachine( NamedElement element )
+    {
+        var StateMachine result = null
+        if (element !== null)
+        {
+            var stateMachineElement = element
+            while (!(stateMachineElement instanceof StateMachine))
+            {
+                stateMachineElement = stateMachineElement.owner
+            }
+            if (stateMachineElement instanceof StateMachine)
+            {
+                result = stateMachineElement
+            }
+        }
+        result
+    }
+
+    /**
+     * Returns the set of all possible vertices that could be an end-point (source or target)
+     * of the given transition. This is, if the transition is inside a composite state S,
+     * the set contains the following (and only these):
+     * 
+     * <ul>
+     *   <li>S
+     *   <li>All substates of S
+     *   <li>All pseudo-states owned by S (entry, exit, initial, history, choice, junction and terminate points)
+     *   <li>All the connection points (entry or exit points) of all the substates of S
+     * </ul>
+     */
+    static def Iterable<Vertex> getPossibleEndpoints( Transition transition )
+    {
+        val List<Vertex> vertices = newArrayList
+        if (transition !== null)
+        {
+            val state = transition.ownerState as CompositeState
+            if (state !== null)
+            {
+                vertices.addAll( state.substates )
+                vertices.addAll( state.pseudostates )
+                vertices.addAll( state.substates.map[connectionPoints] )
+            }
+        }
+        vertices
+    }
+
     static def Iterable<Pseudostate> getPseudostates( CompositeState state )
     {
         val List<Pseudostate> pseudostates = newArrayList
diff --git a/plugins/xtumlrt/common/org.eclipse.papyrusrt.xtumlrt.util/src/org/eclipse/papyrusrt/xtumlrt/util/XTUMLRTUtil.xtend b/plugins/xtumlrt/common/org.eclipse.papyrusrt.xtumlrt.util/src/org/eclipse/papyrusrt/xtumlrt/util/XTUMLRTUtil.xtend
index ee60f7d..a1ce36a 100644
--- a/plugins/xtumlrt/common/org.eclipse.papyrusrt.xtumlrt.util/src/org/eclipse/papyrusrt/xtumlrt/util/XTUMLRTUtil.xtend
+++ b/plugins/xtumlrt/common/org.eclipse.papyrusrt.xtumlrt.util/src/org/eclipse/papyrusrt/xtumlrt/util/XTUMLRTUtil.xtend
@@ -9,6 +9,7 @@
 
 import java.util.Comparator
 import java.util.LinkedHashSet
+import java.util.List
 import org.eclipse.papyrusrt.xtumlrt.common.Behaviour
 import org.eclipse.papyrusrt.xtumlrt.common.Capsule
 import org.eclipse.papyrusrt.xtumlrt.common.CapsulePart
@@ -23,10 +24,10 @@
 import org.eclipse.papyrusrt.xtumlrt.common.ProtocolBehaviourFeatureKind
 import org.eclipse.papyrusrt.xtumlrt.common.Signal
 import org.eclipse.papyrusrt.xtumlrt.common.StructuredType
-import org.eclipse.papyrusrt.xtumlrt.common.VisibilityKind
+import org.eclipse.papyrusrt.xtumlrt.umlrt.PortKind
 import org.eclipse.papyrusrt.xtumlrt.umlrt.PortRegistration
 import org.eclipse.papyrusrt.xtumlrt.umlrt.RTPort
-import org.eclipse.papyrusrt.xtumlrt.umlrt.PortKind
+import static extension org.eclipse.papyrusrt.xtumlrt.util.GeneralUtil.*
 
 class XTUMLRTUtil
 {
@@ -84,9 +85,36 @@
     {
         val set = new LinkedHashSet<Capsule>()
         set.addAll( packge.entities.filter( Capsule ) )
+        for ( pkg : packge.packages )
+        {
+            set.addAll( pkg.allCapsules )
+        }
         set
     }
 
+    static dispatch def Iterable<Protocol> getAllProtocols( Model model )
+    {
+        val set = new LinkedHashSet<Protocol>()
+        set.addAll( model.protocols )
+        for ( pkg : model.packages )
+        {
+            set.addAll( pkg.allProtocols )
+        }
+        set
+    }
+
+    static dispatch def Iterable<Protocol> getAllProtocols( Package packge )
+    {
+        val set = new LinkedHashSet<Protocol>()
+        set.addAll( packge.protocols )
+        for ( pkg : packge.packages )
+        {
+            set.addAll( pkg.allProtocols )
+        }
+        set
+    }
+
+
     /**
      * Returns the set of all ports in the class, including those which have been inherited
      * and those which are redefinitions of inherited ports.
@@ -128,6 +156,22 @@
     }
 
     /**
+     * Returns the list of all elements in the containment chain from the root element
+     * to the given element.
+     */
+    static def Iterable<CommonElement> getAllContainers( CommonElement element )
+    {
+        val List<CommonElement> list = newArrayList
+        var elem = element
+        while (elem !== null)
+        {
+            list.add( 0, elem )
+            elem = elem.owner
+        }
+        list
+    }
+
+    /**
      * Returns the set of all ports in the class, including those which have been inherited
      * and those which are redefinitions of inherited ports.
      */
@@ -279,6 +323,27 @@
         }
     }
 
+    /**
+     * Returns the lowest common ancestor to the given elements, i.e. the element 
+     * that contains (directly or indirectly) both elements and which doesn't contain any other common 
+     * ancestor of both elements.
+     */
+    static def CommonElement getLowestCommonAncestor( CommonElement element1, CommonElement element2 )
+    {
+        val prefix = getLowestCommonAncestorPrefix(element1, element2)
+        prefix.last
+    }
+
+    /**
+     * Returns the container list of the lowest common ancestor to the given elements, i.e. the element 
+     * that contains (directly or indirectly) both elements and which doesn't contain any other common 
+     * ancestor of both elements.
+     */
+    static def Iterable<CommonElement> getLowestCommonAncestorPrefix( CommonElement element1, CommonElement element2 )
+    {
+        longestCommonPrefix(element1.allContainers, element2.allContainers)
+    }
+
     static def Iterable<Signal> getOutSignals( Protocol protocol )
     {
         protocol.protocolBehaviourFeatures
diff --git a/plugins/xtumlrt/xtext/org.eclipse.papyrusrt.xtumlrt.xtext.ui/src/org/eclipse/papyrusrt/xtumlrt/xtext/ui/labeling/UmlrtLabelProvider.xtend b/plugins/xtumlrt/xtext/org.eclipse.papyrusrt.xtumlrt.xtext.ui/src/org/eclipse/papyrusrt/xtumlrt/xtext/ui/labeling/UmlrtLabelProvider.xtend
index 53ba1bd..e322d11 100644
--- a/plugins/xtumlrt/xtext/org.eclipse.papyrusrt.xtumlrt.xtext.ui/src/org/eclipse/papyrusrt/xtumlrt/xtext/ui/labeling/UmlrtLabelProvider.xtend
+++ b/plugins/xtumlrt/xtext/org.eclipse.papyrusrt.xtumlrt.xtext.ui/src/org/eclipse/papyrusrt/xtumlrt/xtext/ui/labeling/UmlrtLabelProvider.xtend
@@ -89,7 +89,11 @@
 	}
 	
 	def dispatch String text(Port element) {
-		element.name + ' : ' + text(element.type)
+		val type = element.type
+		if (type !== null)
+			element.name + ' : ' + text(element.type)
+		else
+			element.name
 	}
 	
 	def dispatch String text(CapsulePart element) {
diff --git a/plugins/xtumlrt/xtext/org.eclipse.papyrusrt.xtumlrt.xtext/META-INF/MANIFEST.MF b/plugins/xtumlrt/xtext/org.eclipse.papyrusrt.xtumlrt.xtext/META-INF/MANIFEST.MF
index 3a06832..db7dbb3 100644
--- a/plugins/xtumlrt/xtext/org.eclipse.papyrusrt.xtumlrt.xtext/META-INF/MANIFEST.MF
+++ b/plugins/xtumlrt/xtext/org.eclipse.papyrusrt.xtumlrt.xtext/META-INF/MANIFEST.MF
@@ -10,6 +10,7 @@
  org.eclipse.papyrusrt.xtumlrt.common.model;bundle-version="0.7.2",
  org.eclipse.papyrusrt.xtumlrt.statemach.ext.model;bundle-version="0.7.2",
  org.eclipse.papyrusrt.xtumlrt.umlrt.model;bundle-version="0.7.2",
+ org.eclipse.papyrusrt.xtumlrt.util;bundle-version="0.7.2",
  org.eclipse.xtext;bundle-version="2.10.0",
  org.eclipse.xtext.xbase;bundle-version="2.10.0",
  org.eclipse.xtext.util;bundle-version="2.10.0",
diff --git a/plugins/xtumlrt/xtext/org.eclipse.papyrusrt.xtumlrt.xtext/src/org/eclipse/papyrusrt/xtumlrt/xtext/Tumlrt.xtext b/plugins/xtumlrt/xtext/org.eclipse.papyrusrt.xtumlrt.xtext/src/org/eclipse/papyrusrt/xtumlrt/xtext/Tumlrt.xtext
index 92d1b05..8011a71 100644
--- a/plugins/xtumlrt/xtext/org.eclipse.papyrusrt.xtumlrt.xtext/src/org/eclipse/papyrusrt/xtumlrt/xtext/Tumlrt.xtext
+++ b/plugins/xtumlrt/xtext/org.eclipse.papyrusrt.xtumlrt.xtext/src/org/eclipse/papyrusrt/xtumlrt/xtext/Tumlrt.xtext
@@ -411,7 +411,7 @@
 ;
 
 RTTrigger returns RTTrigger:
-    RTTriggerMPForm | RTTriggerPMForm
+    RTTriggerPMForm // | RTTriggerMPForm
 ;
 
 fragment RTTriggerPortsFragment returns RTTrigger:
@@ -422,11 +422,14 @@
     )
 ;
 
+
 RTTriggerMPForm returns RTTrigger:
+    {RTTrigger}
     'on' signal=[Signal|QualifiedName] 'from' RTTriggerPortsFragment
 ;
 
 RTTriggerPMForm returns RTTrigger:
+    {RTTrigger}
     'on' RTTriggerPortsFragment ':' signal=[Signal|QualifiedName]
 ;
 
@@ -499,8 +502,8 @@
 	'{'
 		DescriptionFragment
 		(lifelines+=Lifeline)*
-		(messages+=Message)*
 		(fragments+=Fragment)*
+		(messages+=Message)*
 		AnnotationsFragment
 	'}';
 
diff --git a/plugins/xtumlrt/xtext/org.eclipse.papyrusrt.xtumlrt.xtext/src/org/eclipse/papyrusrt/xtumlrt/xtext/scoping/UmlrtScopeProvider.xtend b/plugins/xtumlrt/xtext/org.eclipse.papyrusrt.xtumlrt.xtext/src/org/eclipse/papyrusrt/xtumlrt/xtext/scoping/UmlrtScopeProvider.xtend
index 8fd27e7..f243c8d 100644
--- a/plugins/xtumlrt/xtext/org.eclipse.papyrusrt.xtumlrt.xtext/src/org/eclipse/papyrusrt/xtumlrt/xtext/scoping/UmlrtScopeProvider.xtend
+++ b/plugins/xtumlrt/xtext/org.eclipse.papyrusrt.xtumlrt.xtext/src/org/eclipse/papyrusrt/xtumlrt/xtext/scoping/UmlrtScopeProvider.xtend
@@ -3,25 +3,36 @@
  */
 package org.eclipse.papyrusrt.xtumlrt.xtext.scoping
 
-import org.eclipse.papyrusrt.xtumlrt.common.CapsulePart
-import org.eclipse.emf.ecore.EReference
-import org.eclipse.xtext.scoping.IScope
-import org.eclipse.xtext.EcoreUtil2
-import org.eclipse.papyrusrt.xtumlrt.common.Capsule
-import org.eclipse.xtext.scoping.Scopes
-import org.eclipse.xtext.scoping.impl.FilteringScope
 import com.google.common.base.Predicate
-import org.eclipse.xtext.resource.IEObjectDescription
+import com.google.inject.Inject
+import java.util.List
+import org.eclipse.emf.ecore.EObject
+import org.eclipse.emf.ecore.EReference
+import org.eclipse.papyrusrt.xtumlrt.common.Capsule
+import org.eclipse.papyrusrt.xtumlrt.common.CapsulePart
+import org.eclipse.papyrusrt.xtumlrt.common.Connector
 import org.eclipse.papyrusrt.xtumlrt.common.ConnectorEnd
-import org.eclipse.xtext.resource.impl.AliasedEObjectDescription
+import org.eclipse.papyrusrt.xtumlrt.common.NamedElement
+import org.eclipse.papyrusrt.xtumlrt.common.ProtocolBehaviourFeatureKind
+import org.eclipse.papyrusrt.xtumlrt.interactions.Interaction
+import org.eclipse.papyrusrt.xtumlrt.statemach.Transition
+import org.eclipse.papyrusrt.xtumlrt.statemach.Vertex
+import org.eclipse.papyrusrt.xtumlrt.umlrt.RTTrigger
+import org.eclipse.xtext.naming.IQualifiedNameProvider
 import org.eclipse.xtext.naming.QualifiedName
 import org.eclipse.xtext.resource.EObjectDescription
-import com.google.inject.Inject
-import org.eclipse.xtext.naming.IQualifiedNameProvider
+import org.eclipse.xtext.resource.IEObjectDescription
+import org.eclipse.xtext.resource.impl.AliasedEObjectDescription
+import org.eclipse.xtext.scoping.IScope
+import org.eclipse.xtext.scoping.Scopes
+import org.eclipse.xtext.scoping.impl.AbstractDeclarativeScopeProvider
+import org.eclipse.xtext.scoping.impl.FilteringScope
 import org.eclipse.xtext.scoping.impl.SimpleScope
-import org.eclipse.papyrusrt.xtumlrt.common.NamedElement
-import org.eclipse.emf.ecore.EObject
-import org.eclipse.papyrusrt.xtumlrt.umlrt.RTTrigger
+
+import static extension org.eclipse.papyrusrt.xtumlrt.util.GeneralUtil.*
+import static extension org.eclipse.papyrusrt.xtumlrt.util.XTUMLRTStateMachineUtil.*
+import static extension org.eclipse.papyrusrt.xtumlrt.util.XTUMLRTUtil.*
+import org.eclipse.xtext.naming.IQualifiedNameConverter
 
 /**
  * This class contains custom scoping description.
@@ -30,9 +41,10 @@
  * on how and when to use it.
  *
  */
-class UmlrtScopeProvider extends org.eclipse.xtext.scoping.impl.AbstractDeclarativeScopeProvider
+class UmlrtScopeProvider extends AbstractDeclarativeScopeProvider
 {
     @Inject IQualifiedNameProvider nameProvider
+    @Inject IQualifiedNameConverter nameConverter
 
     def IScope scope_CapsulePart_type( CapsulePart context, EReference eref )
     {
@@ -45,26 +57,95 @@
                 {
                     override apply( IEObjectDescription input )
                     {
-                        input.getEObjectOrProxy() != context.eContainer
+                        val eobj = input.EObjectOrProxy
+                        eobj != context.eContainer
                     }
                 }
             )
         return filteredScope
     }
 
+    def IScope scope_ConnectorEnd_partWithPort( Connector context, EReference eref )
+    {
+        val elements = (context.owner as Capsule).parts
+        Scopes.scopeFor( elements )
+    } 
+
+    def IScope scope_ConnectorEnd_partWithPort( ConnectorEnd context, EReference eref )
+    {
+        val elements = (context.owner.owner as Capsule).parts
+        Scopes.scopeFor( elements )
+    } 
+
     def IScope scope_ConnectorEnd_role( ConnectorEnd context, EReference eref )
     {
         val elements = context.partWithPort.type.ports
-        aliasedScope( context, eref, elements )
+        Scopes.scopeFor( elements )
     }
 
+    def IScope scope_Transition_sourceVertex( Transition context, EReference eref )
+    {
+        transition_endpoints( context, eref )
+    }
+
+    def IScope scope_Transition_targetVertex( Transition context, EReference eref )
+    {
+        transition_endpoints( context, eref )
+    }
+
+    protected def IScope transition_endpoints( Transition context, EReference eref )
+    {
+        val elements = context.possibleEndpoints as List<Vertex>
+        Scopes.scopeFor( elements )
+    }
+
+    def IScope scope_RTTrigger_ports( Transition context, EReference eref )
+    {
+        val capsule = context.ownerStateMachine?.owner as Capsule
+        val elements = capsule.ports
+//        aliasedScope( context, eref, elements )
+        Scopes.scopeFor( elements )
+    }
+
+//    def IScope scope_RTTrigger_ports( RTTrigger context, EReference eref )
+//    {
+//        val capsule = context.ownerStateMachine?.owner as Capsule
+//        val elements = capsule.ports
+////        aliasedScope( context, eref, elements )
+//        Scopes.scopeFor( elements )
+//    }
+
     def IScope scope_RTTrigger_signal( RTTrigger context, EReference eref )
     {
         val ports = context.ports
         if (ports === null || ports.empty ) return delegateGetScope( context , eref )
-        val protocol = ports.get(0).type    // If other ports are listed and they have different protocols, then they are ignored
+        // If other ports are listed and they have different protocols, then they are ignored
+        val port = ports.get(0)
+        val protocol = port.type
         val messages = protocol.protocolBehaviourFeatures
-        aliasedScope( context, eref, messages )
+        val elements =
+            if (!port.conjugate) 
+                messages.filter[kind == ProtocolBehaviourFeatureKind.IN || kind == ProtocolBehaviourFeatureKind.INOUT]
+            else
+                messages.filter[kind == ProtocolBehaviourFeatureKind.OUT || kind == ProtocolBehaviourFeatureKind.INOUT]
+//        aliasedScope( context, eref, messages )
+        Scopes.scopeFor( elements )
+    }
+
+    def IScope scope_Lifeline_represents( Interaction context, EReference eref )
+    {
+        val model = context.root
+        val capsules = model.allCapsules
+        val parts = capsules.map[ parts ].flatten
+        qualifiedNamesScopeFor( context, parts )
+    }
+
+    def IScope scope_Message_signature( Interaction context, EReference eref )
+    {
+        val model = context.root
+        val protocols = model.allProtocols
+        val messages = protocols.map[ protocolBehaviourFeatures ].flatten
+        qualifiedNamesScopeFor( context, messages )
     }
 
     protected def IScope aliasedScope( EObject context, EReference eref, Iterable<? extends NamedElement> elements )
@@ -85,4 +166,62 @@
         return new SimpleScope( existingScope, scope, false )
     }
 
+    protected def IScope aliasedScopeFor( Iterable<? extends NamedElement> elements )
+    {
+        val scope = <IEObjectDescription>newArrayList()
+        for ( element : elements )
+        {
+            scope.add
+            (
+                new AliasedEObjectDescription
+                (
+                    QualifiedName.create( element.name ), 
+                    EObjectDescription.create( nameProvider.getFullyQualifiedName( element ), element )
+                )
+            )
+        }
+        return new SimpleScope( IScope.NULLSCOPE, scope, false )
+    }
+
+    protected def IScope containmentFilteredScope( IScope existingScope, EObject context, EReference eref, Iterable<? extends NamedElement> elements )
+    {
+        val list = elements.toList
+        val filteredScope =
+            new FilteringScope
+            (
+                existingScope,
+                new Predicate<IEObjectDescription>()
+                {
+                    override apply( IEObjectDescription input )
+                    {
+                        val eobj = input.getEObjectOrProxy()
+                        list.contains( eobj )
+                    }
+                }
+            )
+        return filteredScope
+    }
+
+    protected def IScope containmentFilteredAliasedScope( EObject context, EReference eref, Iterable<? extends NamedElement> elements )
+    {
+        val aliased = aliasedScope( context, eref, elements )
+        containmentFilteredScope( aliased, context, eref, elements )
+    }
+    
+    protected def qualifiedNamesScopeFor( EObject context, Iterable<? extends NamedElement> elements )
+    {
+        val contextFqn = nameProvider.getFullyQualifiedName( context )
+        val contextFqnStr = contextFqn.toString
+        val nameComputation = 
+        [
+            NamedElement element | 
+                val elementFqn = nameProvider.getFullyQualifiedName( element )
+                val elementFqnStr = elementFqn.toString
+                val longestCommonPrefix = longestCommonPrefix( contextFqnStr, elementFqnStr )
+                val relativeElementQnStr = elementFqnStr.substring(longestCommonPrefix.length)
+                nameConverter.toQualifiedName( relativeElementQnStr )
+        ]
+        new SimpleScope( IScope.NULLSCOPE, Scopes.scopedElementsFor(elements, nameComputation) )
+    }
+
 }