From c2dad0807ff82fd7275ef2d093f5a4de3633e5ba Mon Sep 17 00:00:00 2001 From: Redkale <22250530@qq.com> Date: Thu, 8 Feb 2018 15:30:35 +0800 Subject: [PATCH] --- src/org/redkale/net/http/Rest.java | 1 + src/org/redkale/net/sncp/SncpClient.java | 9 ++---- src/org/redkale/net/sncp/SncpDynServlet.java | 4 --- src/org/redkale/util/TypeToken.java | 29 ++++++++++++++++++++ 4 files changed, 32 insertions(+), 11 deletions(-) diff --git a/src/org/redkale/net/http/Rest.java b/src/org/redkale/net/http/Rest.java index ae1b8b1c9..2317ac38a 100644 --- a/src/org/redkale/net/http/Rest.java +++ b/src/org/redkale/net/http/Rest.java @@ -766,6 +766,7 @@ public final class Rest { final List paramtypes = new ArrayList<>(); for (final Method method : serviceType.getMethods()) { if (Modifier.isStatic(method.getModifiers())) continue; + if (method.isSynthetic()) continue; Class[] extypes = method.getExceptionTypes(); if (extypes.length > 1) continue; if (extypes.length == 1 && extypes[0] != IOException.class) continue; diff --git a/src/org/redkale/net/sncp/SncpClient.java b/src/org/redkale/net/sncp/SncpClient.java index fc8512ac0..74f6614ca 100644 --- a/src/org/redkale/net/sncp/SncpClient.java +++ b/src/org/redkale/net/sncp/SncpClient.java @@ -215,9 +215,8 @@ public final class SncpClient { for (final java.lang.reflect.Method method : serviceClass.getMethods()) { if (method.isSynthetic()) continue; - final int mod = method.getModifiers(); - if (Modifier.isStatic(mod)) continue; - if (Modifier.isFinal(mod)) continue; + if (Modifier.isStatic(method.getModifiers())) continue; + if (Modifier.isFinal(method.getModifiers())) continue; if (method.getAnnotation(Local.class) != null) continue; if (method.getName().equals("getClass") || method.getName().equals("toString")) continue; if (method.getName().equals("equals") || method.getName().equals("hashCode")) continue; @@ -551,10 +550,6 @@ public final class SncpClient { public SncpAction(final Class clazz, Method method, DLong actionid) { this.actionid = actionid == null ? Sncp.hash(method) : actionid; Type rt = TypeToken.getGenericType(method.getGenericReturnType(), clazz); - if (rt instanceof TypeVariable) { - TypeVariable tv = (TypeVariable) rt; - if (tv.getBounds().length == 1) rt = tv.getBounds()[0]; - } this.resultTypes = rt == void.class ? null : rt; this.boolReturnTypeFuture = CompletableFuture.class.isAssignableFrom(method.getReturnType()); this.futureCreator = boolReturnTypeFuture ? Creator.create((Class) method.getReturnType()) : null; diff --git a/src/org/redkale/net/sncp/SncpDynServlet.java b/src/org/redkale/net/sncp/SncpDynServlet.java index 5752c29f0..92f271df3 100644 --- a/src/org/redkale/net/sncp/SncpDynServlet.java +++ b/src/org/redkale/net/sncp/SncpDynServlet.java @@ -591,10 +591,6 @@ public final class SncpDynServlet extends SncpServlet { java.lang.reflect.Type[] ptypes = TypeToken.getGenericType(method.getGenericParameterTypes(), newClazz); java.lang.reflect.Type[] types = new java.lang.reflect.Type[ptypes.length + 1]; java.lang.reflect.Type rt = TypeToken.getGenericType(method.getGenericReturnType(), newClazz); - if (rt instanceof TypeVariable) { - TypeVariable tv = (TypeVariable) rt; - if (tv.getBounds().length == 1) rt = tv.getBounds()[0]; - } types[0] = rt; System.arraycopy(ptypes, 0, types, 1, ptypes.length); instance.paramTypes = types; diff --git a/src/org/redkale/util/TypeToken.java b/src/org/redkale/util/TypeToken.java index 895de030b..a9681a05c 100644 --- a/src/org/redkale/util/TypeToken.java +++ b/src/org/redkale/util/TypeToken.java @@ -64,6 +64,33 @@ public abstract class TypeToken { return newTypes; } + /** + * 获取TypeVariable对应的实际Type, 如果type不是TypeVariable 直接返回type。 + *
+     *  public abstract class Key {
+     *  }
+     *  public abstract class Val {
+     *  }
+     *  public abstract class AService <K extends Key, V extends Val> {
+     *       public abstract V findValue(K key);
+     *  }
+     *  public class Key2 extends Key {
+     *  }
+     *  public class Val2 extends Val {
+     *  }
+     *  public class Service2 extends Service <Key2, Val2> {
+     *       public Val2 findValue(Key2 key){
+     *          return new Val2();
+     *       }
+     *  }
+     * 
+ * + * + * @param type 泛型 + * @param declaringClass 泛型依附类 + * + * @return Type + */ public static Type getGenericType(final Type type, final Type declaringClass) { if (declaringClass == null) return type; if (type instanceof TypeVariable) { @@ -87,6 +114,8 @@ public abstract class TypeToken { } } } + TypeVariable tv = (TypeVariable) type; + if (tv.getBounds().length == 1) return tv.getBounds()[0]; } return type; }