Issue Details (XML | Word | Printable)

Key: GROOVY-1978
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Jochen Theodorou
Reporter: Jason Weden
Votes: 2
Watchers: 2
Operations

If you were logged in you would be able to see more operations.
groovy

static imports not working with groovy classes

Created: 13/Jul/07 07:35 AM   Updated: 21/Sep/07 07:37 AM   Resolved: 21/Sep/07 07:08 AM
Return to search
Component/s: groovy-jdk
Affects Version/s: 1.1-beta-2
Fix Version/s: 1.1-rc-1

Time Tracking:
Not Specified

Environment: red hat linux


 Description  « Hide

Re: problem with static imports Click to flag this post

by Paul King Jul 12, 2007; 05:47pm :: Rate this Message: (use ratings to moderate[?])

Reply | Reply to Author | Show Only this Message

Looks like a bug.

If I follow the steps as you suggest I can replicate the error.
If I add "groovyc com/test1/Runner.groovy" then I can invoke
"groovy com/test1/Runner.groovy" with no problem.

Please raise an issue.

Paul.

Jason Weden wrote:
> Paul, thanks for your reply. That "static" keyword in the class definition
> shouldn't have been in there. Could you tell me what's different between
> your setup and mine? It's still isn't working for me:
>
> [nvw384@ma34jasper sandbox]$ groovy -version
> Groovy Version: 1.1-beta-2 JVM: 1.5.0_11-b03
>
> [nvw384@ma34jasper sandbox]$ less com/test1/Runner.groovy
>
> package com.test1
>
> import static com.test1.test2.Utils.*
>
> printMe('hello world');
>
> [nvw384@ma34jasper sandbox]$ less com/test1/test2/Utils.groovy
> package com.test1.test2
>
> class Utils {
> static printMe (aString) { > println "$aString" > }
> }
>
> [nvw384@ma34jasper sandbox]$ groovy com/test1/Runner.groovy
> Caught: groovy.lang.MissingMethodException: No signature of method:
> com.test1.Runner.printMe() is applicable for argument types:
> (java.lang.String) values: {"hello world"}
> at com.test1.Runner.run(Runner.groovy:6)
> at com.test1.Runner.main(Runner.groovy)
>
>
>
>



Graeme Rocher made changes - 20/Jul/07 09:16 AM
Field Original Value New Value
Assignee Jochen Theodorou [ blackdrag ]
Fix Version/s 1.1-beta-3 [ 13590 ]
Jochen Theodorou added a comment - 20/Jul/07 11:42 AM

ok, after looking into this I found the reason... at the point the ResolveVisitor finds the static import the class is not yet parsed. Which means finding the static method must be done at a later step than it is currently done.


Jochen Theodorou added a comment - 20/Jul/07 01:35 PM

I splitted ResolveVisitor inot the normal resolving process and a StaticImportVisitor that is doing only static imports. The new class works after ResolveVisitor was run and should then no longer have a problem with not yet parsed classes.


Jochen Theodorou made changes - 20/Jul/07 01:35 PM
Status Open [ 1 ] Closed [ 6 ]
Resolution Fixed [ 1 ]
Jason Weden added a comment - 24/Jul/07 01:10 PM

I'm using snapshot build 447 and this still isn't working for me:

[nvw384@ma34jasper sandbox]$ groovy -version
Groovy Version: 1.1-beta-2 JVM: 1.5.0_11-b03
[nvw384@ma34jasper sandbox]$

nvw384@ma34jasper sandbox]$ echo $GROOVY_HOME
/opt/groovy-1.1-beta-3-SNAPSHOT
[nvw384@ma34jasper sandbox]$ groovy test1/mytest.groovy
Caught: groovy.lang.MissingMethodException: No signature of method: test1.mytest.printMe() is applicable for argument types: () values: {}
at test1.mytest.run(mytest.groovy:5)
at test1.mytest.main(mytest.groovy)

[nvw384@ma34jasper sandbox]$ less test1/mytest.groovy
package test1

import static test1.test2.Utils.*

printMe();

[nvw384@ma34jasper sandbox]$ less test1/test2/Utils.groovy
package test1.test2

class Utils {
def static printMe () { println "hi" }
}


Jason Weden made changes - 24/Jul/07 01:10 PM
Status Closed [ 6 ] Reopened [ 4 ]
Resolution Fixed [ 1 ]
Paul King added a comment - 20/Aug/07 07:04 PM

I did a quick jad of code generated using groovyc. For this code:

import static java.lang.Math.*
println cos(2*PI)

beta-2 generates:

...
            ScriptBytecodeAdapter.invokeStaticMethodN(class1, java.lang.Math.class, "cos", new Object[] {
                ScriptBytecodeAdapter.invokeMethodN(class1, new Integer(2), "multiply", new Object[] {
                    ScriptBytecodeAdapter.getProperty(class1, java.lang.Math.class, "PI")
                })
            })
...

beta-3-SNAPSHOT generates:

...
            ScriptBytecodeAdapter.invokeMethodOnCurrentN(class1, (GroovyObject)ScriptBytecodeAdapter.castToType(this, groovy.lang.GroovyObject.class), "cos", new Object[] {
                ScriptBytecodeAdapter.invokeMethodN(class1, new Integer(2), "multiply", new Object[] {
                    ScriptBytecodeAdapter.getGroovyObjectProperty(class1, this, "PI")
                })
            })
...

The static import visitor seems to be doing the right thing but that isn't reflected in the generated code.


Paul King added a comment - 26/Aug/07 07:32 AM

Can you try again with HEAD. GROOVY-2031 may have fixed this case also.


Guillaume Laforge made changes - 20/Sep/07 03:11 PM
Fix Version/s 1.1-beta-3 [ 13590 ]
Fix Version/s 1.1-rc-1 [ 13165 ]
Paul King added a comment - 21/Sep/07 05:59 AM

I'd like to close this issue. Is it still causing you a problem with beta-3? It works for me here.


Guillaume Laforge added a comment - 21/Sep/07 07:05 AM

If you can't reproduce it with beta-3, you can close it.


Jason Weden added a comment - 21/Sep/07 07:08 AM

Thanks for the nudge. Sorry, I've been so busy. Using the same example code listed in my previous comment, I can see that this is fixed. And.....THANK YOU.

[nvw384@ma34jasper 1978]$ groovy -version
Groovy Version: 1.1-beta-2 JVM: 1.5.0_11-b03

[nvw384@ma34jasper 1978]$ groovy test1/mytest.groovy
Caught: groovy.lang.MissingMethodException: No signature of method: test1.mytest.printMe() is applicable for argument types: () values: {}
at test1.mytest.run(mytest.groovy:5)
at test1.mytest.main(mytest.groovy)

[nvw384@ma34jasper 1978]$ /opt/groovy-1.1-beta-3/bin/groovy test1/mytest.groovy
hi


Jason Weden made changes - 21/Sep/07 07:08 AM
Status Reopened [ 4 ] Resolved [ 5 ]
Resolution Fixed [ 1 ]
Paul King made changes - 21/Sep/07 07:37 AM
Status Resolved [ 5 ] Closed [ 6 ]