Import multiple classes from the same package shortcut?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Import multiple classes from the same package shortcut?

Wujek Srujek
Hi. I have quite a few (static) imports from a certain class that has a huge package name. Is there a way to have any 'shortcut' way to import mulgiple classes, like maybe:

import (static) com.example.some.very.long.package.name.SomeClass {
    NAME_A, NAME_B, NAME_C
}

I know the above won't work, but maybe there is something else available? Of course, I can import .* but I prefer to list what I import explicitly.

wujek
Reply | Threaded
Open this post in threaded view
|

Re: Import multiple classes from the same package shortcut?

Jochen Theodorou
Am 29.09.2011 22:20, schrieb Wujek Srujek:

> Hi. I have quite a few (static) imports from a certain class that has a
> huge package name. Is there a way to have any 'shortcut' way to import
> mulgiple classes, like maybe:
>
> import (static) com.example.some.very.long.package.name.SomeClass {
>      NAME_A, NAME_B, NAME_C
> }
>
> I know the above won't work, but maybe there is something else
> available? Of course, I can import .* but I prefer to list what I import
> explicitly.

you can import multiple things form one class with

import static com.example.some.very.long.package.name.SomeClass.*

but multiple classes not, no

bye blackdrag

--
Jochen "blackdrag" Theodorou - Groovy Project Tech Lead
blog: http://blackdragsview.blogspot.com/
german groovy discussion newsgroup: de.comp.lang.misc
For Groovy programming sources visit http://groovy-lang.org


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

RE: Import multiple classes from the same package shortcut?

Bob Brown
I've got to say I find this syntax quite appealing:

import (static) com.example.some.very.long.package.name.SomeClass {
      NAME_A, NAME_B, NAME_C
}

Nicer than a long sequence of separate import statements and much more
readable than '.*'

It also got me thinking about the interaction between 'import' and '@Grab'
as well.

This 'pattern' bugs me:

@Grab(dependency)
Import some.package

I always want @Grab to "work out" what I need to have imported...the
existing syntax makes me feel like I am duplicating things.

I have long wanted something clearer/more concise, like:

Import some.package@(dependency)

Maybe something like this could clear things up even more:

import  com.example.some.very.long.package.name@(dependency) {
      NAME_A, NAME_B, NAME_C
}

Or, perhaps:

Import @(dependency) {
  com.example.some.very.long.package.name {
      NAME_A, NAME_B, NAME_C
}

Maybe other possibilities can be covered in the same way:

Import @(dependency) {
  com.example.some.very.long.package.name {
      NAME_A,
      NAME_B,
      static NAME_C as N_C
}

Basically, I want Groovy to do the importing for me...

Anyone else?

Cheers,

BOB

> -----Original Message-----
> From: Jochen Theodorou [mailto:[hidden email]]
> Sent: Friday, 30 September 2011 6:36 AM
> To: [hidden email]
> Subject: Re: [groovy-user] Import multiple classes from the same package
> shortcut?
>
> Am 29.09.2011 22:20, schrieb Wujek Srujek:
> > Hi. I have quite a few (static) imports from a certain class that has
> > a huge package name. Is there a way to have any 'shortcut' way to
> > import mulgiple classes, like maybe:
> >
> > import (static) com.example.some.very.long.package.name.SomeClass {
> >      NAME_A, NAME_B, NAME_C
> > }
> >
> > I know the above won't work, but maybe there is something else
> > available? Of course, I can import .* but I prefer to list what I
> > import explicitly.
>
> you can import multiple things form one class with
>
> import static com.example.some.very.long.package.name.SomeClass.*
>
> but multiple classes not, no
>
> bye blackdrag
>
> --
> Jochen "blackdrag" Theodorou - Groovy Project Tech Lead
> blog: http://blackdragsview.blogspot.com/
> german groovy discussion newsgroup: de.comp.lang.misc For Groovy
> programming sources visit http://groovy-lang.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>     http://xircles.codehaus.org/manage_email
>



---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: Import multiple classes from the same package shortcut?

Wujek Srujek
So I would like to refresh this topic ;d i recently did some reading on the new Ceylon language being implemented. Take a look at this:
scroll to the very bottom of the page - it shows the importing stuff that I proposed in my first post. I would really like if Groovy supported that as well, also with aliasing.
Anybody else interested in it?

wujek


On Fri, Sep 30, 2011 at 11:24 AM, Bob Brown <[hidden email]> wrote:
I've got to say I find this syntax quite appealing:

import (static) com.example.some.very.long.package.name.SomeClass {
     NAME_A, NAME_B, NAME_C
}

Nicer than a long sequence of separate import statements and much more
readable than '.*'

It also got me thinking about the interaction between 'import' and '@Grab'
as well.

This 'pattern' bugs me:

@Grab(dependency)
Import some.package

I always want @Grab to "work out" what I need to have imported...the
existing syntax makes me feel like I am duplicating things.

I have long wanted something clearer/more concise, like:

Import some.package@(dependency)

Maybe something like this could clear things up even more:

import  com.example.some.very.long.package.name@(dependency) {
     NAME_A, NAME_B, NAME_C
}

Or, perhaps:

Import @(dependency) {
 com.example.some.very.long.package.name {
     NAME_A, NAME_B, NAME_C
}

Maybe other possibilities can be covered in the same way:

Import @(dependency) {
 com.example.some.very.long.package.name {
     NAME_A,
     NAME_B,
     static NAME_C as N_C
}

Basically, I want Groovy to do the importing for me...

Anyone else?

Cheers,

BOB

> -----Original Message-----
> From: Jochen Theodorou [mailto:[hidden email]]
> Sent: Friday, 30 September 2011 6:36 AM
> To: [hidden email]
> Subject: Re: [groovy-user] Import multiple classes from the same package
> shortcut?
>
> Am 29.09.2011 22:20, schrieb Wujek Srujek:
> > Hi. I have quite a few (static) imports from a certain class that has
> > a huge package name. Is there a way to have any 'shortcut' way to
> > import mulgiple classes, like maybe:
> >
> > import (static) com.example.some.very.long.package.name.SomeClass {
> >      NAME_A, NAME_B, NAME_C
> > }
> >
> > I know the above won't work, but maybe there is something else
> > available? Of course, I can import .* but I prefer to list what I
> > import explicitly.
>
> you can import multiple things form one class with
>
> import static com.example.some.very.long.package.name.SomeClass.*
>
> but multiple classes not, no
>
> bye blackdrag
>
> --
> Jochen "blackdrag" Theodorou - Groovy Project Tech Lead
> blog: http://blackdragsview.blogspot.com/
> german groovy discussion newsgroup: de.comp.lang.misc For Groovy
> programming sources visit http://groovy-lang.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>     http://xircles.codehaus.org/manage_email
>



---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email