groovy
  1. groovy
  2. GROOVY-6043

Precompiled typechecking extension scripts

    Details

    • Type: Improvement Improvement
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.2.0-beta-1
    • Component/s: Static Type Checker
    • Labels:
      None
    • Number of attachments :
      0

      Description

      It would be rather desirable to allow pre-compiled typechecking scripts, if reasonably possible.

      Not only the repeated compilation of the script considerably increases the build time (and with hundreds of sources the difference is not negligible); besides, if one uses AST transforms, they get each time applied to the script, too.

      Most transforms are probably not written to do that – myself, I had to check explicitly for sourceUnit.name=='Script1.groovy' and skip the transform in this case, but that's an extremely ugly and highly fragile solution.

        Activity

        Hide
        Cédric Champeau added a comment -

        Support has been pushed to master. Technically, you have to use:

        @TypeChecked(extensions='fully.qualified.class.Name')
        void foo() { ... }
        

        The extension can be pre-compiled using:

        groovyc -b org.codehaus.groovy.transform.stc.GroovyTypeCheckingExtensionSupport.TypeCheckingDSL MyExtension.groovy
        

        Or you can use a class wrapping the script, like the unit test does:

        package groovy.transform.stc
        
        import org.codehaus.groovy.transform.stc.GroovyTypeCheckingExtensionSupport
        
        class PrecompiledExtension extends GroovyTypeCheckingExtensionSupport.TypeCheckingDSL {
        
            Object run() {
                // body of the script
                setup {
                    addStaticTypeError('Error thrown from extension', context.enclosingClassNode)
                }
            }
        }
        
        Show
        Cédric Champeau added a comment - Support has been pushed to master . Technically, you have to use: @TypeChecked(extensions='fully.qualified.class.Name') void foo() { ... } The extension can be pre-compiled using: groovyc -b org.codehaus.groovy.transform.stc.GroovyTypeCheckingExtensionSupport.TypeCheckingDSL MyExtension.groovy Or you can use a class wrapping the script, like the unit test does: package groovy.transform.stc import org.codehaus.groovy.transform.stc.GroovyTypeCheckingExtensionSupport class PrecompiledExtension extends GroovyTypeCheckingExtensionSupport.TypeCheckingDSL { Object run() { // body of the script setup { addStaticTypeError('Error thrown from extension', context.enclosingClassNode) } } }

          People

          • Assignee:
            Cédric Champeau
            Reporter:
            OC
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: