empty groovy classes generated
Hi!
Today I tried starting using groovy support, I activated the JetGroovy plugin in the hope to being able to use all the new cool stuff ;-)
I am on diana 9825 (jdk 1.6.0_13 64-bit) and use jdk 1.6.0_13 (i586 or 64-bit makes no difference) for the project and Groovy-All 1.6.3.
I've configured the Groovy faces to compile the Groovy source.
Then, I started with a VERY simple Groovy bean
class MyFirstGroovy
{
String textString;
public String xyzString;
}
and tried using it from a java test class
public void testPropertyChange()
{
MyFirstGroovy groovy = new MyFirstGroovy();
groovy.xyzString = "abc";
assertEquals("abc", groovy.xyzString);
groovy.setTextString("any String");
assertEquals("any String", groovy.getTextString()); // this failes as textString returns null instead of "any String"
}
To my very surprise, this test failed at the second assertEquals, when I tried the setter/getter stuff.
I struggled around a little bit, and when trying groovyc from the command line it worked.
I then tried this and that, until I reached the point where I javaped the created class file.
As you can see from this output
javap.exe -c com.ops.MyFirstGroovy
Compiled from "MyFirstGroovy.java"
public class com.ops.MyFirstGroovy extends java.lang.Object implements groovy.lang.GroovyObject{
public java.lang.String xyzString;
public com.ops.MyFirstGroovy();
Code:
0: aload_0
1: invokespecial #1; //Method java/lang/Object."<init>":()V
4: aload_0
5: aconst_null
6: putfield #2; //Field textString:Ljava/lang/String;
9: aload_0
10: aconst_null
11: putfield #3; //Field xyzString:Ljava/lang/String;
14: return
public java.lang.String getTextString();
Code:
0: aconst_null
1: areturn
public void setTextString(java.lang.String);
Code:
0: return
public groovy.lang.MetaClass getMetaClass();
Code:
0: aconst_null
1: areturn
public void setMetaClass(groovy.lang.MetaClass);
Code:
0: return
public java.lang.Object invokeMethod(java.lang.String, java.lang.Object);
Code:
0: aconst_null
1: areturn
public java.lang.Object getProperty(java.lang.String);
Code:
0: aconst_null
1: areturn
public void setProperty(java.lang.String, java.lang.Object);
Code:
0: return
}
The class code is almost empty. You have the class variables, the methods, but no method body. Cleary that this class wont work.
When doing a "rebuild all" then, a reasonable class has been generated and the test works. I then added an empty line to MyFirstGroovy and triggered a build. Voila, the class file is the dumb empty one again, the test failes.
Strange enough, when I create an all new IDEA project, this behaviour can not be seen.
An help will be appreciated.
Thanks!
Ciao,
Mario
(Sorry if this is a double post, I think the previous post has not been sent by my NNTP client)
Please sign in to leave a comment.
Additional findings are, that, even if I configured the facet to "compile" it copies the .groovy file over to the output instead of compiling it.
What I can see is, that close after the compilation started, the dumb class file is generated, at the end of the compile, instead of starting the groovy compiler, just the groovy source are copied there.
Ok, I recreated the project by creating a new empty project without modules and importing the old modules into this project. The problem now went away.
When looking at the project diff file I found that I had a wildcard resource pattern (compiler) of !?*.java, which seems to let the compiler think the groovy file is a resource as it matches the resource pattern.
Changing that setting to the IDEA default (?*.properties;?*.xml;?*.gif;?*.png;?*.jpeg;?*.jpg;?*.html;?*.dtd;?*.tld;?*.ftl) fixed the problem too :-)