Skip to content

GeneratorConfiguration fails in Kotlin #77

Closed

Description

@dmcg

OK, bit of an edge case I admit, but I notice that @inrange doesn't work in Kotlin. I believe it is because the Kotlin compiler doesn't support ElementType.TYPE_USE, so that Parameter.getAnnotatedType().getAnnotations() returns an empty array.

TBH I don't grok the significance of TYPE_USE. I'm happy to help if I can - I have a failing Kotlin test case and a passing Java one.

Activity

  1. pholser commented on Jan 2, 2016

    @pholser
    Owner

    ElementType.TYPE_USE is to enable the annotation on constructs like List<@InRange(...) Integer>:

    http://pholser.github.io/junit-quickcheck/site/0.6-alpha-3-SNAPSHOT/usage/configuring.html

    In my opinion, having junit-quickcheck honor configuration annotations on type uses is a nice touch. That, coupled with junit-quickcheck's unabashed JDK >= 8-only mindset, makes me reluctant to undo the additions of ElementType.TYPE_USE on junit-quickcheck's supplied configuration annotations.

  2. dmcg commented on Jan 2, 2016

    @dmcg
    Author

    That's cool - I'm learning there are unsung additions to Java 8!

    If you were to fetch the annotations directly through parameter.getAnnotations() as well as getAnnotatedType().getAnnotations() it would find those added by the Kotlin compiler. Of course you'd then have the problem of how to merge them - is that conceptually hard?

  3. pniederw commented on Jan 3, 2016

    @pniederw

    I've just run into the same problem with @ValuesOf.

    If you were to fetch the annotations directly through parameter.getAnnotations() as well as getAnnotatedType().getAnnotations() it would find those added by the Kotlin compiler.

    +1

    Raised a Kotlin issue for supporting TYPE_USE (https://youtrack.jetbrains.com/issue/KT-10558). However, it will likely take a while until Java 8 constructs are supported in Kotlin, and I'd love to use junit-quickcheck before that happens.

  4. pholser commented on Jan 3, 2016

    @pholser
    Owner

    @dmcg @pniederw Thanks for the info! This'll be interesting to dive into Kotlin a bit.

  5. pholser commented on Jan 4, 2016

    @pholser
    Owner

    @dmcg @pniederw Let me make sure I'm understanding the problem correctly. Is it the case that the Kotlin compiler creates class files such that annotations such as @InRange and @ValuesOf on a method parameter are available via parameter.getAnnotations() but not via parameter.getAnnotatedType().getAnnotations()?

    If so, I suspect that we could ask for both sets of annotations on creation of a ParameterTypeContext and union the sets.

  6. pniederw commented on Jan 4, 2016

    @pniederw

    Is it the case that the Kotlin compiler creates class files such that annotations such as @inrange and @ValuesOf on a method parameter are available via parameter.getAnnotations() but not via parameter.getAnnotatedType().getAnnotations()?

    That's what I've been seeing in my experiments.

    If so, I suspect that we could ask for both sets of annotations on creation of a ParameterTypeContext and union the sets.

    Sounds good, happy to test a snapshot with this change.

  7. dmcg commented on Jan 4, 2016

    @dmcg
    Author

    I concur.

    Thanks for working on this - I want to play with shrinking!

  8. added a commit that references this issue on Jan 9, 2016
  9. pholser commented on Jan 9, 2016

    @pholser
    Owner

    @dmcg @pniederw Give latest 0.6 alpha 3 snapshot at oss.sonatype.org a spin, and let me know if this works any better for you. My admittedly cursory Kotlin tests seemed to honor the config annotations.

  10. dmcg commented on Jan 11, 2016

    @dmcg
    Author

    Couldn't find snapshot on sonatype, but building from source gives expected behaviour for @InRange in Kotlin. Thanks!

  11. added a commit that references this issue on Jan 11, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions