polygene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From paulmer...@apache.org
Subject [3/4] zest-qi4j git commit: ZEST-30 Scala Support Documentation
Date Tue, 07 Jul 2015 13:10:49 GMT
ZEST-30 Scala Support Documentation


Project: http://git-wip-us.apache.org/repos/asf/zest-qi4j/repo
Commit: http://git-wip-us.apache.org/repos/asf/zest-qi4j/commit/4bb1432f
Tree: http://git-wip-us.apache.org/repos/asf/zest-qi4j/tree/4bb1432f
Diff: http://git-wip-us.apache.org/repos/asf/zest-qi4j/diff/4bb1432f

Branch: refs/heads/develop
Commit: 4bb1432f664df18c4adea292b55ec0ef95a18e41
Parents: 8d225a2
Author: Paul Merlin <paulmerlin@apache.org>
Authored: Tue Jul 7 15:07:28 2015 +0200
Committer: Paul Merlin <paulmerlin@apache.org>
Committed: Tue Jul 7 15:07:28 2015 +0200

----------------------------------------------------------------------
 libraries/lang-scala/dev-status.xml             |  2 +-
 libraries/lang-scala/src/docs/lang-scala.txt    | 89 ++++++++++++++++++++
 .../scala/ExclamationGenericConcern.scala       |  3 +-
 .../qi4j/sample/scala/HelloThereConcern.scala   |  7 +-
 .../qi4j/sample/scala/HelloWorldComposite.scala |  2 +
 .../sample/scala/HelloWorldCompositeTest.java   |  6 ++
 .../qi4j/sample/scala/HelloWorldMixin2.scala    |  4 +-
 .../org/qi4j/sample/scala/TestEntity.scala      |  4 +-
 .../org/qi4j/sample/scala/TestService.scala     |  4 +-
 9 files changed, 112 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/4bb1432f/libraries/lang-scala/dev-status.xml
----------------------------------------------------------------------
diff --git a/libraries/lang-scala/dev-status.xml b/libraries/lang-scala/dev-status.xml
index 1a18f48..58fda09 100644
--- a/libraries/lang-scala/dev-status.xml
+++ b/libraries/lang-scala/dev-status.xml
@@ -24,7 +24,7 @@
     <codebase>beta</codebase>
 
     <!-- none, brief, good, complete -->
-    <documentation>none</documentation>
+    <documentation>brief</documentation>
 
     <!-- none, some, good, complete -->
     <unittests>some</unittests>

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/4bb1432f/libraries/lang-scala/src/docs/lang-scala.txt
----------------------------------------------------------------------
diff --git a/libraries/lang-scala/src/docs/lang-scala.txt b/libraries/lang-scala/src/docs/lang-scala.txt
index 83f9542..c4b3a8f 100644
--- a/libraries/lang-scala/src/docs/lang-scala.txt
+++ b/libraries/lang-scala/src/docs/lang-scala.txt
@@ -25,4 +25,93 @@
 source=libraries/lang-scala/dev-status.xml
 --------------
 
+The Scala Support Library allows Fragments and Composites to be written as Scala traits.
+
 include::../../build/docs/buildinfo/artifact.txt[]
+
+The Scala Support Library is a Generic mixin class that implements  Composites by delegating
to Scala traits.
+
+
+== Composition ==
+
+Example mixin declaration:
+[snippet,scala]
+----
+source=libraries/lang-scala/src/test/scala/org/qi4j/sample/scala/HelloWorldMixin2.scala
+tag=mixin
+----
+
+Example composite declaration:
+[snippet,scala]
+----
+source=libraries/lang-scala/src/test/scala/org/qi4j/sample/scala/HelloWorldComposite.scala
+tag=composite
+----
+
+Example typed concern:
+[snippet,scala]
+----
+source=libraries/lang-scala/src/test/scala/org/qi4j/sample/scala/HelloThereConcern.scala
+tag=typedconcern
+----
+
+Example generic concern with filter:
+[snippet,scala]
+----
+source=libraries/lang-scala/src/test/scala/org/qi4j/sample/scala/ExclamationGenericConcern.scala
+tag=genericconcern
+----
+
+And the assembly code.
+Note that the `ScalaTraitMixin` must be added.
+[snippet,java]
+----
+source=libraries/lang-scala/src/test/scala/org/qi4j/sample/scala/HelloWorldCompositeTest.java
+tag=composite
+----
+
+That pretty much covers the domain model part.
+Usage from Java is transparent, since it looks just like interfaces and classes.
+
+
+== Entity composites ==
+
+The following example separate between command interface (suggestions to change), events
(after the fact), and data, so they are in three separate traits below.
+Only commands are called by client code.
+
+[snippet,scala]
+----
+source=libraries/lang-scala/src/test/scala/org/qi4j/sample/scala/TestEntity.scala
+tag=entity
+----
+
+The `self` operator thing solves the `@This` injection requirements, although it doesn't
do private injections (i.e. the Entity *has* to extend Events and Data for it to work).
+
+Everything is statically typed.
+
+And the corresponding assembly code:
+
+[snippet,java]
+----
+source=libraries/lang-scala/src/test/scala/org/qi4j/sample/scala/HelloWorldCompositeTest.java
+tag=entity
+----
+
+
+== Services composites ==
+
+The following example is a pretty simple service written as a Scala trait:
+
+[snippet,scala]
+----
+source=libraries/lang-scala/src/test/scala/org/qi4j/sample/scala/TestService.scala
+tag=service
+----
+
+And the corresponding assembly code:
+
+[snippet,java]
+----
+source=libraries/lang-scala/src/test/scala/org/qi4j/sample/scala/HelloWorldCompositeTest.java
+tag=service
+----

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/4bb1432f/libraries/lang-scala/src/test/scala/org/qi4j/sample/scala/ExclamationGenericConcern.scala
----------------------------------------------------------------------
diff --git a/libraries/lang-scala/src/test/scala/org/qi4j/sample/scala/ExclamationGenericConcern.scala
b/libraries/lang-scala/src/test/scala/org/qi4j/sample/scala/ExclamationGenericConcern.scala
index 823592d..a87c91d 100644
--- a/libraries/lang-scala/src/test/scala/org/qi4j/sample/scala/ExclamationGenericConcern.scala
+++ b/libraries/lang-scala/src/test/scala/org/qi4j/sample/scala/ExclamationGenericConcern.scala
@@ -18,7 +18,7 @@ import org.qi4j.api.common.{AppliesToFilter, AppliesTo}
 /**
  * Add an exclamation mark to the returned string
  */
-
+// START SNIPPET: genericconcern
 @AppliesTo(Array(classOf[ StringFilter ]))
 class ExclamationGenericConcern
   extends GenericConcern
@@ -33,3 +33,4 @@ class StringFilter
     .getReturnType
     .equals(classOf[ String ])
 }
+// END SNIPPET: genericconcern

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/4bb1432f/libraries/lang-scala/src/test/scala/org/qi4j/sample/scala/HelloThereConcern.scala
----------------------------------------------------------------------
diff --git a/libraries/lang-scala/src/test/scala/org/qi4j/sample/scala/HelloThereConcern.scala
b/libraries/lang-scala/src/test/scala/org/qi4j/sample/scala/HelloThereConcern.scala
index 2cf07bd..33e7981 100644
--- a/libraries/lang-scala/src/test/scala/org/qi4j/sample/scala/HelloThereConcern.scala
+++ b/libraries/lang-scala/src/test/scala/org/qi4j/sample/scala/HelloThereConcern.scala
@@ -13,11 +13,10 @@ package org.qi4j.sample.scala
 
 import org.qi4j.api.concern.ConcernOf
 
-/**
- * TODO
- */
+// START SNIPPET: typedconcern
 class HelloThereConcern
   extends ConcernOf[ HelloWorldMixin2 ] with HelloWorldMixin2
 {
   override def sayHello(name: String ) = next.sayHello("there " + name)
-}
\ No newline at end of file
+}
+// END SNIPPET: typedconcern

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/4bb1432f/libraries/lang-scala/src/test/scala/org/qi4j/sample/scala/HelloWorldComposite.scala
----------------------------------------------------------------------
diff --git a/libraries/lang-scala/src/test/scala/org/qi4j/sample/scala/HelloWorldComposite.scala
b/libraries/lang-scala/src/test/scala/org/qi4j/sample/scala/HelloWorldComposite.scala
index 1321f42..0a209d8 100644
--- a/libraries/lang-scala/src/test/scala/org/qi4j/sample/scala/HelloWorldComposite.scala
+++ b/libraries/lang-scala/src/test/scala/org/qi4j/sample/scala/HelloWorldComposite.scala
@@ -14,6 +14,8 @@ package org.qi4j.sample.scala
 import org.qi4j.api.composite.TransientComposite
 import org.qi4j.api.concern.Concerns
 
+// START SNIPPET: composite
 @Concerns(Array(classOf[ HelloThereConcern ]))
 trait HelloWorldComposite
   extends TransientComposite with HelloWorldMixin with HelloWorldMixin2
+// END SNIPPET: composite

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/4bb1432f/libraries/lang-scala/src/test/scala/org/qi4j/sample/scala/HelloWorldCompositeTest.java
----------------------------------------------------------------------
diff --git a/libraries/lang-scala/src/test/scala/org/qi4j/sample/scala/HelloWorldCompositeTest.java
b/libraries/lang-scala/src/test/scala/org/qi4j/sample/scala/HelloWorldCompositeTest.java
index b627318..e418bdd 100644
--- a/libraries/lang-scala/src/test/scala/org/qi4j/sample/scala/HelloWorldCompositeTest.java
+++ b/libraries/lang-scala/src/test/scala/org/qi4j/sample/scala/HelloWorldCompositeTest.java
@@ -41,9 +41,11 @@ public class HelloWorldCompositeTest
             public void assemble( ModuleAssembly module )
                 throws AssemblyException
             {
+                // START SNIPPET: composite
                 module.transients( HelloWorldComposite.class, HelloWorldComposite2.class
).
                     withMixins( ScalaTraitMixin.class ).
                     withConcerns( ExclamationGenericConcern.class );
+                // END SNIPPET: composite
             }
         };
 
@@ -74,8 +76,12 @@ public class HelloWorldCompositeTest
             public void assemble( ModuleAssembly module )
                 throws AssemblyException
             {
+                // START SNIPPET: entity
                 module.entities( TestEntity.class ).withMixins( ScalaTraitMixin.class );
+                // END SNIPPET: entity
+                // START SNIPPET: service
                 module.services( TestService.class ).withMixins( ScalaTraitMixin.class );
+                // END SNIPPET: service
 
                 new EntityTestAssembler().assemble( module );
                 new RdfMemoryStoreAssembler().assemble( module );

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/4bb1432f/libraries/lang-scala/src/test/scala/org/qi4j/sample/scala/HelloWorldMixin2.scala
----------------------------------------------------------------------
diff --git a/libraries/lang-scala/src/test/scala/org/qi4j/sample/scala/HelloWorldMixin2.scala
b/libraries/lang-scala/src/test/scala/org/qi4j/sample/scala/HelloWorldMixin2.scala
index 389943d..aeb8250 100644
--- a/libraries/lang-scala/src/test/scala/org/qi4j/sample/scala/HelloWorldMixin2.scala
+++ b/libraries/lang-scala/src/test/scala/org/qi4j/sample/scala/HelloWorldMixin2.scala
@@ -13,7 +13,9 @@ package org.qi4j.sample.scala
 
 import org.qi4j.library.constraints.annotation.MaxLength
 
+// START SNIPPET: mixin
 trait HelloWorldMixin2
 {
   def sayHello(@MaxLength(10) name: String ): String = "Hello " + name
-}
\ No newline at end of file
+}
+// END SNIPPET: mixin

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/4bb1432f/libraries/lang-scala/src/test/scala/org/qi4j/sample/scala/TestEntity.scala
----------------------------------------------------------------------
diff --git a/libraries/lang-scala/src/test/scala/org/qi4j/sample/scala/TestEntity.scala b/libraries/lang-scala/src/test/scala/org/qi4j/sample/scala/TestEntity.scala
index d7e0da4..1440c8d 100644
--- a/libraries/lang-scala/src/test/scala/org/qi4j/sample/scala/TestEntity.scala
+++ b/libraries/lang-scala/src/test/scala/org/qi4j/sample/scala/TestEntity.scala
@@ -19,6 +19,7 @@ import org.qi4j.api.property.Property
 /**
  * Test entity
  */
+ // START SNIPPET: entity
 trait TestEntity
   extends EntityComposite with Commands with Events with Data
 
@@ -57,4 +58,5 @@ trait Events
     // Register change by modifying state
     foo = newValue
   }
-}
\ No newline at end of file
+}
+// END SNIPPET: entity

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/4bb1432f/libraries/lang-scala/src/test/scala/org/qi4j/sample/scala/TestService.scala
----------------------------------------------------------------------
diff --git a/libraries/lang-scala/src/test/scala/org/qi4j/sample/scala/TestService.scala b/libraries/lang-scala/src/test/scala/org/qi4j/sample/scala/TestService.scala
index fdbd54b..9c77111 100644
--- a/libraries/lang-scala/src/test/scala/org/qi4j/sample/scala/TestService.scala
+++ b/libraries/lang-scala/src/test/scala/org/qi4j/sample/scala/TestService.scala
@@ -16,8 +16,10 @@ import org.qi4j.api.service.ServiceComposite
 /**
  * Test service that repeats given string
  */
+ // START SNIPPET: service
 trait TestService
   extends ServiceComposite
 {
   def repeat(input: String ): String = input + input
-}
\ No newline at end of file
+}
+// END SNIPPET: service


Mime
View raw message