Skip to content

Allow configuration annotations from a generator used with @From onto the parameter #279

@SimY4

Description

@SimY4

Consider a generator like this:

@MyAnnotation(value = "Some default")
class MyClassGenerator extends Generator<MyClass> {
  private MyAnnotation myAnnotation;

  ...

  public MyClass generate(SourceOfRandomness random, GenerationStatus status) {
    MyClassFieldGenerator myClassFieldGenerator = gen().make(MyClassFieldGenerator.class);
    myClassFieldGenerator.configure(myAnnotation);
    return new MyClass(myClassFieldGenerator.generate(random, status))
  }

  public void configure(MyAnnotation myAnnotation) {
    this.myAnnotation = myAnnotation;
  }
}

What's interesting about it is that by calling gen().make(MyClassFieldGenerator.class) I can put my configuration annotation on generator class itself to configure defaults on it without calling to myClassFieldGenerator.configure(myAnnotation); explicitly.

But I can't do the same for Generator that is referred from a Property method itself:

@Property
public void myProperty(@From(MyClassGenerator.class) MyClass myClass) {
  // here MyClassGenerator will not receive defaults from annotation present on Generator class.
}

In practice, this means that I have to instantiate default annotation instance myself if it's not provided by the framework which looks like something that could be easily avoided.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions