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

keyword 'use' like 'import (static)' to use categories in a complete compilation unit

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Open
    • Major
    • Resolution: Unresolved
    • None
    • 4.x
    • None
    • None

    Description

      I'd like to have a keyword 'use' which can be used at the beginning of a file, like a static import, but as category. So:

      The first example from http://groovy.codehaus.org/Groovy+Categories :

      import groovy.xml.*

      def html = /* ... */

      use (groovy.xml.dom.DOMCategory) {
      assert html.head.title.text() == 'Test'
      // ...
      }

      Would then become:

      import groovy.xml.*
      use groovy.xml.dom.DOMCategory

      def html = /* ... */

      assert html.head.title.text() == 'Test'
      assert html.body.p.text() == 'This is a test.'
      // ...

      I think this is extremely usefull when using a category in more then one method.

      Attachments

        Activity

          People

            Unassigned Unassigned
            jogi Jörg Gottschling
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated: