Still playing with Roaster so I could fix https://issues.jboss.org/browse/FORGE-1618 (Command constraint-new-validator to create a new validator implementation). I don't know how to do two things (nicely) :

# Parameterize interface

For a constraint, I need to implement a parametrize interface like this :

public class MaxValidatorForString implements ConstraintValidator<Max, Number> {

The only way I could find is passing a String :

final JavaClassSource javaClass = Roaster.create(JavaClassSource.class);
javaClass.addInterface("ConstraintValidator<Max, Number>");

It's a shame because with addInterface(Class), it does the import automatically and things are more typed. But I cannot add types :

final JavaClassSource javaClass = Roaster.create(JavaClassSource.class);

It would be good to have something like :


# Typed parameters

My isValid method takes two parameters. And the only way to add two parameters seems to be by a String

javaClass.addMethod().setPublic().setName("isValid").setReturnType("boolean").setParameters("Number value, ConstraintValidatorContext context").setBody("return false;").addAnnotation(Override.class);

Again, it would be nice to have typed parameters so the import is implicit, and things are a bit more typed :

javaClass.addMethod().setPublic().setName("isValid").setReturnType("boolean").addParameter(Number.class, "value").addParameter(ConstraintValidatorContext.class, "context").setBody("return false;").addAnnotation(Override.class);

So I'm just wondering if I'm missing something or this is not implemented yet on Roaster

Antonio Goncalves 
Software architect and Java Champion

Web site | Twitter | LinkedIn | Paris JUG | Devoxx France