You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@polygene.apache.org by pa...@apache.org on 2015/11/16 17:08:39 UTC

[1/2] zest-java git commit: Minor edits (unnecessary/missing generics, dead code...) around @This injection

Repository: zest-java
Updated Branches:
  refs/heads/develop 73b7f1969 -> 3c6c11f4d


Minor edits (unnecessary/missing generics, dead code...) around @This injection


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

Branch: refs/heads/develop
Commit: f871f7a8e2077145894438fe27424c1dcd2eaece
Parents: 73b7f19
Author: Paul Merlin <pa...@apache.org>
Authored: Mon Nov 16 16:05:45 2015 +0100
Committer: Paul Merlin <pa...@apache.org>
Committed: Mon Nov 16 16:05:45 2015 +0100

----------------------------------------------------------------------
 .../runtime/composite/ConstructorsModel.java    | 31 +++++++-------------
 .../injection/InjectedParametersModel.java      | 16 ----------
 2 files changed, 10 insertions(+), 37 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zest-java/blob/f871f7a8/core/runtime/src/main/java/org/apache/zest/runtime/composite/ConstructorsModel.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/composite/ConstructorsModel.java b/core/runtime/src/main/java/org/apache/zest/runtime/composite/ConstructorsModel.java
index 435a020..faf0754 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/composite/ConstructorsModel.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/composite/ConstructorsModel.java
@@ -56,24 +56,24 @@ public final class ConstructorsModel
     implements Binder, Dependencies, VisitableHierarchy<Object, Object>
 {
     @SuppressWarnings( "raw" )
-    private final Class fragmentClass;
+    private final Class<?> fragmentClass;
     private final List<ConstructorModel> constructorModels;
     private List<ConstructorModel> boundConstructors;
 
     @SuppressWarnings( { "raw", "unchecked" } )
-    public ConstructorsModel( Class fragmentClass )
+    public ConstructorsModel( Class<?> fragmentClass )
     {
         this.fragmentClass = fragmentClass;
         validate( fragmentClass );
         constructorModels = new ArrayList<>();
-        Constructor[] realConstructors = this.fragmentClass.getDeclaredConstructors();
-        Class injectionClass = FragmentClassLoader.getSourceClass( fragmentClass );
-        for( Constructor constructor : realConstructors )
+        Constructor<?>[] realConstructors = this.fragmentClass.getDeclaredConstructors();
+        Class<?> injectionClass = FragmentClassLoader.getSourceClass( fragmentClass );
+        for( Constructor<?> constructor : realConstructors )
         {
             constructor.setAccessible( true );
             try
             {
-                Constructor injectionConstructor = injectionClass.getDeclaredConstructor( constructor.getParameterTypes() );
+                Constructor<?> injectionConstructor = injectionClass.getDeclaredConstructor( constructor.getParameterTypes() );
                 injectionConstructor.setAccessible( true );
                 ConstructorModel constructorModel = newConstructorModel( this.fragmentClass, constructor,
                                                                          injectionConstructor );
@@ -91,7 +91,7 @@ public final class ConstructorsModel
     }
 
     @SuppressWarnings( "raw" )
-    private void validate( Class fragmentClass )
+    private void validate( Class<?> fragmentClass )
     {
         // Ensure that the fragment class is not an inner class, in which case we should give a reasonable exception
         if( fragmentClass.getDeclaringClass() == null )
@@ -113,23 +113,12 @@ public final class ConstructorsModel
             return constructorModels.stream().flatMap( ConstructorModel::dependencies );
         }
         return boundConstructors.stream().flatMap( ConstructorModel::dependencies );
-
-//        Function<ConstructorModel, Iterable<DependencyModel>> constructorDependencies = new Function<ConstructorModel, Iterable<DependencyModel>>()
-//        {
-//            @Override
-//            public Iterable<DependencyModel> apply( ConstructorModel constructorModel )
-//            {
-//                return constructorModel.dependencies();
-//            }
-//        };
-//
-//        return Iterables.flattenIterables( Iterables.map( constructorDependencies, boundConstructors == null ? constructorModels : boundConstructors ) );
     }
 
     @SuppressWarnings( "raw" )
-    private ConstructorModel newConstructorModel( Class fragmentClass,
-                                                  Constructor realConstructor,
-                                                  Constructor injectedConstructor
+    private ConstructorModel newConstructorModel( Class<?> fragmentClass,
+                                                  Constructor<?> realConstructor,
+                                                  Constructor<?> injectedConstructor
     )
     {
         int idx = 0;

http://git-wip-us.apache.org/repos/asf/zest-java/blob/f871f7a8/core/runtime/src/main/java/org/apache/zest/runtime/injection/InjectedParametersModel.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/injection/InjectedParametersModel.java b/core/runtime/src/main/java/org/apache/zest/runtime/injection/InjectedParametersModel.java
index db1665c..4fdd2a8 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/injection/InjectedParametersModel.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/injection/InjectedParametersModel.java
@@ -15,14 +15,11 @@
 package org.apache.zest.runtime.injection;
 
 import java.util.ArrayList;
-import java.util.Collection;
 import java.util.List;
-import java.util.function.Predicate;
 import java.util.stream.Stream;
 import org.apache.zest.api.composite.InjectedParametersDescriptor;
 import org.apache.zest.functional.HierarchicalVisitor;
 import org.apache.zest.functional.VisitableHierarchy;
-import org.apache.zest.runtime.composite.ConstructorModel;
 
 /**
  * JAVADOC
@@ -81,19 +78,6 @@ public final class InjectedParametersModel
         return visitor.visitLeave( this );
     }
 
-    public Collection<DependencyModel> filter( Predicate<DependencyModel> specification )
-    {
-        ArrayList<DependencyModel> result = new ArrayList<DependencyModel>();
-        for( DependencyModel model : parameterDependencies )
-        {
-            if( specification.test( model ) )
-            {
-                result.add( model );
-            }
-        }
-        return result;
-    }
-
     @Override
     public String toString()
     {


[2/2] zest-java git commit: Tighten private mixins and @This injection tests

Posted by pa...@apache.org.
Tighten private mixins and @This injection tests


Project: http://git-wip-us.apache.org/repos/asf/zest-java/repo
Commit: http://git-wip-us.apache.org/repos/asf/zest-java/commit/3c6c11f4
Tree: http://git-wip-us.apache.org/repos/asf/zest-java/tree/3c6c11f4
Diff: http://git-wip-us.apache.org/repos/asf/zest-java/diff/3c6c11f4

Branch: refs/heads/develop
Commit: 3c6c11f4d3cc7d2fb3421e1bb2671560ecfb649c
Parents: f871f7a
Author: Paul Merlin <pa...@apache.org>
Authored: Mon Nov 16 16:23:51 2015 +0100
Committer: Paul Merlin <pa...@apache.org>
Committed: Mon Nov 16 16:23:51 2015 +0100

----------------------------------------------------------------------
 .../ConstructorInjectionOfThisTest.java         | 72 +++++++++++++++++---
 .../zest/runtime/mixin/PrivateMixinTest.java    | 38 +++++++++--
 2 files changed, 92 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zest-java/blob/3c6c11f4/core/runtime/src/test/java/org/apache/zest/runtime/injection/ConstructorInjectionOfThisTest.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/test/java/org/apache/zest/runtime/injection/ConstructorInjectionOfThisTest.java b/core/runtime/src/test/java/org/apache/zest/runtime/injection/ConstructorInjectionOfThisTest.java
index 308e506..43ae9cb 100644
--- a/core/runtime/src/test/java/org/apache/zest/runtime/injection/ConstructorInjectionOfThisTest.java
+++ b/core/runtime/src/test/java/org/apache/zest/runtime/injection/ConstructorInjectionOfThisTest.java
@@ -4,7 +4,7 @@
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  *
- *     You may obtain a copy of the License at 
+ *     You may obtain a copy of the License at
  *     http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
@@ -13,20 +13,23 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package org.apache.zest.runtime.injection;
 
 import org.junit.Test;
 import org.apache.zest.api.activation.ActivationException;
+import org.apache.zest.api.common.UseDefaults;
 import org.apache.zest.api.concern.ConcernOf;
 import org.apache.zest.api.injection.scope.This;
-import org.apache.zest.api.mixin.Mixins;
 import org.apache.zest.api.mixin.NoopMixin;
+import org.apache.zest.api.property.Property;
 import org.apache.zest.api.sideeffect.SideEffectOf;
 import org.apache.zest.api.structure.Module;
 import org.apache.zest.bootstrap.AssemblyException;
 import org.apache.zest.bootstrap.ModuleAssembly;
 import org.apache.zest.bootstrap.SingletonAssembler;
+import org.junit.Ignore;
+
+import static org.junit.Assert.assertFalse;
 
 /**
  * This test is created in response to QI-359
@@ -35,7 +38,7 @@ public class ConstructorInjectionOfThisTest
 {
 
     @Test
-    public void givenConcernWithThisInConstructorWhenCreatingModelExpectException()
+    public void givenMixinWithThisInConstructorWhenCreatingModelExpectNoException()
         throws ActivationException, AssemblyException
     {
         SingletonAssembler singletonAssembler = new SingletonAssembler()
@@ -45,7 +48,7 @@ public class ConstructorInjectionOfThisTest
             public void assemble( ModuleAssembly module )
                 throws AssemblyException
             {
-                module.values( Does.class ).withConcerns( DoesConcern.class );
+                module.values( Does.class ).withMixins( DoesMixin.class );
             }
         };
         Module module = singletonAssembler.application().findModule( "Layer 1", "Module 1" );
@@ -53,8 +56,27 @@ public class ConstructorInjectionOfThisTest
         does.doSomething();
     }
 
-    @Test
-    public void givenSideEffectWithThisInConstructorWhenCreatingModelExpectException()
+    @Test @Ignore
+    public void givenConcernWithThisInConstructorWhenCreatingModelExpectNoException()
+        throws ActivationException, AssemblyException
+    {
+        SingletonAssembler singletonAssembler = new SingletonAssembler()
+        {
+
+            @Override
+            public void assemble( ModuleAssembly module )
+                throws AssemblyException
+            {
+                module.values( Does.class ).withMixins( NoopMixin.class ).withConcerns( DoesConcern.class );
+            }
+        };
+        Module module = singletonAssembler.application().findModule( "Layer 1", "Module 1" );
+        Does does = module.newValue( Does.class );
+        does.doSomething();
+    }
+
+    @Test @Ignore
+    public void givenSideEffectWithThisInConstructorWhenCreatingModelExpectNoException()
         throws ActivationException, AssemblyException
     {
         SingletonAssembler singletonAssembler = new SingletonAssembler()
@@ -64,7 +86,7 @@ public class ConstructorInjectionOfThisTest
             public void assemble( ModuleAssembly module )
                 throws AssemblyException
             {
-                module.values( Does.class ).withSideEffects( DoesSideEffect.class );
+                module.values( Does.class ).withMixins( NoopMixin.class ).withSideEffects( DoesSideEffect.class );
             }
         };
         Module module = singletonAssembler.application().findModule( "Layer 1", "Module 1" );
@@ -72,7 +94,29 @@ public class ConstructorInjectionOfThisTest
         does.doSomething();
     }
 
-    public static class DoesConcern extends ConcernOf<Does>
+    public static class DoesMixin
+        implements Does
+    {
+        private DoesPrivateFragment doesPrivateFragment;
+
+        public DoesMixin( @This DoesPrivateFragment doesPrivateFragment )
+        {
+            if( doesPrivateFragment == null )
+            {
+                throw new NullPointerException();
+            }
+            this.doesPrivateFragment = doesPrivateFragment;
+        }
+
+        @Override
+        public void doSomething()
+        {
+            assertFalse( doesPrivateFragment.someState().get() );
+        }
+    }
+
+    public static class DoesConcern
+        extends ConcernOf<Does>
         implements Does
     {
 
@@ -92,7 +136,8 @@ public class ConstructorInjectionOfThisTest
         }
     }
 
-    public static class DoesSideEffect extends SideEffectOf<Does>
+    public static class DoesSideEffect
+        extends SideEffectOf<Does>
         implements Does
     {
 
@@ -112,7 +157,12 @@ public class ConstructorInjectionOfThisTest
         }
     }
 
-    @Mixins( NoopMixin.class )
+    public interface DoesPrivateFragment
+    {
+        @UseDefaults
+        Property<Boolean> someState();
+    }
+
     public interface Does
     {
         void doSomething();

http://git-wip-us.apache.org/repos/asf/zest-java/blob/3c6c11f4/core/runtime/src/test/java/org/apache/zest/runtime/mixin/PrivateMixinTest.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/test/java/org/apache/zest/runtime/mixin/PrivateMixinTest.java b/core/runtime/src/test/java/org/apache/zest/runtime/mixin/PrivateMixinTest.java
index 9ed5207..98a24d5 100644
--- a/core/runtime/src/test/java/org/apache/zest/runtime/mixin/PrivateMixinTest.java
+++ b/core/runtime/src/test/java/org/apache/zest/runtime/mixin/PrivateMixinTest.java
@@ -12,7 +12,6 @@
  * limitations under the License.
  *
  */
-
 package org.apache.zest.runtime.mixin;
 
 import org.junit.Test;
@@ -33,6 +32,7 @@ import static org.junit.Assert.assertThat;
 public class PrivateMixinTest
     extends AbstractZestTest
 {
+    @Override
     public void assemble( ModuleAssembly module )
         throws AssemblyException
     {
@@ -43,10 +43,10 @@ public class PrivateMixinTest
      * Tests that private mixins are injected correctly.
      */
     @Test
-    public void privateMixinInjection()
+    public void privateMixinFieldAndConstructorInjection()
     {
         SpeakComposite test = module.newTransient( SpeakComposite.class );
-        assertThat( "Speak", test.speak(), is( equalTo( "I say it works" ) ) );
+        assertThat( "Speak", test.speak(), is( equalTo( "I say it works!" ) ) );
     }
 
     @Mixins( SpeakMixin.class )
@@ -58,21 +58,27 @@ public class PrivateMixinTest
     public static class SpeakMixin
         implements Speak
     {
-        @This
-        Word word;
+        private final Word word;
+        @This Punctuation punctuation;
+
+        public SpeakMixin( @This Word word )
+        {
+            this.word = word;
+        }
 
+        @Override
         public String speak()
         {
-            return "I say " + word.get();
+            return "I say " + word.get() + punctuation.punctuate();
         }
     }
 
-    @Mixins( { WordMixin.class } )
     public interface SpeakComposite
         extends Speak, TransientComposite
     {
     }
 
+    @Mixins( WordMixin.class )
     public interface Word
     {
         String get();
@@ -81,9 +87,27 @@ public class PrivateMixinTest
     public static class WordMixin
         implements Word
     {
+        @Override
         public String get()
         {
             return "it works";
         }
     }
+
+    @Mixins( PunctuationMixin.class )
+    public interface Punctuation
+    {
+        String punctuate();
+    }
+
+    public static class PunctuationMixin
+        implements Punctuation
+    {
+        @Override
+        public String punctuate()
+        {
+            return "!";
+        }
+
+    }
 }