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

Improve type parameter resolution in complex class structure #67

Closed harawata closed 6 years ago

harawata commented 7 years ago

Here is the background:

I wrote formatters and type converters for Java Time API (here is the repo). I tried to let Stripes auto-detect them via Extension.Packages, but it failed with warnings like below.

2017/05/22 16:09:27,988 WARN (stripes.config.RuntimeConfiguration#warn) - Type parameter for non-abstract Formatter [class net.harawata.stripes.jsr310.format.LocalDateFormatter] is not a class.

Basically, I created an abstract class that contains the common code ...

public abstract class
  TemporalAccessorFormatter<T extends TemporalAccessor>
  implements Formatter<T> {}

... and extend it to create the actual implementations.

public class LocalDateFormatter
  extends TemporalAccessorFormatter<LocalDate> {}

With this structure, ReflectUtil#getActualTypeParameters(LocalDateFormatter.class, Formatter.class) returns the type variable T instead of LocalDate.

With this PR applied, the method returns the correct type. This change should be backward compatible.

harawata commented 6 years ago

Thank you @rgrashel :)