incorrect "The type mytype is already defined" flag

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

incorrect "The type mytype is already defined" flag

Eric Tiffany
I'm trying to define a class inside a groovy script, which looks something like this:

import blah

x = 1
y = 2

class mytype {
int counter = 1
public mytype(z) {

counter = z
}

m = new mytype(y)


Somehow, the groovy plugin has become convinced that mytype is already defined.  

If I delete the class definition from the script, and put the definition in a "real" groovy class file by itself, Eclipse then thinks the class definition in the new file is already defined.  

I have searched my entire workspace and it is not defined anywhere else.

I'm not sure how I could repeat this to file a bug; all I want to know is how do I get Eclipse out of this lose state?


ET




Reply | Threaded
Open this post in threaded view
|

Re: incorrect "The type mytype is already defined" flag

Andrew Eisenberg
It's possible that there is a working copy of a Groovy Class being
stored somewhere but not released.  I'd like to get to the bottom of
this.

Just to be clear, does your problem appear when class mytype is
defined inside of your script, or when it is defined outside of it?
What is the name of the script?  Is this compilable on the command
line?

If you can reproduce this problem in another project, then please send it over.

A short term fix might be to close the project and re-open it.

On Tue, Jun 1, 2010 at 10:06 AM, Eric Tiffany <[hidden email]> wrote:

> I'm trying to define a class inside a groovy script, which looks something
> like this:
> import blah
> x = 1
> y = 2
> class mytype {
> int counter = 1
> public mytype(z) {
> counter = z
> }
> m = new mytype(y)
>
> Somehow, the groovy plugin has become convinced that mytype is already
> defined.
> If I delete the class definition from the script, and put the definition in
> a "real" groovy class file by itself, Eclipse then thinks the class
> definition in the new file is already defined.
> I have searched my entire workspace and it is not defined anywhere else.
> I'm not sure how I could repeat this to file a bug; all I want to know is
> how do I get Eclipse out of this lose state?
>
> ET
>
>
>
>

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

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: incorrect "The type mytype is already defined" flag

Eric Tiffany
This started with a class that I had defined inside a script -- it was also defined in another script and I copied it from there.  That's probably where eclipse got confused (even though the two scripts are completely independent).

renaming the class in one of the scripts had no effect.

closing and reopening the files had no effect.  

I didn't try restarting eclipse.

Moving the class to a separate groovy class file made the error move with the class; eclipse now complained that the class in the groovy class file was already defined.

However, I solved the problem like this:

1.  Delete the class from the class file, and save that file.

2.  Save the script file (without the class), then open it copy the class definition back in, and save the file again.

I guess I'll consider this a weird corner case, but if it pops up again I'll invest some more energy.

Thanks,

ET

On Jun 1, 2010, at 1:21 PM, Andrew Eisenberg wrote:

> It's possible that there is a working copy of a Groovy Class being
> stored somewhere but not released.  I'd like to get to the bottom of
> this.
>
> Just to be clear, does your problem appear when class mytype is
> defined inside of your script, or when it is defined outside of it?
> What is the name of the script?  Is this compilable on the command
> line?
>
> If you can reproduce this problem in another project, then please send it over.
>
> A short term fix might be to close the project and re-open it.
>
> On Tue, Jun 1, 2010 at 10:06 AM, Eric Tiffany <[hidden email]> wrote:
>> I'm trying to define a class inside a groovy script, which looks something
>> like this:
>> import blah
>> x = 1
>> y = 2
>> class mytype {
>> int counter = 1
>> public mytype(z) {
>> counter = z
>> }
>> m = new mytype(y)
>>
>> Somehow, the groovy plugin has become convinced that mytype is already
>> defined.
>> If I delete the class definition from the script, and put the definition in
>> a "real" groovy class file by itself, Eclipse then thinks the class
>> definition in the new file is already defined.
>> I have searched my entire workspace and it is not defined anywhere else.
>> I'm not sure how I could repeat this to file a bug; all I want to know is
>> how do I get Eclipse out of this lose state?
>>
>> ET
>>
>>
>>
>>
>
> ---------------------------------------------------------------------
> 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: incorrect "The type mytype is already defined" flag

Jayet, Patrick
Hi Eric,

This reminds me of an issue I had once.

If you have a script file (let's say Foo.groovy) and you try to define a class named Foo inside it, you get the error you mention, since Groovy already implicitly generates a class 'Foo' for the script.

Let me give an example. You have two groovy scripts as follows:

---
// Foo.groovy
package baz

def doIt() {
        println "I am Foo"
}

---
// Bar.groovy
package baz

Foo f = new Foo()
f.doIt()

---

If you execute Bar.groovy, you get 'I am Foo' printed out. So you can invoke directly Foo like if it was a class, since the class is implicitly defined by Groovy. That's the reason why we cannot redefine a class of the same name than its parent script.

Is it the configuration you had?

Hope it helps.
Cheers,

Patrick

-----Original Message-----
From: Eric Tiffany [mailto:[hidden email]]
Sent: Dienstag, 1. Juni 2010 19:55
To: [hidden email]
Subject: Re: [groovy-eclipse-plugin-user] incorrect "The type mytype is already defined" flag

This started with a class that I had defined inside a script -- it was also defined in another script and I copied it from there.  That's probably where eclipse got confused (even though the two scripts are completely independent).

renaming the class in one of the scripts had no effect.

closing and reopening the files had no effect.  

I didn't try restarting eclipse.

Moving the class to a separate groovy class file made the error move with the class; eclipse now complained that the class in the groovy class file was already defined.

However, I solved the problem like this:

1.  Delete the class from the class file, and save that file.

2.  Save the script file (without the class), then open it copy the class definition back in, and save the file again.

I guess I'll consider this a weird corner case, but if it pops up again I'll invest some more energy.

Thanks,

ET



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

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: incorrect "The type mytype is already defined" flag

Eric Tiffany
Thanks, but that's not my scenario.

The file is something_random.groovy, and the class inside is named myclass.

I think that something in eclipse (either the groovy plugin or something deeper) was holding on to a reference that it saw in another script, and got stuck.

ET

On Jun 1, 2010, at 3:43 PM, Jayet, Patrick wrote:

> Hi Eric,
>
> This reminds me of an issue I had once.
>
> If you have a script file (let's say Foo.groovy) and you try to define a class named Foo inside it, you get the error you mention, since Groovy already implicitly generates a class 'Foo' for the script.
>
> Let me give an example. You have two groovy scripts as follows:
>
> ---
> // Foo.groovy
> package baz
>
> def doIt() {
> println "I am Foo"
> }
>
> ---
> // Bar.groovy
> package baz
>
> Foo f = new Foo()
> f.doIt()
>
> ---
>
> If you execute Bar.groovy, you get 'I am Foo' printed out. So you can invoke directly Foo like if it was a class, since the class is implicitly defined by Groovy. That's the reason why we cannot redefine a class of the same name than its parent script.
>
> Is it the configuration you had?
>
> Hope it helps.
> Cheers,
>
> Patrick
>
> -----Original Message-----
> From: Eric Tiffany [mailto:[hidden email]]
> Sent: Dienstag, 1. Juni 2010 19:55
> To: [hidden email]
> Subject: Re: [groovy-eclipse-plugin-user] incorrect "The type mytype is already defined" flag
>
> This started with a class that I had defined inside a script -- it was also defined in another script and I copied it from there.  That's probably where eclipse got confused (even though the two scripts are completely independent).
>
> renaming the class in one of the scripts had no effect.
>
> closing and reopening the files had no effect.  
>
> I didn't try restarting eclipse.
>
> Moving the class to a separate groovy class file made the error move with the class; eclipse now complained that the class in the groovy class file was already defined.
>
> However, I solved the problem like this:
>
> 1.  Delete the class from the class file, and save that file.
>
> 2.  Save the script file (without the class), then open it copy the class definition back in, and save the file again.
>
> I guess I'll consider this a weird corner case, but if it pops up again I'll invest some more energy.
>
> Thanks,
>
> ET
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>   http://xircles.codehaus.org/manage_email
>
>

ET
--
  ___/ __  __/    [hidden email]
 __/      /     mobile +1-413-627-1778
____/    _/              skype et01267



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

    http://xircles.codehaus.org/manage_email