polygene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From paulmer...@apache.org
Subject [13/14] zest-java git commit: get rid of org.apache.zest.runtime.legacy.Specifications
Date Mon, 28 Nov 2016 16:07:58 GMT
get rid of org.apache.zest.runtime.legacy.Specifications

and simplify


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

Branch: refs/heads/develop
Commit: b4c26443ad908f91bb5ab38fcc898b55d7fd722c
Parents: d7f000c
Author: Paul Merlin <paulmerlin@apache.org>
Authored: Mon Nov 28 13:23:49 2016 +0100
Committer: Paul Merlin <paulmerlin@apache.org>
Committed: Mon Nov 28 13:23:49 2016 +0100

----------------------------------------------------------------------
 .../org/apache/zest/api/util/Annotations.java   |  5 +++
 .../bootstrap/CompositeAssemblyImpl.java        | 19 ++++-------
 .../runtime/composite/ConstructorsModel.java    |  9 ++---
 .../zest/runtime/composite/MixinModel.java      |  2 +-
 .../zest/runtime/injection/DependencyModel.java | 11 ------
 .../runtime/injection/InjectedFieldsModel.java  | 11 +++---
 .../runtime/injection/InjectedMethodsModel.java |  6 ++--
 .../ServiceInjectionProviderFactory.java        |  7 ++--
 .../zest/runtime/legacy/Specifications.java     | 36 --------------------
 .../zest/runtime/service/ServiceModel.java      |  5 +--
 10 files changed, 26 insertions(+), 85 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zest-java/blob/b4c26443/core/api/src/main/java/org/apache/zest/api/util/Annotations.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/zest/api/util/Annotations.java b/core/api/src/main/java/org/apache/zest/api/util/Annotations.java
index 838f7e8..a5598d7 100644
--- a/core/api/src/main/java/org/apache/zest/api/util/Annotations.java
+++ b/core/api/src/main/java/org/apache/zest/api/util/Annotations.java
@@ -43,6 +43,11 @@ public final class Annotations
     public static final Function<Type, Stream<Annotation>> ANNOTATIONS_OF =
         Classes.forTypes( type -> Arrays.stream( Classes.RAW_CLASS.apply( type ).getAnnotations()
) );
 
+    public static Predicate<Annotation> typeHasAnnotation( Class<? extends Annotation>
annotationType )
+    {
+        return element -> hasAnnotation( annotationType ).test( type().apply( element
) );
+    }
+
     public static Predicate<AnnotatedElement> hasAnnotation( final Class<? extends
Annotation> annotationType )
     {
         return element -> element.getAnnotation( annotationType ) != null;

http://git-wip-us.apache.org/repos/asf/zest-java/blob/b4c26443/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/CompositeAssemblyImpl.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/CompositeAssemblyImpl.java
b/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/CompositeAssemblyImpl.java
index 6f4bbbf..b0731c3 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/CompositeAssemblyImpl.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/CompositeAssemblyImpl.java
@@ -97,16 +97,14 @@ import org.apache.zest.runtime.property.PropertiesModel;
 import org.apache.zest.runtime.property.PropertyModel;
 
 import static java.util.stream.Stream.concat;
-import static org.apache.zest.api.util.Annotations.hasAnnotation;
 import static org.apache.zest.api.util.Annotations.isType;
-import static org.apache.zest.api.util.Annotations.type;
+import static org.apache.zest.api.util.Annotations.typeHasAnnotation;
 import static org.apache.zest.api.util.Classes.classHierarchy;
 import static org.apache.zest.api.util.Classes.interfacesOf;
 import static org.apache.zest.api.util.Classes.isAssignableFrom;
 import static org.apache.zest.api.util.Classes.typeOf;
 import static org.apache.zest.api.util.Classes.typesOf;
 import static org.apache.zest.api.util.Classes.wrapperClass;
-import static org.apache.zest.runtime.legacy.Specifications.translate;
 
 /**
  * Declaration of a Composite.
@@ -247,19 +245,16 @@ public abstract class CompositeAssemblyImpl
                         mixinsModel
                     );
 
-                    DependencyModel.InjectionTypeFunction injectionTypeFunction = new DependencyModel.InjectionTypeFunction();
-                    DependencyModel.ScopeSpecification thisSpec = new DependencyModel.ScopeSpecification(
This.class );
                     Stream<? extends Dependencies> source = Stream.of( methodComposite,
mixinModel );
                     source.flatMap( Dependencies::dependencies )
-                        .filter( thisSpec )
-                        .map( injectionTypeFunction )
-                        .forEach( thisDependencies::add );
+                          .filter( new DependencyModel.ScopeSpecification( This.class ) )
+                          .map( DependencyModel::rawInjectionType )
+                          .forEach( thisDependencies::add );
 
                     interfacesOf( mixinModel.mixinClass() )
                         .map( Classes.RAW_CLASS )
                         .filter( clazz -> Stream.of( Initializable.class, Lifecycle.class,
InvocationHandler.class )
-                            .noneMatch( c -> c
-                                .equals( clazz ) ) )
+                                                .noneMatch( c -> c.equals( clazz ) ) )
                         .forEach( thisDependencies::add );
 
                     compositeMethodsModel.addMethod( methodComposite );
@@ -541,7 +536,7 @@ public abstract class CompositeAssemblyImpl
 
         List<AbstractConstraintModel> constraintModels = new ArrayList<>();
         List<Annotation> filtered = constraintAnnotations
-            .filter( translate( type(), hasAnnotation( ConstraintDeclaration.class ) ) )
+            .filter( typeHasAnnotation( ConstraintDeclaration.class ) )
             .collect( Collectors.toList() );
 
         // TODO: This massive block below should be cleaned up.
@@ -577,7 +572,7 @@ public abstract class CompositeAssemblyImpl
             // No implementation found!
             // Check if if it's a composite constraints
             if( Arrays.stream( annotationType.getAnnotations() )
-                .anyMatch( translate( type(), hasAnnotation( ConstraintDeclaration.class
) ) ) )
+                .anyMatch( typeHasAnnotation( ConstraintDeclaration.class ) ) )
             {
                 ValueConstraintsModel valueConstraintsModel = constraintsFor(
                     Arrays.stream( annotationType.getAnnotations() ),

http://git-wip-us.apache.org/repos/asf/zest-java/blob/b4c26443/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 5608027..db6c2e1 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
@@ -30,14 +30,12 @@ import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.List;
-import java.util.function.Predicate;
 import java.util.stream.Stream;
 import org.apache.zest.api.common.ConstructionException;
 import org.apache.zest.api.composite.CompositeDescriptor;
 import org.apache.zest.api.composite.InvalidCompositeException;
 import org.apache.zest.api.injection.InjectionScope;
 import org.apache.zest.api.injection.scope.Uses;
-import org.apache.zest.api.util.Annotations;
 import org.apache.zest.api.util.Classes;
 import org.apache.zest.bootstrap.BindingException;
 import org.apache.zest.functional.HierarchicalVisitor;
@@ -48,10 +46,11 @@ import org.apache.zest.runtime.injection.DependencyModel;
 import org.apache.zest.runtime.injection.InjectedParametersModel;
 import org.apache.zest.runtime.injection.InjectionContext;
 import org.apache.zest.runtime.injection.ParameterizedTypeInstance;
-import org.apache.zest.runtime.legacy.Specifications;
 import org.apache.zest.runtime.model.Binder;
 import org.apache.zest.runtime.model.Resolution;
 
+import static org.apache.zest.api.util.Annotations.typeHasAnnotation;
+
 /**
  * JAVADOC
  */
@@ -129,10 +128,8 @@ public final class ConstructorsModel
         Annotation[][] parameterAnnotations = injectedConstructor.getParameterAnnotations();
         for( Type type : injectedConstructor.getGenericParameterTypes() )
         {
-            Predicate<Annotation> injectionAnnotationSpec = Specifications.translate(
-                Annotations.type(), Annotations.hasAnnotation( InjectionScope.class ) );
             Annotation injectionAnnotation = Stream.of( parameterAnnotations[ idx ] )
-                                                   .filter( injectionAnnotationSpec )
+                                                   .filter( typeHasAnnotation( InjectionScope.class
) )
                                                    .findFirst().orElse( null );
 
             if( injectionAnnotation == null )

http://git-wip-us.apache.org/repos/asf/zest-java/blob/b4c26443/core/runtime/src/main/java/org/apache/zest/runtime/composite/MixinModel.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/composite/MixinModel.java
b/core/runtime/src/main/java/org/apache/zest/runtime/composite/MixinModel.java
index 9ce738b..cf6af21 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/composite/MixinModel.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/composite/MixinModel.java
@@ -159,7 +159,7 @@ public final class MixinModel
         return dependencies()
             .filter( new DependencyModel.ScopeSpecification( This.class ) )
             .distinct()
-            .map( new DependencyModel.InjectionTypeFunction() )
+            .map( DependencyModel::rawInjectionType )
             .collect( Collectors.toList() );
     }
 

http://git-wip-us.apache.org/repos/asf/zest-java/blob/b4c26443/core/runtime/src/main/java/org/apache/zest/runtime/injection/DependencyModel.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/injection/DependencyModel.java
b/core/runtime/src/main/java/org/apache/zest/runtime/injection/DependencyModel.java
index 23c5659..bc8f914 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/injection/DependencyModel.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/injection/DependencyModel.java
@@ -26,7 +26,6 @@ import java.lang.reflect.Type;
 import java.lang.reflect.TypeVariable;
 import java.util.Collections;
 import java.util.Iterator;
-import java.util.function.Function;
 import java.util.function.Predicate;
 import java.util.stream.Stream;
 import org.apache.zest.api.common.ConstructionException;
@@ -419,14 +418,4 @@ public final class DependencyModel
             return model.hasScope( scope );
         }
     }
-
-    public static class InjectionTypeFunction
-        implements Function<DependencyModel, Class<?>>
-    {
-        @Override
-        public Class<?> apply( DependencyModel dependencyModel )
-        {
-            return dependencyModel.rawInjectionType();
-        }
-    }
 }

http://git-wip-us.apache.org/repos/asf/zest-java/blob/b4c26443/core/runtime/src/main/java/org/apache/zest/runtime/injection/InjectedFieldsModel.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/injection/InjectedFieldsModel.java
b/core/runtime/src/main/java/org/apache/zest/runtime/injection/InjectedFieldsModel.java
index bcaf027..125e73a 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/injection/InjectedFieldsModel.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/injection/InjectedFieldsModel.java
@@ -28,6 +28,7 @@ import java.lang.reflect.TypeVariable;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
+import java.util.Objects;
 import java.util.stream.Stream;
 import org.apache.zest.api.injection.InjectionScope;
 import org.apache.zest.api.util.Classes;
@@ -35,9 +36,7 @@ import org.apache.zest.api.util.Fields;
 import org.apache.zest.functional.HierarchicalVisitor;
 import org.apache.zest.functional.VisitableHierarchy;
 
-import static org.apache.zest.api.util.Annotations.hasAnnotation;
-import static org.apache.zest.api.util.Annotations.type;
-import static org.apache.zest.runtime.legacy.Specifications.translate;
+import static org.apache.zest.api.util.Annotations.typeHasAnnotation;
 
 /**
  * JAVADOC
@@ -51,9 +50,9 @@ public final class InjectedFieldsModel
     {
         Fields.fieldsOf( fragmentClass ).forEach( field ->
             Arrays.stream( field.getAnnotations() )
-                .filter( translate( type(), hasAnnotation( InjectionScope.class ) ) )
-                .filter( annot -> annot != null )
-                .forEach( injectionAnnotation ->  addModel( fragmentClass, field, injectionAnnotation
)
+                  .filter( typeHasAnnotation( InjectionScope.class ) )
+                  .filter( Objects::nonNull )
+                  .forEach( injectionAnnotation ->  addModel( fragmentClass, field, injectionAnnotation
)
             )
         );
     }

http://git-wip-us.apache.org/repos/asf/zest-java/blob/b4c26443/core/runtime/src/main/java/org/apache/zest/runtime/injection/InjectedMethodsModel.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/injection/InjectedMethodsModel.java
b/core/runtime/src/main/java/org/apache/zest/runtime/injection/InjectedMethodsModel.java
index 4615c0c..b303ea6 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/injection/InjectedMethodsModel.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/injection/InjectedMethodsModel.java
@@ -30,14 +30,12 @@ import java.util.List;
 import java.util.Optional;
 import java.util.stream.Stream;
 import org.apache.zest.api.injection.InjectionScope;
-import org.apache.zest.api.util.Annotations;
 import org.apache.zest.api.util.Classes;
 import org.apache.zest.api.util.Methods;
 import org.apache.zest.functional.HierarchicalVisitor;
-import org.apache.zest.runtime.legacy.Specifications;
 import org.apache.zest.functional.VisitableHierarchy;
 
-import static org.apache.zest.api.util.Annotations.hasAnnotation;
+import static org.apache.zest.api.util.Annotations.typeHasAnnotation;
 
 /**
  * JAVADOC
@@ -60,7 +58,7 @@ public final class InjectedMethodsModel
                 for( int i = 0; i < parameterAnnotations.length; i++ )
                 {
                     Optional<Annotation> opt = Arrays.stream( parameterAnnotations[
i ] )
-                        .filter( Specifications.translate( Annotations.type(), hasAnnotation(
InjectionScope.class ) ) )
+                        .filter( typeHasAnnotation( InjectionScope.class ) )
                         .findFirst();
                     if( opt.isPresent() )
                     {

http://git-wip-us.apache.org/repos/asf/zest-java/blob/b4c26443/core/runtime/src/main/java/org/apache/zest/runtime/injection/provider/ServiceInjectionProviderFactory.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/injection/provider/ServiceInjectionProviderFactory.java
b/core/runtime/src/main/java/org/apache/zest/runtime/injection/provider/ServiceInjectionProviderFactory.java
index 9d0ed4f..85817d2 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/injection/provider/ServiceInjectionProviderFactory.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/injection/provider/ServiceInjectionProviderFactory.java
@@ -29,7 +29,6 @@ import java.util.stream.Stream;
 import org.apache.zest.api.service.NoSuchServiceException;
 import org.apache.zest.api.service.ServiceReference;
 import org.apache.zest.api.service.qualifier.Qualifier;
-import org.apache.zest.api.util.Annotations;
 import org.apache.zest.api.util.Classes;
 import org.apache.zest.bootstrap.InvalidInjectionException;
 import org.apache.zest.functional.Iterables;
@@ -37,10 +36,9 @@ import org.apache.zest.runtime.injection.DependencyModel;
 import org.apache.zest.runtime.injection.InjectionContext;
 import org.apache.zest.runtime.injection.InjectionProvider;
 import org.apache.zest.runtime.injection.InjectionProviderFactory;
-import org.apache.zest.runtime.legacy.Specifications;
 import org.apache.zest.runtime.model.Resolution;
 
-import static org.apache.zest.api.util.Annotations.hasAnnotation;
+import static org.apache.zest.api.util.Annotations.typeHasAnnotation;
 
 public final class ServiceInjectionProviderFactory
     implements InjectionProviderFactory
@@ -52,8 +50,7 @@ public final class ServiceInjectionProviderFactory
     {
         // TODO This could be changed to allow multiple @Qualifier annotations
         Annotation qualifierAnnotation = Stream.of( dependencyModel.annotations() )
-                                               .filter( Specifications.translate( Annotations.type(),
-                                                                                  hasAnnotation(
Qualifier.class ) ) )
+                                               .filter( typeHasAnnotation( Qualifier.class
) )
                                                .findFirst().orElse( null );
         Predicate<ServiceReference<?>> serviceQualifier = null;
         if( qualifierAnnotation != null )

http://git-wip-us.apache.org/repos/asf/zest-java/blob/b4c26443/core/runtime/src/main/java/org/apache/zest/runtime/legacy/Specifications.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/legacy/Specifications.java
b/core/runtime/src/main/java/org/apache/zest/runtime/legacy/Specifications.java
deleted file mode 100644
index ac2491e..0000000
--- a/core/runtime/src/main/java/org/apache/zest/runtime/legacy/Specifications.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- *  Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you 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
- *
- *       http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License.
- *
- *
- */
-package org.apache.zest.runtime.legacy;
-
-import java.util.function.Function;
-import java.util.function.Predicate;
-
-/**
- * Common generic specification expressions
- */
-public class Specifications
-{
-    public static <FROM, TO> Predicate<FROM> translate( final Function<FROM,
TO> function,
-                                                        final Predicate<? super TO>
specification
-    )
-    {
-        return item -> specification.test( function.apply( item ) );
-    }
-}

http://git-wip-us.apache.org/repos/asf/zest-java/blob/b4c26443/core/runtime/src/main/java/org/apache/zest/runtime/service/ServiceModel.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/service/ServiceModel.java
b/core/runtime/src/main/java/org/apache/zest/runtime/service/ServiceModel.java
index 5e9e1c0..2083c94 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/service/ServiceModel.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/service/ServiceModel.java
@@ -49,8 +49,6 @@ import org.apache.zest.runtime.injection.DependencyModel;
 import org.apache.zest.runtime.injection.InjectionContext;
 import org.apache.zest.runtime.property.PropertyInstance;
 
-import static org.apache.zest.runtime.legacy.Specifications.translate;
-
 /**
  * JAVADOC
  */
@@ -171,8 +169,7 @@ public final class ServiceModel extends CompositeModel
     public Class calculateConfigurationType()
     {
         DependencyModel.ScopeSpecification thisSpec = new DependencyModel.ScopeSpecification(
This.class );
-        Predicate<DependencyModel> configurationCheck =
-            translate( new DependencyModel.InjectionTypeFunction(), clazz -> clazz.equals(
Configuration.class ) );
+        Predicate<DependencyModel> configurationCheck = item -> item.rawInjectionType().equals(
Configuration.class );
         return dependencies().filter( thisSpec.and( configurationCheck ) )
             .filter( dependencyModel -> dependencyModel.rawInjectionType().equals( Configuration.class
) )
             .filter( dependencyModel -> dependencyModel.injectionType() instanceof ParameterizedType
)


Mime
View raw message