StripesFramework / stripes

Stripes is a Java framework with the goal of making Servlet/JSP based web development in Java as easy, intuitive and straight-forward as it should be. It's stripey and it doesn't suck.
http://www.stripesframework.org/
171 stars 73 forks source link

Update AnnotatedClassActionResolver.java #68

Closed nclemeur closed 6 years ago

nclemeur commented 7 years ago

Add support for Java 8 default method in interfaces as an event handler. It looks like the getDeclaredMethods does not return default method in interface implemented by the ActionBean.

Note: the method.isDefault() require java 8. So I don't know what is the minimum JDK supported by Stripes, but this patch would require at least Java 8

rgrashel commented 6 years ago

Hi @nclemeur,

I am not sure if you are able, but I looked at the source code for Java 8 java.lang.reflect.Method class and this can be done without using Java 8. You only need to copy the logic from the isDefault() method which is very simple. All you would need to do is put this method inside of ReflectUtil and have it take a Method as an argument. Then modify the AnnotatedClassActionResolver to call ReflectUtil.isDefault( method ). Can you modify your pull request and I will perform the merge? Here is what the code would look like in ReflectUtil:

public static boolean isDefault( Method method ) {
  // Default methods are public non-abstract instance methods
  // declared in an interface.
  return ((method.getModifiers() & (Modifier.ABSTRACT | Modifier.PUBLIC | Modifier.STATIC)) == Modifier.PUBLIC) && method.getDeclaringClass().isInterface();
}
rgrashel commented 6 years ago

@nclemeur

I went ahead and took the Java 7 compliant approach I mentioned above and accepted the remainder of the changes. So Java 8 default methods should now be supported in master. Thanks.