Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-11489

In-project extension methods

    XMLWordPrintableJSON

Details

    • Wish
    • Status: Closed
    • Major
    • Resolution: Duplicate
    • 4.0.23
    • None
    • Compiler
    • None

    Description

      I make thorough use of extension methods to build DSLs both for libraries and for business applications, but the limitation that extension methods have to exist before the compilation unit starts is a major drawback (for example, I can't define extension methods on some library type that refer to business-domain objects). While dabbling with Kotlin for an Android app, I noticed that Kotlin manages the selection of extension methods by using import static to specify the method, allowing references to extension methods that reside in the compilation unit where they're consumed.

      It would be a major quality-of-life improvement to be able to define extension methods in the same place where they're used. I can think of a number of approaches that might work, in approximate descending order of convenience:

      1. Consider the local compilation unit's META-INF entry for extension methods.
      2. Use import static or similar syntax to specifically identify extension methods that should be considered.
      3. Provide an annotation applied to the class providing the extension methods that would cause the compiler to make them available.
      4. Provide an annotation applied to the consuming class specifying where to look.

      #3 might have some chicken-and-egg problems relating to partial compilation, but the others may be less tricky.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              chrylis Christopher Smith
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: