[484112] Includes are generated in the alphabetic order

The order of generated has been modified from alphabetic order to
orderes set of the content. The non-regression tests are updated.

Bug: 484112
Change-Id: Idfc82fdce5c7fb6cd28266588f3cdcc3ba49801e
Signed-off-by: Johan Hardy <johan.hardy@spacebel.be>
diff --git a/org.eclipse.umlgen.gen.embedded.c/plugins/org.eclipse.umlgen.gen.embedded.c/src/org/eclipse/umlgen/gen/embedded/c/commons/namedelement.mtl b/org.eclipse.umlgen.gen.embedded.c/plugins/org.eclipse.umlgen.gen.embedded.c/src/org/eclipse/umlgen/gen/embedded/c/commons/namedelement.mtl
index 69a8eb2..d494e67 100644
--- a/org.eclipse.umlgen.gen.embedded.c/plugins/org.eclipse.umlgen.gen.embedded.c/src/org/eclipse/umlgen/gen/embedded/c/commons/namedelement.mtl
+++ b/org.eclipse.umlgen.gen.embedded.c/plugins/org.eclipse.umlgen.gen.embedded.c/src/org/eclipse/umlgen/gen/embedded/c/commons/namedelement.mtl
@@ -83,5 +83,8 @@
 [query public orderByContents(s : Sequence(uml::NamedElement)) : Sequence (uml::NamedElement) = 
 s->sortedBy(n : uml::NamedElement | n.eContainer().eContents()->indexOf(n))/]
 
+[query public orderByContents(s : Sequence(uml::Usage)) : Sequence (uml::Usage) = 
+s->sortedBy(u : uml::Usage | u.oclAsType(uml::NamedElement).eContainer().eContents()->indexOf(u.oclAsType(uml::NamedElement)))/]
+
 [query public hasStereotype(e : uml::Element, qualifiedName : String) : Boolean =
 not(e.getAppliedStereotype(qualifiedName).oclIsUndefined())/]
diff --git a/org.eclipse.umlgen.gen.embedded.c/plugins/org.eclipse.umlgen.gen.embedded.c/src/org/eclipse/umlgen/gen/embedded/c/templates/include.mtl b/org.eclipse.umlgen.gen.embedded.c/plugins/org.eclipse.umlgen.gen.embedded.c/src/org/eclipse/umlgen/gen/embedded/c/templates/include.mtl
index d762c10..bf85a5e 100644
--- a/org.eclipse.umlgen.gen.embedded.c/plugins/org.eclipse.umlgen.gen.embedded.c/src/org/eclipse/umlgen/gen/embedded/c/templates/include.mtl
+++ b/org.eclipse.umlgen.gen.embedded.c/plugins/org.eclipse.umlgen.gen.embedded.c/src/org/eclipse/umlgen/gen/embedded/c/templates/include.mtl
@@ -47,7 +47,7 @@
 [template public genHIncludes(p : uml::Package) post(trim())]
 [genHIncludeParentPackage()/]
 [let seq : Sequence(uml::Usage) = getAllPublicUsage(ownedElement->filter(uml::Usage)->asSequence())]
-[for (u : uml::Usage | seq->sortedBy(name))]
+[for (u : uml::Usage | seq->orderByContents())]
 [if client->notEmpty() and (not(client->excludes(p)))]
 /* Dependency [if name->notEmpty()][name/]: [/if][supplier.name/] <- [client.name/] */
 [supplier.genInclude()/]
@@ -59,7 +59,7 @@
 [template public genCIncludes(p : uml::Package) post(trim())]
 [genCIncludeOwnHeader()/]
 [let seq : Sequence(uml::Usage) = getAllPrivateUsage(ownedElement->filter(uml::Usage)->asSequence())]
-[for (u : uml::Usage | seq->sortedBy(name))]
+[for (u : uml::Usage | seq->orderByContents())]
 [if client->notEmpty() and (not(client->excludes(p)))]
 /* Dependency [if name->notEmpty()][name/]: [/if][supplier.name/] <- [client.name/] */
 [supplier.genInclude()/]
@@ -71,8 +71,8 @@
 [template public genHIncludes(c : uml::Class) post(trim())]
 [genHIncludeParentPackage()/]
 [if not(ancestors(Package)->asOrderedSet()->select(oclIsTypeOf(uml::Package))->first()->isEmpty())]
-[let seq : Sequence(uml::Usage) = getAllPublicUsage(ancestors(Package)->asOrderedSet()->select(oclIsTypeOf(uml::Package))->first().ownedElement->filter(uml::Usage)->asSequence())]
-[for (u : uml::Usage | seq->sortedBy(name))]
+[let seq : Sequence(uml::Usage) = getAllPublicUsage(ancestors(Package)->select(oclIsTypeOf(uml::Package))->first().ownedElement->filter(uml::Usage)->asSequence())]
+[for (u : uml::Usage | seq->orderByContents())]
 [if client->notEmpty() and (not(client->excludes(c)))]
 /* Dependency [if name->notEmpty()][name/]: [/if][supplier.name/] <- [client.name/] */
 [supplier.genInclude()/]
@@ -85,8 +85,8 @@
 [template public genCIncludes(c : uml::Class) post(trim())]
 [genCIncludeOwnHeader()/]
 [if not(ancestors(Package)->asOrderedSet()->select(oclIsTypeOf(uml::Package))->first()->isEmpty())]
-[let seq : Sequence(uml::Usage) = getAllPrivateUsage(ancestors(Package)->asOrderedSet()->select(oclIsTypeOf(uml::Package))->first().ownedElement->filter(uml::Usage)->asSequence())]
-[for (u : uml::Usage | seq->sortedBy(name))]
+[let seq : Sequence(uml::Usage) = getAllPrivateUsage(ancestors(Package)->select(oclIsTypeOf(uml::Package))->first().ownedElement->filter(uml::Usage)->asSequence())]
+[for (u : uml::Usage | seq->orderByContents())]
 [if client->notEmpty() and (not(client->excludes(c)))]
 /* Dependency [if name->notEmpty()][name/]: [/if][supplier.name/] <- [client.name/] */
 [supplier.genInclude()/]
diff --git a/org.eclipse.umlgen.gen.embedded.c/tests/org.eclipse.umlgen.gen.embedded.c.tests/models/NonRegressionModel.uml b/org.eclipse.umlgen.gen.embedded.c/tests/org.eclipse.umlgen.gen.embedded.c.tests/models/NonRegressionModel.uml
index 697ebba..92a6c8f 100644
--- a/org.eclipse.umlgen.gen.embedded.c/tests/org.eclipse.umlgen.gen.embedded.c.tests/models/NonRegressionModel.uml
+++ b/org.eclipse.umlgen.gen.embedded.c/tests/org.eclipse.umlgen.gen.embedded.c.tests/models/NonRegressionModel.uml
@@ -699,7 +699,7 @@
         </packagedElement>

         <packagedElement xmi:type="uml:Usage" xmi:id="_LWxMEA9fEeWawdzS12uxpQ" name="aSingleton_anObject" client="_2-fvkA9XEeWawdzS12uxpQ" supplier="_3mXn4A9XEeWawdzS12uxpQ"/>

         <packagedElement xmi:type="uml:Usage" xmi:id="_S9RqcA9fEeWawdzS12uxpQ" name="aSingleton_aClass" visibility="private" client="_2-fvkA9XEeWawdzS12uxpQ" supplier="_3vS6YA9XEeWawdzS12uxpQ"/>

-        <packagedElement xmi:type="uml:Usage" xmi:id="_XZR7sA9fEeWawdzS12uxpQ" name="anObject_aSingleton" client="_3mXn4A9XEeWawdzS12uxpQ" supplier="_2-fvkA9XEeWawdzS12uxpQ"/>

+        <packagedElement xmi:type="uml:Usage" xmi:id="_XZR7sA9fEeWawdzS12uxpQ" name="anObject_aSingleton" visibility="private" client="_3mXn4A9XEeWawdzS12uxpQ" supplier="_2-fvkA9XEeWawdzS12uxpQ"/>

         <packagedElement xmi:type="uml:Usage" xmi:id="_XZR7sQ9fEeWawdzS12uxpQ" name="anObject_aClass" visibility="private" client="_3mXn4A9XEeWawdzS12uxpQ" supplier="_3vS6YA9XEeWawdzS12uxpQ"/>

         <packagedElement xmi:type="uml:Usage" xmi:id="_XjQXEA9fEeWawdzS12uxpQ" name="aClass_aSingleton" client="_3vS6YA9XEeWawdzS12uxpQ" supplier="_2-fvkA9XEeWawdzS12uxpQ"/>

         <packagedElement xmi:type="uml:Usage" xmi:id="_XjQXEQ9fEeWawdzS12uxpQ" name="aClass_anObject" visibility="private" client="_3vS6YA9XEeWawdzS12uxpQ" supplier="_3mXn4A9XEeWawdzS12uxpQ"/>

diff --git a/org.eclipse.umlgen.gen.embedded.c/tests/org.eclipse.umlgen.gen.embedded.c.tests/src-gen/Package1/Package2/anObject.c b/org.eclipse.umlgen.gen.embedded.c/tests/org.eclipse.umlgen.gen.embedded.c.tests/src-gen/Package1/Package2/anObject.c
index 6de3aba..ca9631b 100644
--- a/org.eclipse.umlgen.gen.embedded.c/tests/org.eclipse.umlgen.gen.embedded.c.tests/src-gen/Package1/Package2/anObject.c
+++ b/org.eclipse.umlgen.gen.embedded.c/tests/org.eclipse.umlgen.gen.embedded.c.tests/src-gen/Package1/Package2/anObject.c
@@ -17,6 +17,8 @@
 
 /* Dependency with own header */
 #include "Package1/Package2/anObject.h"
+/* Dependency anObject_aSingleton: aSingleton <- anObject */
+#include "Package1/Package2/aSingleton.h"
 /* Dependency anObject_aClass: aClass <- anObject */
 #include "Package1/Package2/aClass.h"
 
diff --git a/org.eclipse.umlgen.gen.embedded.c/tests/org.eclipse.umlgen.gen.embedded.c.tests/src-gen/Package1/Package2/anObject.h b/org.eclipse.umlgen.gen.embedded.c/tests/org.eclipse.umlgen.gen.embedded.c.tests/src-gen/Package1/Package2/anObject.h
index 770b26b..681f058 100644
--- a/org.eclipse.umlgen.gen.embedded.c/tests/org.eclipse.umlgen.gen.embedded.c.tests/src-gen/Package1/Package2/anObject.h
+++ b/org.eclipse.umlgen.gen.embedded.c/tests/org.eclipse.umlgen.gen.embedded.c.tests/src-gen/Package1/Package2/anObject.h
@@ -20,8 +20,6 @@
 
 /* Dependency with parent package */
 #include "Package1/Package2/Package2.h"
-/* Dependency anObject_aSingleton: aSingleton <- anObject */
-#include "Package1/Package2/aSingleton.h"
 
 /**********************************************************************************
  * Package2/anObject.h