tamaya-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anat...@apache.org
Subject [05/16] incubator-tamaya git commit: Fixed type parameter evaluation.
Date Tue, 24 Mar 2015 21:20:22 GMT
Fixed type parameter evaluation.


Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/7bdbe56c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/7bdbe56c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/7bdbe56c

Branch: refs/heads/master
Commit: 7bdbe56c1879dbed0b305d903bb626d5f863e2c1
Parents: 42175ba
Author: anatole <anatole@apache.org>
Authored: Tue Mar 24 15:54:08 2015 +0100
Committer: anatole <anatole@apache.org>
Committed: Tue Mar 24 15:54:08 2015 +0100

----------------------------------------------------------------------
 .../main/java/org/apache/tamaya/TypeLiteral.java   | 17 ++++++++++-------
 .../main/java/org/apache/tamaya/TypeLiteral.java   | 14 ++++++++------
 2 files changed, 18 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/7bdbe56c/java7/api/src/main/java/org/apache/tamaya/TypeLiteral.java
----------------------------------------------------------------------
diff --git a/java7/api/src/main/java/org/apache/tamaya/TypeLiteral.java b/java7/api/src/main/java/org/apache/tamaya/TypeLiteral.java
index edd69eb..a3abdf5 100644
--- a/java7/api/src/main/java/org/apache/tamaya/TypeLiteral.java
+++ b/java7/api/src/main/java/org/apache/tamaya/TypeLiteral.java
@@ -52,9 +52,10 @@ public class TypeLiteral<T> implements Serializable {
     /**
      * Creates a new TypeLiteral based on a given type.
      * @param type the type , not null.
+     * @param <R> the literal generic type.
      * @return the corresponding TypeLiteral, never null.
      */
-    public static TypeLiteral<?> of(Type type){
+    public static <R> TypeLiteral<R> of(Type type){
         return new TypeLiteral<>(type);
     }
 
@@ -102,16 +103,18 @@ public class TypeLiteral<T> implements Serializable {
      * @return the generic type parameter of the given single type generic interfaceType,
or null.
      */
     public static Type getTypeParameter(Class<?> clazz, Class<?> interfaceType)
{
-        Type type = clazz.getGenericSuperclass();
-        if (type instanceof ParameterizedType) {
-            if(interfaceType == null ||type.equals(interfaceType)){
+        Type[] types = clazz.getGenericInterfaces();
+        for(Type type:types) {
+            if (type instanceof ParameterizedType) {
                 ParameterizedType parameterizedType = (ParameterizedType) type;
-                if (parameterizedType.getActualTypeArguments().length == 1) {
-                    return parameterizedType.getActualTypeArguments()[0];
+                if(interfaceType==null || parameterizedType.getRawType().equals(interfaceType)){
+                    if (parameterizedType.getActualTypeArguments().length == 1) {
+                        return parameterizedType.getActualTypeArguments()[0];
+                    }
                 }
             }
         }
-        return getTypeParameter(clazz, interfaceType);
+        return null;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/7bdbe56c/java8/api/src/main/java/org/apache/tamaya/TypeLiteral.java
----------------------------------------------------------------------
diff --git a/java8/api/src/main/java/org/apache/tamaya/TypeLiteral.java b/java8/api/src/main/java/org/apache/tamaya/TypeLiteral.java
index 6edbb68..c77cadb 100644
--- a/java8/api/src/main/java/org/apache/tamaya/TypeLiteral.java
+++ b/java8/api/src/main/java/org/apache/tamaya/TypeLiteral.java
@@ -103,16 +103,18 @@ public class TypeLiteral<T> implements Serializable {
      * @return the generic type parameter of the given single type generic interfaceType,
or null.
      */
     public static Type getTypeParameter(Class<?> clazz, Class<?> interfaceType)
{
-        Type type = clazz.getGenericSuperclass();
-        if (type instanceof ParameterizedType) {
-            if(interfaceType == null ||type.equals(interfaceType)){
+        Type[] types = clazz.getGenericInterfaces();
+        for(Type type:types) {
+            if (type instanceof ParameterizedType) {
                 ParameterizedType parameterizedType = (ParameterizedType) type;
-                if (parameterizedType.getActualTypeArguments().length == 1) {
-                    return parameterizedType.getActualTypeArguments()[0];
+                if(interfaceType==null || parameterizedType.getRawType().equals(interfaceType)){
+                    if (parameterizedType.getActualTypeArguments().length == 1) {
+                        return parameterizedType.getActualTypeArguments()[0];
+                    }
                 }
             }
         }
-        return getTypeParameter(clazz, interfaceType);
+        return null;
     }
 
     /**


Mime
View raw message