Problem with Singleton AST Transformation with groovy-eclipse-compiler 2.5.1-1

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

Problem with Singleton AST Transformation with groovy-eclipse-compiler 2.5.1-1

Carr, Brian M
Hello,

The groovy-eclipse-compiler for Maven is failing to compile code which depends on a class with the Singleton AST transformation.

Example:
//groovy
@Singleton
class Foo {
}

//java
public class Bar {
  public void someMethod() {
    Foo.getInstance()
  }
}


While in eclipse, the resolution works fine.


any suggestions?

--b
___________________________
Brian M. Carr
Senior Software Engineer
Identity Management, ITS Applications
University of Texas at Austin
V: 512-232-6419
F: 512-471-5746
[hidden email]


smime.p7s (6K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Problem with Singleton AST Transformation with groovy-eclipse-compiler 2.5.1-1

Andy Clement
Hi Brian,

I'm a bit confused.  You mentioned:

> While in eclipse, the resolution works fine.
That seems strange, I wouldn't expect it to work in Eclipse.  At the
time the Java compiler looks up the 'getInstance()' method, the
Singleton transform hasn't run.  When I just tried it, I got an error
in the Java type (as expected):

"The method getInstance() is undefined for the type Foo"

Do you have the groovy type and the Java type in different projects? I
would expect it to work then (as the groovy type is entirely compiled
before the Java type).

If you have it working, can you share your project with me that shows
it behaving, and I'll check whats up.

The groovy-eclipse-compiler for maven should, I believe, fail in the same way.

cheers,
Andy

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

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: Problem with Singleton AST Transformation with groovy-eclipse-compiler 2.5.1-1

Carr, Brian M
In eclipse, on the java file, you see the red 'X' next to the line in the editor, however, the file itself is not marked as errored, and a class file is generated.

If you run a test against the Java file, it works as expected.  

This is in contrast to the maven compilation which fails completely.

--b
___________________________
Brian M. Carr
Senior Software Engineer
Identity Management, ITS Applications
University of Texas at Austin
V: 512-232-6419
F: 512-471-5746
[hidden email]

On Sep 26, 2011, at 3:40 PM, Andy Clement wrote:

> Hi Brian,
>
> I'm a bit confused.  You mentioned:
>
>> While in eclipse, the resolution works fine.
> That seems strange, I wouldn't expect it to work in Eclipse.  At the
> time the Java compiler looks up the 'getInstance()' method, the
> Singleton transform hasn't run.  When I just tried it, I got an error
> in the Java type (as expected):
>
> "The method getInstance() is undefined for the type Foo"
>
> Do you have the groovy type and the Java type in different projects? I
> would expect it to work then (as the groovy type is entirely compiled
> before the Java type).
>
> If you have it working, can you share your project with me that shows
> it behaving, and I'll check whats up.
>
> The groovy-eclipse-compiler for maven should, I believe, fail in the same way.
>
> cheers,
> Andy
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>


smime.p7s (6K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Problem with Singleton AST Transformation with groovy-eclipse-compiler 2.5.1-1

Andy Clement
Oh yes, the old 'not running ast transforms as part of reconciling' -
thats why the editor shows the X and not the problems view.  Putting
that aside, under Eclipse you do indeed appear to be getting away with
it in this @Singleton case in terms of Java code depending on
transformed groovy code - that isn't always guaranteed to work.

Anyway, please raise a jira for the maven situation, we'll have a look
- there is clearly an inconsistency, it should really either work in
both scenarios or fail in both scenarios.

cheers,
Andy

On 26 September 2011 13:44, Carr, Brian M <[hidden email]> wrote:

> In eclipse, on the java file, you see the red 'X' next to the line in the editor, however, the file itself is not marked as errored, and a class file is generated.
>
> If you run a test against the Java file, it works as expected.
>
> This is in contrast to the maven compilation which fails completely.
>
> --b
> ___________________________
> Brian M. Carr
> Senior Software Engineer
> Identity Management, ITS Applications
> University of Texas at Austin
> V: 512-232-6419
> F: 512-471-5746
> [hidden email]
>
> On Sep 26, 2011, at 3:40 PM, Andy Clement wrote:
>
>> Hi Brian,
>>
>> I'm a bit confused.  You mentioned:
>>
>>> While in eclipse, the resolution works fine.
>> That seems strange, I wouldn't expect it to work in Eclipse.  At the
>> time the Java compiler looks up the 'getInstance()' method, the
>> Singleton transform hasn't run.  When I just tried it, I got an error
>> in the Java type (as expected):
>>
>> "The method getInstance() is undefined for the type Foo"
>>
>> Do you have the groovy type and the Java type in different projects? I
>> would expect it to work then (as the groovy type is entirely compiled
>> before the Java type).
>>
>> If you have it working, can you share your project with me that shows
>> it behaving, and I'll check whats up.
>>
>> The groovy-eclipse-compiler for maven should, I believe, fail in the same way.
>>
>> cheers,
>> Andy
>>
>> ---------------------------------------------------------------------
>> 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: Problem with Singleton AST Transformation with groovy-eclipse-compiler 2.5.1-1

Andy Clement
Ok, I've done some digging.

As I put in my first response, I didn't think this should really work.
 Lets ignore the red X in the editor and concentrate on the real
editor in the problems view.  If I define the two files as you had
them in your project:

@Singleton
class Foo { }

public class Bar {
 public void someMethod() {
   Foo.getInstance()
 }
}

It will compile Bar OK.  Why is that? This is due to the on disk
compiled Foo.class being used to satisfy the Foo lookup when the Bar
class is compiled.  If the files are compiled together, both from
source, it will not compile as the transform hasn't run at the point
getInstance is looked up.  To simulate this behaviour in eclipse, just
do a project clean of the project with the two files above - you will
get the error in the problems view.  A maven compile is like an
eclipse clean compile, all from source with nothing on disk to confuse
the issue.  Hence maven always fails.

The bug really is that there is a way you can get away with this
reference and the java code will successfully build on an incremental
build if the groovy code has previously been built.  Stopping that
from happening is tricky.  I raised
http://jira.codehaus.org/browse/GRECLIPSE-1209 to make a note of it.
We could special case full builds so that they are aware this method
is coming in via transform - but I am not a great fan of special
casing for transforms in the compiler (it'll only work for those I
choose to add, not in the general case).

cheers
Andy

On 26 September 2011 14:24, Andy Clement <[hidden email]> wrote:

> Oh yes, the old 'not running ast transforms as part of reconciling' -
> thats why the editor shows the X and not the problems view.  Putting
> that aside, under Eclipse you do indeed appear to be getting away with
> it in this @Singleton case in terms of Java code depending on
> transformed groovy code - that isn't always guaranteed to work.
>
> Anyway, please raise a jira for the maven situation, we'll have a look
> - there is clearly an inconsistency, it should really either work in
> both scenarios or fail in both scenarios.
>
> cheers,
> Andy
>
> On 26 September 2011 13:44, Carr, Brian M <[hidden email]> wrote:
>> In eclipse, on the java file, you see the red 'X' next to the line in the editor, however, the file itself is not marked as errored, and a class file is generated.
>>
>> If you run a test against the Java file, it works as expected.
>>
>> This is in contrast to the maven compilation which fails completely.
>>
>> --b
>> ___________________________
>> Brian M. Carr
>> Senior Software Engineer
>> Identity Management, ITS Applications
>> University of Texas at Austin
>> V: 512-232-6419
>> F: 512-471-5746
>> [hidden email]
>>
>> On Sep 26, 2011, at 3:40 PM, Andy Clement wrote:
>>
>>> Hi Brian,
>>>
>>> I'm a bit confused.  You mentioned:
>>>
>>>> While in eclipse, the resolution works fine.
>>> That seems strange, I wouldn't expect it to work in Eclipse.  At the
>>> time the Java compiler looks up the 'getInstance()' method, the
>>> Singleton transform hasn't run.  When I just tried it, I got an error
>>> in the Java type (as expected):
>>>
>>> "The method getInstance() is undefined for the type Foo"
>>>
>>> Do you have the groovy type and the Java type in different projects? I
>>> would expect it to work then (as the groovy type is entirely compiled
>>> before the Java type).
>>>
>>> If you have it working, can you share your project with me that shows
>>> it behaving, and I'll check whats up.
>>>
>>> The groovy-eclipse-compiler for maven should, I believe, fail in the same way.
>>>
>>> cheers,
>>> Andy
>>>
>>> ---------------------------------------------------------------------
>>> 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: Problem with Singleton AST Transformation with groovy-eclipse-compiler 2.5.1-1

Carr, Brian M
Hmm, I see.  I don't agree with special-casing it either, however, being unable to cross compile code which uses AST transformations is a drag.  The workaround is to create a method,

T getJavaInstance() { getInstance() }

in the groovy class, but it's ugly and tedious.

I'm not an expert in compilers, but would it be possible to have a 2-pass compilation that creates class files for anything that uses an ast transform, then have the 2nd pass depend on the compiled class files?

--b
___________________________
Brian M. Carr
Senior Software Engineer
Identity Management, ITS Applications
University of Texas at Austin
V: 512-232-6419
F: 512-471-5746
[hidden email]

On Sep 26, 2011, at 5:08 PM, Andy Clement wrote:

> Ok, I've done some digging.
>
> As I put in my first response, I didn't think this should really work.
> Lets ignore the red X in the editor and concentrate on the real
> editor in the problems view.  If I define the two files as you had
> them in your project:
>
> @Singleton
> class Foo { }
>
> public class Bar {
> public void someMethod() {
>   Foo.getInstance()
> }
> }
>
> It will compile Bar OK.  Why is that? This is due to the on disk
> compiled Foo.class being used to satisfy the Foo lookup when the Bar
> class is compiled.  If the files are compiled together, both from
> source, it will not compile as the transform hasn't run at the point
> getInstance is looked up.  To simulate this behaviour in eclipse, just
> do a project clean of the project with the two files above - you will
> get the error in the problems view.  A maven compile is like an
> eclipse clean compile, all from source with nothing on disk to confuse
> the issue.  Hence maven always fails.
>
> The bug really is that there is a way you can get away with this
> reference and the java code will successfully build on an incremental
> build if the groovy code has previously been built.  Stopping that
> from happening is tricky.  I raised
> http://jira.codehaus.org/browse/GRECLIPSE-1209 to make a note of it.
> We could special case full builds so that they are aware this method
> is coming in via transform - but I am not a great fan of special
> casing for transforms in the compiler (it'll only work for those I
> choose to add, not in the general case).
>
> cheers
> Andy
>
> On 26 September 2011 14:24, Andy Clement <[hidden email]> wrote:
>> Oh yes, the old 'not running ast transforms as part of reconciling' -
>> thats why the editor shows the X and not the problems view.  Putting
>> that aside, under Eclipse you do indeed appear to be getting away with
>> it in this @Singleton case in terms of Java code depending on
>> transformed groovy code - that isn't always guaranteed to work.
>>
>> Anyway, please raise a jira for the maven situation, we'll have a look
>> - there is clearly an inconsistency, it should really either work in
>> both scenarios or fail in both scenarios.
>>
>> cheers,
>> Andy
>>
>> On 26 September 2011 13:44, Carr, Brian M <[hidden email]> wrote:
>>> In eclipse, on the java file, you see the red 'X' next to the line in the editor, however, the file itself is not marked as errored, and a class file is generated.
>>>
>>> If you run a test against the Java file, it works as expected.
>>>
>>> This is in contrast to the maven compilation which fails completely.
>>>
>>> --b
>>> ___________________________
>>> Brian M. Carr
>>> Senior Software Engineer
>>> Identity Management, ITS Applications
>>> University of Texas at Austin
>>> V: 512-232-6419
>>> F: 512-471-5746
>>> [hidden email]
>>>
>>> On Sep 26, 2011, at 3:40 PM, Andy Clement wrote:
>>>
>>>> Hi Brian,
>>>>
>>>> I'm a bit confused.  You mentioned:
>>>>
>>>>> While in eclipse, the resolution works fine.
>>>> That seems strange, I wouldn't expect it to work in Eclipse.  At the
>>>> time the Java compiler looks up the 'getInstance()' method, the
>>>> Singleton transform hasn't run.  When I just tried it, I got an error
>>>> in the Java type (as expected):
>>>>
>>>> "The method getInstance() is undefined for the type Foo"
>>>>
>>>> Do you have the groovy type and the Java type in different projects? I
>>>> would expect it to work then (as the groovy type is entirely compiled
>>>> before the Java type).
>>>>
>>>> If you have it working, can you share your project with me that shows
>>>> it behaving, and I'll check whats up.
>>>>
>>>> The groovy-eclipse-compiler for maven should, I believe, fail in the same way.
>>>>
>>>> cheers,
>>>> Andy
>>>>
>>>> ---------------------------------------------------------------------
>>>> 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
>
>


smime.p7s (6K) Download Attachment