polygene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nic...@apache.org
Subject zest-java git commit: ZEST-118; Fixed some of the bugs that was introduced in the Iterable conversion to Stream.
Date Thu, 27 Aug 2015 05:18:52 GMT
Repository: zest-java
Updated Branches:
  refs/heads/develop 44742590e -> 360c40e39


ZEST-118; Fixed some of the bugs that was introduced in the Iterable conversion to Stream.


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

Branch: refs/heads/develop
Commit: 360c40e39f6840e4058089733e73fc8446dcfa44
Parents: 4474259
Author: Niclas Hedhman <niclas@hedhman.org>
Authored: Thu Aug 27 13:07:14 2015 +0800
Committer: Niclas Hedhman <niclas@hedhman.org>
Committed: Thu Aug 27 13:07:14 2015 +0800

----------------------------------------------------------------------
 .../zest/api/object/NoSuchObjectException.java  |  11 +-
 .../java/org/apache/zest/api/util/Classes.java  | 108 +++++++++++--------
 .../runtime/bootstrap/ServiceAssemblyImpl.java  |  10 +-
 .../zest/runtime/structure/ModuleInstance.java  |   4 +-
 .../zest/runtime/structure/TypeLookup.java      |  15 ++-
 .../helpers/JSONMapEntityStoreActivation.java   |   2 +-
 .../helpers/JSONMapEntityStoreMixin.java        |  12 +--
 7 files changed, 97 insertions(+), 65 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zest-java/blob/360c40e3/core/api/src/main/java/org/apache/zest/api/object/NoSuchObjectException.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/zest/api/object/NoSuchObjectException.java
b/core/api/src/main/java/org/apache/zest/api/object/NoSuchObjectException.java
index 35e2655..f6a823e 100644
--- a/core/api/src/main/java/org/apache/zest/api/object/NoSuchObjectException.java
+++ b/core/api/src/main/java/org/apache/zest/api/object/NoSuchObjectException.java
@@ -13,6 +13,8 @@
  */
 package org.apache.zest.api.object;
 
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
 import org.apache.zest.api.common.InvalidApplicationException;
 
 /**
@@ -26,10 +28,13 @@ public class NoSuchObjectException
     private final String objectType;
     private final String moduleName;
 
-    public NoSuchObjectException( String type, String moduleName )
+    public NoSuchObjectException( String type, String moduleName, Stream<Class<?>>
visible )
     {
-        super( "Could not find any visible Object of type [" + type + "] in module [" +
-               moduleName + "]." );
+        super( "Could not find any visible Object of type [" + type + "] in module ["
+               + moduleName
+               + "]. The visible types are: \n"
+               + visible.map( Class::getName ).collect( Collectors.joining("\n") )
+        );
         this.objectType = type;
         this.moduleName = moduleName;
     }

http://git-wip-us.apache.org/repos/asf/zest-java/blob/360c40e3/core/api/src/main/java/org/apache/zest/api/util/Classes.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/zest/api/util/Classes.java b/core/api/src/main/java/org/apache/zest/api/util/Classes.java
index 19180cb..4fece50 100644
--- a/core/api/src/main/java/org/apache/zest/api/util/Classes.java
+++ b/core/api/src/main/java/org/apache/zest/api/util/Classes.java
@@ -24,11 +24,9 @@ import java.lang.reflect.ParameterizedType;
 import java.lang.reflect.Type;
 import java.lang.reflect.TypeVariable;
 import java.lang.reflect.WildcardType;
-import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashMap;
 import java.util.LinkedHashSet;
-import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.function.Function;
@@ -175,12 +173,22 @@ public final class Classes
                 }
                 else
                 {
-                    Stream<Type> stream1 = Arrays.stream( clazz.getGenericInterfaces()
).flatMap( INTERFACES_OF );
-                    Stream<Type> stream2 = Stream.of( type )
-                        .map( RAW_CLASS )
-                        .map( Class::getSuperclass )
-                        .map( RAW_CLASS );
-                    return concat( stream1, stream2 );
+//                    Stream<Type> stream1 = Arrays.stream( clazz.getGenericInterfaces()
).flatMap( INTERFACES_OF );
+//                    Stream<Type> stream2 = Stream.of( type )
+//                        .map( RAW_CLASS )
+//                        .map( Class::getSuperclass )
+//                        .map( RAW_CLASS );
+//                    return concat( stream1, stream2 );
+
+                    return concat( Stream.of( clazz.getGenericInterfaces() ).flatMap( INTERFACES_OF
),
+                                   Stream.of( clazz.getSuperclass() ).flatMap( INTERFACES_OF
) );
+//                    return flatten(
+//                        flattenIterables(
+//                            map( INTERFACES_OF, iterable( clazz.getGenericInterfaces()
) )
+//                        ),
+//                        INTERFACES_OF.apply( RAW_CLASS.apply( type ).getSuperclass() )
+//                    );
+
                 }
             }
         }
@@ -192,12 +200,12 @@ public final class Classes
         if( clazz.isInterface() )
         {
             Stream<Type> intfaces = Arrays.stream( clazz.getGenericInterfaces() ).flatMap(
INTERFACES_OF );
-            return concat( Stream.of(clazz), intfaces );
+            return concat( Stream.of( clazz ), intfaces );
         }
         else
         {
             return concat( Stream.of( clazz ),
-                           Stream.of( type ).flatMap( CLASS_HIERARCHY ).flatMap( INTERFACES_OF
));
+                           Stream.of( type ).flatMap( CLASS_HIERARCHY ).flatMap( INTERFACES_OF
) );
         }
     };
 
@@ -223,12 +231,12 @@ public final class Classes
 
     public static Stream<? extends Type> interfacesOf( Type type )
     {
-        return Stream.of(type).flatMap( INTERFACES_OF );
+        return Stream.of( type ).flatMap( INTERFACES_OF );
     }
 
     public static Stream<Class<?>> classHierarchy( Class<?> type )
     {
-        return Stream.of(type).flatMap( CLASS_HIERARCHY );
+        return Stream.of( type ).flatMap( CLASS_HIERARCHY );
     }
 
     public static Type wrapperClass( Type type )
@@ -273,7 +281,7 @@ public final class Classes
 
     public static <T> Function<Type, Stream<T>> forTypes( final Function<Type,
Stream<T>> function )
     {
-        return type -> Stream.of(type).flatMap( TYPES_OF ).flatMap( function );
+        return type -> Stream.of( type ).flatMap( TYPES_OF ).flatMap( function );
     }
 
     @SuppressWarnings( "raw" )
@@ -361,8 +369,8 @@ public final class Classes
         return Stream.of( type )
             .flatMap( TYPES_OF )
             .map( RAW_CLASS )
-            .map( clazz -> clazz.getAnnotation(annotationClass))
-            .filter(  annot -> annot != null )
+            .map( clazz -> clazz.getAnnotation( annotationClass ) )
+            .filter( annot -> annot != null )
             .findAny().get();
 //
 //
@@ -404,7 +412,7 @@ public final class Classes
     @SuppressWarnings( "raw" )
     public static Type resolveTypeVariable( TypeVariable name, Class declaringClass, Class
topClass )
     {
-        Type type = resolveTypeVariable( name, declaringClass, new HashMap<TypeVariable,
Type>(), topClass );
+        Type type = resolveTypeVariable( name, declaringClass, new HashMap<>(), topClass
);
         if( type == null )
         {
             type = Object.class;
@@ -412,7 +420,6 @@ public final class Classes
         return type;
     }
 
-    @SuppressWarnings( "raw" )
     private static Type resolveTypeVariable( TypeVariable name,
                                              Class declaringClass,
                                              Map<TypeVariable, Type> mappings,
@@ -429,37 +436,30 @@ public final class Classes
             return resolvedType;
         }
 
-        Stream<? extends Type> stream1 = Arrays.stream( current.getGenericInterfaces()
)
+        Stream<? extends Type> stream = Arrays.stream( current.getGenericInterfaces()
)
             .flatMap( INTERFACES_OF )
             .distinct();
 
-        return concat( Stream.of(current.getGenericSuperclass()), stream1)
-                .map( type ->
-                      {
-                          Class subClass;
-                          if( type instanceof ParameterizedType )
-                          {
-                              ParameterizedType pt = (ParameterizedType) type;
-                              Type[] args = pt.getActualTypeArguments();
-                              Class clazz = (Class) pt.getRawType();
-                              TypeVariable[] vars = clazz.getTypeParameters();
-                              for( int i = 0; i < vars.length; i++ )
-                              {
-                                  TypeVariable var = vars[ i ];
-                                  Type mappedType = args[ i ];
-                                  mappings.put( var, mappedType );
-                              }
-                              subClass = (Class) pt.getRawType();
-                          }
-                          else
-                          {
-                              subClass = (Class) type;
-                          }
-                          return subClass;
-                      } )
-                .map( subClass -> resolveTypeVariable( name, declaringClass, mappings,
subClass ) )
-                .filter( type -> type != null )
-                .findAny().get();
+        Type genericSuperclass = current.getGenericSuperclass();
+        if( genericSuperclass != null )
+        {
+            stream = concat( stream, Stream.of( genericSuperclass ) );
+        }
+        return stream.map( type -> {
+            Class subClass;
+            if( type instanceof ParameterizedType )
+            {
+                subClass = extractTypeVariables( mappings, (ParameterizedType) type );
+            }
+            else
+            {
+                subClass = (Class) type;
+            }
+            return subClass;
+        } )
+            .map( subClass -> resolveTypeVariable( name, declaringClass, mappings, subClass
) )
+            .filter( type -> type != null )
+            .findAny().orElse( null );
 
 //        List<Type> types = new ArrayList<>();
 //        for( Type type : current.getGenericInterfaces() )
@@ -512,6 +512,22 @@ public final class Classes
 //        return null;
     }
 
+    private static Class extractTypeVariables( Map<TypeVariable, Type> mappings, ParameterizedType
type )
+    {
+        Class subClass;
+        Type[] args = type.getActualTypeArguments();
+        Class clazz = (Class) type.getRawType();
+        TypeVariable[] vars = clazz.getTypeParameters();
+        for( int i = 0; i < vars.length; i++ )
+        {
+            TypeVariable var = vars[ i ];
+            Type mappedType = args[ i ];
+            mappings.put( var, mappedType );
+        }
+        subClass = (Class) type.getRawType();
+        return subClass;
+    }
+
     /**
      * Get URI for a class.
      *
@@ -602,7 +618,7 @@ public final class Classes
     @SuppressWarnings( "raw" )
     public static String toString( Stream<? extends Class> types )
     {
-        return "[" + types.map(Class::getSimpleName).collect( Collectors.joining(",")) +"]";
+        return "[" + types.map( Class::getSimpleName ).collect( Collectors.joining( "," )
) + "]";
     }
 
     public static Function<Type, String> toClassName()

http://git-wip-us.apache.org/repos/asf/zest-java/blob/360c40e3/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ServiceAssemblyImpl.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ServiceAssemblyImpl.java
b/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ServiceAssemblyImpl.java
index 825ebe4..255c2d0 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ServiceAssemblyImpl.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ServiceAssemblyImpl.java
@@ -80,18 +80,20 @@ public final class ServiceAssemblyImpl extends CompositeAssemblyImpl
     private Iterable<Class<? extends Activator<?>>> activatorsDeclarations(
Stream<? extends Class<?>> typess )
     {
         return typess.flatMap( Classes::typesOf )
-            .filter( type -> Annotations.annotationOn( type, Activators.class ) == null
)
+//            .filter( type -> Annotations.annotationOn( type, Activators.class ) == null
)
             .flatMap( this::getAnnotations )
             .collect( Collectors.toList() );
     }
 
     private Stream<? extends Class<? extends Activator<?>>> getAnnotations(
Type type )
     {
-        Activators activators1 = Annotations.annotationOn( type, Activators.class );
-        if( activators1 == null )
+        Activators activators = Annotations.annotationOn( type, Activators.class );
+        if( activators == null )
         {
             return Stream.empty();
         }
-        return Arrays.stream( activators1.value() );
+        return Arrays.stream( activators.value() );
     }
+
+
 }

http://git-wip-us.apache.org/repos/asf/zest-java/blob/360c40e3/core/runtime/src/main/java/org/apache/zest/runtime/structure/ModuleInstance.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/structure/ModuleInstance.java
b/core/runtime/src/main/java/org/apache/zest/runtime/structure/ModuleInstance.java
index 2237dfa..2bd8496 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/structure/ModuleInstance.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/structure/ModuleInstance.java
@@ -311,7 +311,7 @@ public class ModuleInstance
 
         if( modelModule == null )
         {
-            throw new NoSuchObjectException( mixinType.getName(), name() );
+            throw new NoSuchObjectException( mixinType.getName(), name(), typeLookup.allVisibleObjects()
);
         }
 
         InjectionContext injectionContext = new InjectionContext( modelModule.module(), UsesInstance.EMPTY_USES.use(
uses ) );
@@ -327,7 +327,7 @@ public class ModuleInstance
 
         if( modelModule == null )
         {
-            throw new NoSuchObjectException( instance.getClass().getName(), name() );
+            throw new NoSuchObjectException( instance.getClass().getName(), name(), typeLookup.allVisibleObjects()
);
         }
 
         InjectionContext injectionContext = new InjectionContext( modelModule.module(), UsesInstance.EMPTY_USES.use(
uses ) );

http://git-wip-us.apache.org/repos/asf/zest-java/blob/360c40e3/core/runtime/src/main/java/org/apache/zest/runtime/structure/TypeLookup.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/structure/TypeLookup.java
b/core/runtime/src/main/java/org/apache/zest/runtime/structure/TypeLookup.java
index 975e7e2..3baaee7 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/structure/TypeLookup.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/structure/TypeLookup.java
@@ -33,9 +33,9 @@ import org.apache.zest.api.composite.AmbiguousTypeException;
 import org.apache.zest.api.composite.ModelDescriptor;
 import org.apache.zest.api.service.NoSuchServiceException;
 import org.apache.zest.api.service.ServiceReference;
-import org.apache.zest.runtime.legacy.Specifications;
 import org.apache.zest.runtime.composite.TransientModel;
 import org.apache.zest.runtime.entity.EntityModel;
+import org.apache.zest.runtime.legacy.Specifications;
 import org.apache.zest.runtime.object.ObjectModel;
 import org.apache.zest.runtime.value.ValueModel;
 import org.apache.zest.spi.module.ModelModule;
@@ -473,6 +473,19 @@ public class TypeLookup
         return models.map( ambiguityFinder );
     }
 
+    public Stream<Class<?>> allVisibleObjects()
+    {
+        return concat( moduleInstance.visibleObjects( module ),
+                       concat(
+                           moduleInstance.layerInstance().visibleObjects( layer ),
+                           concat(
+                               moduleInstance.layerInstance().visibleObjects( application
),
+                               moduleInstance.layerInstance().usedLayersInstance().visibleObjects()
+                           )
+                       )
+        ).flatMap( model -> model.model().types() );
+    }
+
     private static class ModelModuleTypesFunction<T extends ModelDescriptor>
         implements Function<ModelModule<T>, Stream<Class<?>>>
     {

http://git-wip-us.apache.org/repos/asf/zest-java/blob/360c40e3/core/spi/src/main/java/org/apache/zest/spi/entitystore/helpers/JSONMapEntityStoreActivation.java
----------------------------------------------------------------------
diff --git a/core/spi/src/main/java/org/apache/zest/spi/entitystore/helpers/JSONMapEntityStoreActivation.java
b/core/spi/src/main/java/org/apache/zest/spi/entitystore/helpers/JSONMapEntityStoreActivation.java
index 0acc631..e98939a 100644
--- a/core/spi/src/main/java/org/apache/zest/spi/entitystore/helpers/JSONMapEntityStoreActivation.java
+++ b/core/spi/src/main/java/org/apache/zest/spi/entitystore/helpers/JSONMapEntityStoreActivation.java
@@ -38,7 +38,7 @@ public interface JSONMapEntityStoreActivation
     /**
      * JSONMapEntityStoreMixin Activator.
      */
-    public class Activator
+    class Activator
         extends ActivatorAdapter<ServiceReference<JSONMapEntityStoreActivation>>
     {
 

http://git-wip-us.apache.org/repos/asf/zest-java/blob/360c40e3/core/spi/src/main/java/org/apache/zest/spi/entitystore/helpers/JSONMapEntityStoreMixin.java
----------------------------------------------------------------------
diff --git a/core/spi/src/main/java/org/apache/zest/spi/entitystore/helpers/JSONMapEntityStoreMixin.java
b/core/spi/src/main/java/org/apache/zest/spi/entitystore/helpers/JSONMapEntityStoreMixin.java
index 72f7a99..f85564d 100644
--- a/core/spi/src/main/java/org/apache/zest/spi/entitystore/helpers/JSONMapEntityStoreMixin.java
+++ b/core/spi/src/main/java/org/apache/zest/spi/entitystore/helpers/JSONMapEntityStoreMixin.java
@@ -28,9 +28,6 @@ import java.io.Writer;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.UUID;
-import org.json.JSONException;
-import org.json.JSONObject;
-import org.json.JSONTokener;
 import org.apache.zest.api.cache.CacheOptions;
 import org.apache.zest.api.common.Optional;
 import org.apache.zest.api.entity.EntityDescriptor;
@@ -64,9 +61,9 @@ import org.apache.zest.spi.entitystore.ModuleEntityStoreUnitOfWork;
 import org.apache.zest.spi.entitystore.StateCommitter;
 import org.apache.zest.spi.module.ModelModule;
 import org.apache.zest.spi.module.ModuleSpi;
-
-import static org.apache.zest.functional.Iterables.first;
-import static org.apache.zest.functional.Iterables.map;
+import org.json.JSONException;
+import org.json.JSONObject;
+import org.json.JSONTokener;
 
 /**
  * Implementation of EntityStore that works with an implementation of MapEntityStore.
@@ -437,7 +434,7 @@ public class JSONMapEntityStoreMixin
                                                        module.name(),
                                                        module.findVisibleEntityTypes()
                                                            .map( ModelModule.toStringFunction
)
-            );
+                );
             }
 
             return new JSONEntityState( valueSerialization,
@@ -479,7 +476,6 @@ public class JSONMapEntityStoreMixin
             {
                 String type = data.getString( JSONKeys.TYPE );
                 EntityDescriptor entityDescriptor = module.entityDescriptor( type );
-//                return new JSONEntityState( currentTime, valueSerialization, identity,
entityDescriptor, data );
                 return new JSONEntityState( valueSerialization, data.getString( JSONKeys.VERSION
), data.getLong( JSONKeys.MODIFIED ), identity, EntityStatus.LOADED, entityDescriptor, data
);
             }
             catch( JSONException e )


Mime
View raw message