Scala-generated Getters/Setters not accessible by plugin Follow
(Please read my next posting in this thread. It clarifies/enhances the actual problem.)
Forgive me if I am mistaken...
I expect the scala class:
var name: String = ""
var age: Int = 0
will automatically generate getters/setters for the name and age fields. But when I do this in IntelliJ and then try to manipulate MyClass in java via:
public void someJavaMethod()
MyClass myClass = new MyClass();
myClass.setAge( 32 );
I get a compiler error that setAge does not exist.
I understand that, by default, scala will generate not setXXX() and getXXX(), but XXX() and XXX_$eq(). And to get the former I need to used the @BeanProperty annotation. But in either case, NO methods - regardless of how named - are generated for MyClass. (Auto-complete shows no methods other than Object's equals(), hashCode(), toString(), etc)
Please sign in to leave a comment.
I don't know enough about the @BeanProperty annotation to suggest what's going wrong for you. You didn't show the Scala code you wrote with those annotations, so I can't compare it with any information I can find on my own.
My real point is replying is to say that questions about the language itself or its standard libraries are best addressed to the Scala-User (see ) mailing list and this forum used for matters specific to IDEA's support for writing, testing and debugging Scala code.
Thank you for the reply, Randall. When re-reading my original post I see I was not clear that this is an IntelliJ/Scala plug-in issue - not a general scala language issue.
Let me rephrase (and enhance given more recent investigation).
I have decompiled the MyClass.class file (via javap) and found that getters/setters are indeed being generated by the scala compiler within IntelliJ.
The problem I find is that from within IntelliJ, both the java and scala IntelliJ editors do not recognize those generated methods.
1. In the case of scala source, the use of the generated methods are not flagged as errors, but generated methods do not show up in the list of available methods on the automatic completion menu.
2. For Java source, the use of the generated methods are flagged as errors in the IntelliJ java editor.
3. However, the code does compile/build and the methods do work as expected for both java and scala.
So, to restate, here is the real problem I'm having:
- Methods that the scala compiler automatically generates for a scala source file are not available in the command completion menu (in either scala or java IntelliJ editors)
- Those same methods are flagged as "cannot resolve" errors in the java (not scala) editor.
BTW- To have the scala compiler generate JavaBean-style getters/setters you use the scala.reflect.BeanProperty annotation. For the code below, the scala compiler will generate these 4 methods for the "name" field: name(), getName(), name_$eq(String), and setName(String)
var name: String = ""
var age: Int = 0
I see. Well then, now the JetBrains folks know about the issue and will no doubt add it to their list of things to investigate.
By the way, there was a new Scala plug-in release yesterday. Are you running the latest?
And my last point: it's always good to give the specifics of your set-up. I always give these things:
- Scala plug-in version
- IDEA version
- Java version
- OS information
- CPU / Architecture information
Scala Plugin v0.2.25681
IntelliJ IDEA v22.214.171.12486
Java JDK 1.6.0_12
Windows 7 32-bit
Intel Core 2 Duo T9500 @2.60 GHz
Have a look at this related JIRA issue http://www.jetbrains.net/jira/browse/SCL-980 and add your votes.
Thanks, Chris. I have voted for that issue.
Have you also found that - aside from BeanProperties - even scala-named automatically generated getters/setters xxx() and xxx_$eq(type) are inaccessible via the plugin?
This seems to be an outright bug (whereas the BeanProps issue might be considered an enhancement - although one I'd very much like to see addressed).
I just checked and I am seeing the same thing - 1) the implicit Scala accessor/mutator methods are not available via autocomplete when attempting to choose a method on a Scala object reference from within Java code and 2) are highlighted as errors in the editor pane once entered manually.
The implicit accessor/mutator methods and the @BeanProperty annotation are part of the Scala Language specification. In that sense, I'd consider the lack of support a bug in both cases. The plugin presumably needs to add this extra metadata to the Scala class representation exposed throughout the IDE.
* Scala Plugin v0.2.25681
* IntelliJ IDEA 8.1.3, build 9886
* Java .6.0_13-b03-211
* Mac OS X 10.5.7
This problem was fixed in trunk (you can try nightly build tommorow for check).
Still problem for same thing for find usages and rename (so be careful), but it will be fixed too.