google-code-export / gwt-dispatch

Automatically exported from code.google.com/p/gwt-dispatch
1 stars 0 forks source link

Remove need for getActionType() in Action Handlers #26

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The AbstractActionHandler could implement the getActionType() by taking the 
first generic declaration like so:

@SuppressWarnings({"unchecked"})
public Class<A> getActionType() {
    return GenericsUtils.getFirstGenericDeclaration(this.getClass());
}

The getFirstGenericDeclaration contains:

public static Class getFirstGenericDeclaration(@NotNull Class clazz) {
    Assert.notNull(clazz);

    Type classGenType = clazz.getGenericSuperclass();

    // special CGLIB workaround -- get generic superclass of superclass
    if (clazz.getName().contains("$$EnhancerByCGLIB$$")) {
        classGenType = clazz.getSuperclass().getGenericSuperclass();
    }

    if (classGenType instanceof ParameterizedType) {
        Type[] params = ((ParameterizedType) 
classGenType).getActualTypeArguments();

        if ((params != null) && (params.length >= 1)) {
            return (Class) params[0];
        }
    }

    for (Type ifGenType : clazz.getGenericInterfaces()) {
        if (ifGenType instanceof ParameterizedType) {
            Type[] params = ((ParameterizedType) 
ifGenType).getActualTypeArguments();

            if ((params != null) && (params.length >= 1)) {
                return (Class) params[0];
            }
        }
    }

    return null;
}

Original issue reported on code.google.com by mathias....@gmail.com on 10 Feb 2010 at 11:12

GoogleCodeExporter commented 9 years ago

Original comment by Bitmei...@gmail.com on 25 Apr 2010 at 2:08

GoogleCodeExporter commented 9 years ago

Original comment by Bitmei...@gmail.com on 18 Aug 2010 at 7:04

GoogleCodeExporter commented 9 years ago

Original comment by robert.munteanu on 21 Apr 2011 at 10:24

GoogleCodeExporter commented 9 years ago

Original comment by robert.munteanu on 24 Apr 2011 at 7:05