Bug 487604 - Explicit dependency to system element should be supported

Generate include statement for dependency drawn to the system element.

Change-Id: If9df3c995fa4fd57967d4fe610b5861641605089
Signed-off-by: yroh <ysroh@zeligsoft.com>
diff --git a/models/samples/ComputerSystem/expected_src/Computer.hh b/models/samples/ComputerSystem/expected_src/Computer.hh
index 896aabb..8f734b8 100644
--- a/models/samples/ComputerSystem/expected_src/Computer.hh
+++ b/models/samples/ComputerSystem/expected_src/Computer.hh
@@ -17,6 +17,8 @@
 struct UMLRTSlot;
 
 #include "ResourceType.hh"
+#include "umlrttimerid.hh"
+#include "umlrttimespec.hh"
 
 #include <iostream>

 #include <iomanip>

diff --git a/plugins/umlrt/codegen/org.eclipse.papyrusrt.codegen.cpp.rts/src/org/eclipse/papyrusrt/codegen/cpp/rts/UMLRTRuntime.java b/plugins/umlrt/codegen/org.eclipse.papyrusrt.codegen.cpp.rts/src/org/eclipse/papyrusrt/codegen/cpp/rts/UMLRTRuntime.java
index ca34ad4..d512801 100644
--- a/plugins/umlrt/codegen/org.eclipse.papyrusrt.codegen.cpp.rts/src/org/eclipse/papyrusrt/codegen/cpp/rts/UMLRTRuntime.java
+++ b/plugins/umlrt/codegen/org.eclipse.papyrusrt.codegen.cpp.rts/src/org/eclipse/papyrusrt/codegen/cpp/rts/UMLRTRuntime.java
@@ -7,6 +7,7 @@
  *******************************************************************************/
 package org.eclipse.papyrusrt.codegen.cpp.rts;
 
+import org.eclipse.papyrusrt.codegen.lang.cpp.Element;
 import org.eclipse.papyrusrt.codegen.lang.cpp.Expression;
 import org.eclipse.papyrusrt.codegen.lang.cpp.Name;
 import org.eclipse.papyrusrt.codegen.lang.cpp.Type;
@@ -31,6 +32,7 @@
 import org.eclipse.papyrusrt.codegen.lang.cpp.external.StandardLibrary;
 import org.eclipse.papyrusrt.codegen.utils.RTSModelLibraryUtils;
 import org.eclipse.papyrusrt.codegen.utils.XTUMLRTUtil;
+import org.eclipse.papyrusrt.xtumlrt.common.NamedElement;
 import org.eclipse.papyrusrt.xtumlrt.common.Protocol;
 import org.eclipse.papyrusrt.xtumlrt.common.Signal;
 
@@ -785,11 +787,29 @@
             return UMLRTTimerId.getType();
         if( RTSModelLibraryUtils.isTimerSpec( type ) )
             return UMLRTTimespec.getType();
-        return null;
-    }
+		if (RTSModelLibraryUtils.isMessage(type))
+			return UMLRTMessage.getType();
+		return null;
+	}
+
+	/**
+	 * Return the system-defined cpp element of the given element and null if
+	 * the type is not recognized.
+	 */
+	public static Element getSystemElement(NamedElement element) {
+		if (RTSModelLibraryUtils.isCapsuleId(element))
+			return UMLRTCapsuleId.Element;
+		if (RTSModelLibraryUtils.isTimerId(element))
+			return UMLRTTimerId.Element;
+		if (RTSModelLibraryUtils.isTimerSpec(element))
+			return UMLRTTimespec.Element;
+		if (RTSModelLibraryUtils.isMessage(element))
+			return UMLRTMessage.Element;
+		return null;
+	}
 
     /**
-     * Return the Type of the given system-defined protocol and null if the protocol is not recognized. 
+     * Return the Type of the given system-defined protocol and null if the protocol is not recognized.
      */
     public static Type getSystemProtocolRole( Protocol protocol, boolean baseRole )
     {
diff --git a/plugins/umlrt/codegen/org.eclipse.papyrusrt.codegen.cpp/src/org/eclipse/papyrusrt/codegen/cpp/CppCodePattern.java b/plugins/umlrt/codegen/org.eclipse.papyrusrt.codegen.cpp/src/org/eclipse/papyrusrt/codegen/cpp/CppCodePattern.java
index dadac42..201f65e 100644
--- a/plugins/umlrt/codegen/org.eclipse.papyrusrt.codegen.cpp/src/org/eclipse/papyrusrt/codegen/cpp/CppCodePattern.java
+++ b/plugins/umlrt/codegen/org.eclipse.papyrusrt.codegen.cpp/src/org/eclipse/papyrusrt/codegen/cpp/CppCodePattern.java
@@ -647,6 +647,9 @@
 
     public Element getCppElement( NamedElement element )
     {
+		if (RTSModelLibraryUtils.isSystemElement(element)) {
+			return UMLRTRuntime.getSystemElement(element);
+		}
         if( element instanceof org.eclipse.papyrusrt.xtumlrt.common.Capsule )
             return getCppClass( Output.CapsuleClass, element );
         else if( element instanceof org.eclipse.papyrusrt.xtumlrt.common.StructuredType )
diff --git a/plugins/umlrt/codegen/org.eclipse.papyrusrt.codegen.cpp/src/org/eclipse/papyrusrt/codegen/cpp/internal/BasicClassGenerator.java b/plugins/umlrt/codegen/org.eclipse.papyrusrt.codegen.cpp/src/org/eclipse/papyrusrt/codegen/cpp/internal/BasicClassGenerator.java
index d510e8e..3d85ddc 100644
--- a/plugins/umlrt/codegen/org.eclipse.papyrusrt.codegen.cpp/src/org/eclipse/papyrusrt/codegen/cpp/internal/BasicClassGenerator.java
+++ b/plugins/umlrt/codegen/org.eclipse.papyrusrt.codegen.cpp/src/org/eclipse/papyrusrt/codegen/cpp/internal/BasicClassGenerator.java
@@ -71,7 +71,6 @@
 import org.eclipse.papyrusrt.codegen.lang.cpp.stmt.UserCode;
 import org.eclipse.papyrusrt.codegen.utils.CodeGenUtils;
 import org.eclipse.papyrusrt.codegen.utils.QualifiedNames;
-import org.eclipse.papyrusrt.codegen.utils.RTSModelLibraryUtils;
 import org.eclipse.papyrusrt.codegen.xtumlrt.trans.RTCppGenerationProperties;
 import org.eclipse.papyrusrt.xtumlrt.common.AbstractAction;
 import org.eclipse.papyrusrt.xtumlrt.common.ActionCode;
@@ -511,8 +510,7 @@
                     Element cppElement = cpp.getCppElement( supplier );
                     if( cppElement != null )
                     {
-						if (depKindInHead == null && depKindInImpl == null
-								&& !RTSModelLibraryUtils.isSystemElement(supplier)) {
+						if (depKindInHead == null && depKindInImpl == null) {
 							depKindInHead = DependencyKind.INCLUSION;
 						}
                         cppDependencyInHead = getDependency( cppElement, supplier, depKindInHead );
diff --git a/plugins/umlrt/codegen/org.eclipse.papyrusrt.codegen.utils/src/org/eclipse/papyrusrt/codegen/utils/RTSModelLibraryUtils.xtend b/plugins/umlrt/codegen/org.eclipse.papyrusrt.codegen.utils/src/org/eclipse/papyrusrt/codegen/utils/RTSModelLibraryUtils.xtend
index 0f9a1af..be0198f 100644
--- a/plugins/umlrt/codegen/org.eclipse.papyrusrt.codegen.utils/src/org/eclipse/papyrusrt/codegen/utils/RTSModelLibraryUtils.xtend
+++ b/plugins/umlrt/codegen/org.eclipse.papyrusrt.codegen.utils/src/org/eclipse/papyrusrt/codegen/utils/RTSModelLibraryUtils.xtend
@@ -7,21 +7,24 @@
  *******************************************************************************/
 package org.eclipse.papyrusrt.codegen.utils
 
-import org.eclipse.emf.ecore.util.EcoreUtil
 import org.eclipse.emf.common.util.URI
 import org.eclipse.emf.ecore.resource.Resource
 import org.eclipse.emf.ecore.resource.ResourceSet
-import org.eclipse.uml2.uml.UMLPackage
+import org.eclipse.emf.ecore.util.EcoreUtil
 import org.eclipse.papyrusrt.codegen.CodeGenPlugin
 import org.eclipse.papyrusrt.xtumlrt.common.CommonElement
-import org.eclipse.papyrusrt.xtumlrt.common.NamedElement
-import org.eclipse.papyrusrt.xtumlrt.common.Signal
-import org.eclipse.papyrusrt.xtumlrt.common.Protocol
+import org.eclipse.papyrusrt.xtumlrt.common.CommonFactory
 import org.eclipse.papyrusrt.xtumlrt.common.Model
-import org.eclipse.papyrusrt.xtumlrt.common.Type
+import org.eclipse.papyrusrt.xtumlrt.common.NamedElement
+import org.eclipse.papyrusrt.xtumlrt.common.Protocol
+import org.eclipse.papyrusrt.xtumlrt.common.Signal
+import org.eclipse.uml2.uml.Collaboration
+import org.eclipse.uml2.uml.Element
+import org.eclipse.uml2.uml.Package
+import org.eclipse.uml2.uml.UMLPackage
+
 import static extension org.eclipse.papyrusrt.codegen.utils.UMLRealTimeProfileUtil.*
 import static extension org.eclipse.papyrusrt.codegen.utils.XTUMLRTUtil.*
-import org.eclipse.papyrusrt.xtumlrt.common.CommonFactory
 
 class RTSModelLibraryUtils
 {
@@ -66,15 +69,16 @@
     public static val TIMER_ID_TYPE_NAME    = "UMLRTTimerId"
     public static val TIME_SPEC_TYPE_NAME   = "UMLRTTimespec"
     public static val TIME_SPEC_2_TYPE_NAME = "UMLRTTimeSpec"
-
+    public static val MESSAGE_TYPE_NAME     = "UMLRTMessage"
+    
     /** Packages */
     public static val INTERNAL_PACKAGE_NAME  = "Internal"
 
     /** Protocol elements */
-    private static var org.eclipse.uml2.uml.Collaboration FRAME_PROTOCOL    = null
-    private static var org.eclipse.uml2.uml.Collaboration TIMING_PROTOCOL   = null
-    private static var org.eclipse.uml2.uml.Collaboration LOG_PROTOCOL      = null
-    private static var org.eclipse.uml2.uml.Collaboration BASECOMM_PROTOCOL = null
+    private static var Collaboration FRAME_PROTOCOL    = null
+    private static var Collaboration TIMING_PROTOCOL   = null
+    private static var Collaboration LOG_PROTOCOL      = null
+    private static var Collaboration BASECOMM_PROTOCOL = null
 
     /** Protocol message elements: Timing */
     private static var TIMEOUT_MESSAGE   = null
@@ -110,12 +114,12 @@
             return null
         }
         val eobj = EcoreUtil.getObjectByType( contents, UMLPackage.Literals.PACKAGE )
-        if (eobj === null || !(eobj instanceof org.eclipse.uml2.uml.Package))
+        if (eobj === null || !(eobj instanceof Package))
         {
             CodeGenPlugin.warning( "Unable to load package " + fullURI.toPlatformString(true) + "; first element is null or not a UML Package" )
             return null
         }
-        val pkg = eobj as org.eclipse.uml2.uml.Package
+        val pkg = eobj as Package
         return pkg
     }
 
@@ -180,15 +184,14 @@
         RTSModelLibrary
     }
 
-    static def getProtocol( org.eclipse.uml2.uml.Package packge, String name )
+    static def getProtocol( Package packge, String name )
     {
         val protocolContainer = packge.getPackagedElement( name )
-        if (protocolContainer !== null && protocolContainer instanceof org.eclipse.uml2.uml.Package)
+        if (protocolContainer !== null && protocolContainer instanceof Package)
         {
-            val protocol = (protocolContainer as org.eclipse.uml2.uml.Package).getPackagedElement( name )
-            if (protocol !== null && protocol instanceof org.eclipse.uml2.uml.Collaboration)
-                protocol as org.eclipse.uml2.uml.Collaboration
-            
+            val protocol = (protocolContainer as Package).getPackagedElement( name )
+            if (protocol !== null && protocol instanceof Collaboration)
+                protocol as Collaboration
         }
     }
 
@@ -224,7 +227,7 @@
         if (BASECOMM_PROTOCOL === null || reload)
         {
             val internalPackage = RTSModelLibrary.getPackagedElement( INTERNAL_PACKAGE_NAME )
-            if (internalPackage instanceof org.eclipse.uml2.uml.Package)
+            if (internalPackage instanceof Package)
                 BASECOMM_PROTOCOL = getProtocol( internalPackage, BASECOMM_PROTOCOL_NAME )
         }
         BASECOMM_PROTOCOL
@@ -267,7 +270,7 @@
     /**
      * Returns true iff the given UML model is the model library.
      */
-    static def boolean isRTSModelLibrary( org.eclipse.uml2.uml.Package packge )
+    static def boolean isRTSModelLibrary( Package packge )
     {
         if (packge == RTSModelLibrary) return true
         val uriConverter = packge.eResource.resourceSet.URIConverter
@@ -303,13 +306,13 @@
         && (element as NamedElement).hasSysAnnotation
     }
 
-    static def boolean isSystemElement( org.eclipse.uml2.uml.Element element )
+    static def boolean isSystemElement( Element element )
     {
         element.model !== null
         && element.model.isRTSModelLibrary
     }
 
-    static def isCapsuleId( Type type )
+    static def isCapsuleId( NamedElement type )
     {
         type !== null && type.name !== null
         && type.name == CAPSULE_ID_TYPE_NAME
@@ -335,19 +338,24 @@
         && isTextualRTSModelLibrary( element.root as Model )
     }
 
-    static def isTimerId( Type type )
+    static def isTimerId( NamedElement type )
     {
         type !== null && type.name !== null
         && type.name == TIMER_ID_TYPE_NAME
         && isSystemElement( type )
     }
 
-    static def isTimerSpec( Type type )
+    static def isTimerSpec( NamedElement type )
     {
         type !== null && type.name !== null
         && (type.name == TIME_SPEC_2_TYPE_NAME || type.name == TIME_SPEC_TYPE_NAME)  // TODO Until Bug 469218 is resolved
         && isSystemElement( type )
     }
+    
+    static def isMessage(NamedElement type) {
+        type !== null && type.name !== null 
+        && type.name == MESSAGE_TYPE_NAME && isSystemElement(type)
+    }
 
     static def isBaseCommProtocol( Protocol protocol )
     {