This commit is contained in:
@@ -766,6 +766,7 @@ public final class Rest {
|
||||
final List<java.lang.reflect.Type[]> 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;
|
||||
|
||||
@@ -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<? extends CompletableFuture>) method.getReturnType()) : null;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -64,6 +64,33 @@ public abstract class TypeToken<T> {
|
||||
return newTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取TypeVariable对应的实际Type, 如果type不是TypeVariable 直接返回type。
|
||||
* <pre>
|
||||
* 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();
|
||||
* }
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
*
|
||||
* @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<T> {
|
||||
}
|
||||
}
|
||||
}
|
||||
TypeVariable tv = (TypeVariable) type;
|
||||
if (tv.getBounds().length == 1) return tv.getBounds()[0];
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user