tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject svn commit: r1196359 - in /tapestry/tapestry5/trunk/tapestry-ioc/src: main/java/org/apache/tapestry5/ioc/internal/services/ main/java/org/apache/tapestry5/ioc/internal/util/ main/java/org/apache/tapestry5/ioc/services/ test/java/org/apache/tapestry5/io...
Date Tue, 01 Nov 2011 23:09:47 GMT
Author: hlship
Date: Tue Nov  1 23:09:47 2011
New Revision: 1196359

URL: http://svn.apache.org/viewvc?rev=1196359&view=rev
Log:
TAP5-1739: Change TypeCoercer to use PlasticUtils.toWrapperType()

Modified:
    tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/TypeCoercerImpl.java
    tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/InternalUtils.java
    tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/CoercionTuple.java
    tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/ModuleImplTest.java

Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/TypeCoercerImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/TypeCoercerImpl.java?rev=1196359&r1=1196358&r2=1196359&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/TypeCoercerImpl.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/TypeCoercerImpl.java
Tue Nov  1 23:09:47 2011
@@ -23,6 +23,7 @@ import org.apache.tapestry5.ioc.services
 import org.apache.tapestry5.ioc.services.TypeCoercer;
 import org.apache.tapestry5.ioc.util.AvailableValues;
 import org.apache.tapestry5.ioc.util.UnknownValueException;
+import org.apache.tapestry5.plastic.PlasticUtils;
 import org.apache.tapestry5.util.StringToEnumCoercion;
 
 import java.util.*;
@@ -56,7 +57,7 @@ public class TypeCoercerImpl implements 
         Object coerce(Object input)
         {
 
-            Class sourceType = input != null ? input.getClass() : void.class;
+            Class sourceType = input != null ? input.getClass() : Void.class;
 
             if (type.isAssignableFrom(sourceType))
                 return input;
@@ -131,7 +132,16 @@ public class TypeCoercerImpl implements 
     public Object coerce(Object input, Class targetType)
     {
         assert targetType != null;
-        Class effectiveTargetType = InternalUtils.getWrapperType(targetType);
+        // This is needed by TypeCoercer, which has its own rules about how to handler void.class
(as a stand-in
+        // for null). Plastic treats Void as the wrapper for void.
+        /*
+if (type == void.class)
+{
+   return type;
+}
+    */
+
+        Class effectiveTargetType = PlasticUtils.toWrapperType(targetType);
 
         if (effectiveTargetType.isInstance(input))
             return input;
@@ -144,8 +154,26 @@ public class TypeCoercerImpl implements 
     {
         assert sourceType != null;
         assert targetType != null;
-        Class effectiveSourceType = InternalUtils.getWrapperType(sourceType);
-        Class effectiveTargetType = InternalUtils.getWrapperType(targetType);
+        // This is needed by TypeCoercer, which has its own rules about how to handler void.class
(as a stand-in
+        // for null). Plastic treats Void as the wrapper for void.
+        /*
+if (type == void.class)
+{
+   return type;
+}
+    */
+
+        Class effectiveSourceType = PlasticUtils.toWrapperType(sourceType);
+        // This is needed by TypeCoercer, which has its own rules about how to handler void.class
(as a stand-in
+        // for null). Plastic treats Void as the wrapper for void.
+        /*
+if (type == void.class)
+{
+   return type;
+}
+    */
+
+        Class effectiveTargetType = PlasticUtils.toWrapperType(targetType);
 
         if (effectiveTargetType.isAssignableFrom(effectiveSourceType))
             return NO_COERCION;
@@ -158,8 +186,26 @@ public class TypeCoercerImpl implements 
     {
         assert sourceType != null;
         assert targetType != null;
-        Class effectiveTargetType = InternalUtils.getWrapperType(targetType);
-        Class effectiveSourceType = InternalUtils.getWrapperType(sourceType);
+        // This is needed by TypeCoercer, which has its own rules about how to handler void.class
(as a stand-in
+        // for null). Plastic treats Void as the wrapper for void.
+        /*
+if (type == void.class)
+{
+   return type;
+}
+    */
+
+        Class effectiveTargetType = PlasticUtils.toWrapperType(targetType);
+        // This is needed by TypeCoercer, which has its own rules about how to handler void.class
(as a stand-in
+        // for null). Plastic treats Void as the wrapper for void.
+        /*
+if (type == void.class)
+{
+   return type;
+}
+    */
+
+        Class effectiveSourceType = PlasticUtils.toWrapperType(sourceType);
 
         // Is a coercion even necessary? Not if the target type is assignable from the
         // input value.
@@ -167,7 +213,7 @@ public class TypeCoercerImpl implements 
         if (effectiveTargetType.isAssignableFrom(effectiveSourceType))
             return "";
 
-        return getTargetCoercion(targetType).explain(sourceType);
+        return getTargetCoercion(effectiveTargetType).explain(effectiveSourceType);
     }
 
     private synchronized TargetCoercion getTargetCoercion(Class targetType)
@@ -225,7 +271,7 @@ public class TypeCoercerImpl implements 
     @SuppressWarnings("unchecked")
     private Coercion findOrCreateCoercion(Class sourceType, Class targetType)
     {
-        if (sourceType == void.class)
+        if (sourceType == Void.class)
             return searchForNullCoercion(targetType);
 
         // These are instance variables because this method may be called concurrently.
@@ -279,7 +325,7 @@ public class TypeCoercerImpl implements 
      */
     private Coercion searchForNullCoercion(Class targetType)
     {
-        List<CoercionTuple> tuples = getTuples(void.class, targetType);
+        List<CoercionTuple> tuples = getTuples(Void.class, targetType);
 
         for (CoercionTuple tuple : tuples)
         {
@@ -336,7 +382,7 @@ public class TypeCoercerImpl implements 
             // Don't pull in Object -> type coercions when doing
             // a search from null.
 
-            if (sourceType == void.class)
+            if (sourceType == Void.class)
                 return;
         }
     }

Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/InternalUtils.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/InternalUtils.java?rev=1196359&r1=1196358&r2=1196359&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/InternalUtils.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/InternalUtils.java
Tue Nov  1 23:09:47 2011
@@ -1552,17 +1552,4 @@ public class InternalUtils
         });
     }
 
-    public static Class getWrapperType(Class type)
-    {
-        // This is needed by TypeCoercer, which has its own rules about how to handler void.class
(as a stand-in
-        // for null). Plastic treats Void as the wrapper for void.
-
-        if (type == void.class)
-        {
-            return type;
-        }
-
-        return PlasticUtils.toWrapperType(type);
-    }
-
 }

Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/CoercionTuple.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/CoercionTuple.java?rev=1196359&r1=1196358&r2=1196359&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/CoercionTuple.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/CoercionTuple.java
Tue Nov  1 23:09:47 2011
@@ -14,7 +14,6 @@
 
 package org.apache.tapestry5.ioc.services;
 
-import org.apache.tapestry5.ioc.internal.util.InternalUtils;
 import org.apache.tapestry5.plastic.PlasticUtils;
 
 /**
@@ -64,7 +63,7 @@ public final class CoercionTuple<S, T>
 
     private String convert(Class type)
     {
-        if (void.class.equals(type))
+        if (Void.class.equals(type))
             return "null";
 
         String name = PlasticUtils.toTypeName(type);
@@ -116,8 +115,26 @@ public final class CoercionTuple<S, T>
         assert targetType != null;
         assert coercion != null;
 
-        this.sourceType = InternalUtils.getWrapperType(sourceType);
-        this.targetType = InternalUtils.getWrapperType(targetType);
+        // This is needed by TypeCoercer, which has its own rules about how to handler void.class
(as a stand-in
+        // for null). Plastic treats Void as the wrapper for void.
+        /*
+if (type == void.class)
+{
+   return type;
+}
+    */
+
+        this.sourceType = PlasticUtils.toWrapperType(sourceType);
+        // This is needed by TypeCoercer, which has its own rules about how to handler void.class
(as a stand-in
+        // for null). Plastic treats Void as the wrapper for void.
+        /*
+if (type == void.class)
+{
+   return type;
+}
+    */
+
+        this.targetType = PlasticUtils.toWrapperType(targetType);
         this.coercion = wrap ? new CoercionWrapper<S, T>(coercion) : coercion;
     }
 

Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/ModuleImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/ModuleImplTest.java?rev=1196359&r1=1196358&r2=1196359&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/ModuleImplTest.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/ModuleImplTest.java
Tue Nov  1 23:09:47 2011
@@ -17,7 +17,6 @@ package org.apache.tapestry5.ioc.interna
 import org.apache.tapestry5.ioc.*;
 import org.apache.tapestry5.ioc.def.*;
 import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
-import org.apache.tapestry5.ioc.services.ClassFactory;
 import org.slf4j.Logger;
 import org.testng.annotations.Test;
 
@@ -55,7 +54,7 @@ public class ModuleImplTest extends IOCI
     {
         InternalRegistry registry = mockInternalRegistry();
         ServiceDef serviceDef = mockServiceDef();
-        DecoratorDef2 def1 =newMock(DecoratorDef2.class);
+        DecoratorDef2 def1 = newMock(DecoratorDef2.class);
         DecoratorDef def2 = newMock(DecoratorDef2.class);
         Set<DecoratorDef> rawDefs = newMock(Set.class);
         Logger logger = mockLogger();
@@ -92,12 +91,12 @@ public class ModuleImplTest extends IOCI
     {
         InternalRegistry registry = mockInternalRegistry();
         ServiceDef serviceDef = mockServiceDef();
-        DecoratorDef2 def1 =newMock(DecoratorDef2.class);
+        DecoratorDef2 def1 = newMock(DecoratorDef2.class);
         DecoratorDef def2 = newMock(DecoratorDef2.class);
         Set<DecoratorDef> rawDefs = newMock(Set.class);
-        Set<Class> def1Markers = CollectionFactory.newSet((Class)BlueMarker.class);
-        Set<Class> serviceDefMarkers =CollectionFactory.newSet((Class)RedMarker.class);
-        Set<Class> allMarkers = CollectionFactory.newSet((Class)BlueMarker.class, (Class)BlueMarker.class);
+        Set<Class> def1Markers = CollectionFactory.newSet((Class) BlueMarker.class);
+        Set<Class> serviceDefMarkers = CollectionFactory.newSet((Class) RedMarker.class);
+        Set<Class> allMarkers = CollectionFactory.newSet((Class) BlueMarker.class,
(Class) BlueMarker.class);
         Logger logger = mockLogger();
 
         ModuleDef moduleDef = mockModuleDef();
@@ -177,9 +176,9 @@ public class ModuleImplTest extends IOCI
         AdvisorDef2 def1 = mockAdvisorDef2();
         AdvisorDef2 def2 = mockAdvisorDef2();
         Set<AdvisorDef> rawDefs = newMock(Set.class);
-        Set<Class> def1Markers = CollectionFactory.newSet((Class)BlueMarker.class);
-        Set<Class> serviceDefMarkers =CollectionFactory.newSet((Class)RedMarker.class);
-        Set<Class> allMarkers = CollectionFactory.newSet((Class)BlueMarker.class, (Class)BlueMarker.class);
+        Set<Class> def1Markers = CollectionFactory.newSet((Class) BlueMarker.class);
+        Set<Class> serviceDefMarkers = CollectionFactory.newSet((Class) RedMarker.class);
+        Set<Class> allMarkers = CollectionFactory.newSet((Class) BlueMarker.class,
(Class) BlueMarker.class);
         Logger logger = mockLogger();
 
         ModuleDef2 moduleDef = mockModuleDef2();
@@ -221,9 +220,9 @@ public class ModuleImplTest extends IOCI
         AdvisorDef2 def1 = mockAdvisorDef2();
         AdvisorDef2 def2 = mockAdvisorDef2();
         Set<AdvisorDef> rawDefs = newMock(Set.class);
-        Set<Class> def1Markers = CollectionFactory.newSet((Class)BlueMarker.class);
-        Set<Class> serviceDefMarkers =CollectionFactory.newSet((Class)BlueMarker.class);
-        Set<Class> allMarkers = CollectionFactory.newSet((Class)BlueMarker.class);
+        Set<Class> def1Markers = CollectionFactory.newSet((Class) BlueMarker.class);
+        Set<Class> serviceDefMarkers = CollectionFactory.newSet((Class) BlueMarker.class);
+        Set<Class> allMarkers = CollectionFactory.newSet((Class) BlueMarker.class);
         Logger logger = mockLogger();
 
         ModuleDef2 moduleDef = mockModuleDef2();
@@ -258,7 +257,7 @@ public class ModuleImplTest extends IOCI
     }
 
 
-     @SuppressWarnings("unchecked")
+    @SuppressWarnings("unchecked")
     @Test
     public void no_advisor_def_when_service_interface_is_default_and_no_markers()
     {
@@ -340,8 +339,7 @@ public class ModuleImplTest extends IOCI
         {
             foe.foe();
             unreachable();
-        }
-        catch (RuntimeException ex)
+        } catch (RuntimeException ex)
         {
             // The details are checked elsewhere.
         }



Mime
View raw message