Objects not visible in mixed Eclipse Project

View: New views
5 Messages — Rating Filter:   Alert me  

Objects not visible in mixed Eclipse Project

by Bastian, Mark :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Objects not visible in mixed Eclipse Project When I add the Scala nature to a Java Project in Eclipse by right-clicking and selecting Scala => Add Scala Nature everything seems to work fine and I can now mix my .java and .scala class files for compilation.  I can mix my classes across languages.  However, this only seems to work for classes and not for objects.  When I create a standalone object or try to refer to a class companion object with ObjectName$.MODULE$ Eclipse is unable to locate the object.  Autocomplete pops up the classes from my .scala files but none of the objects.  If I just type the objects in an error occurs.  I can see the object .class files in the bin directory, but Eclipse just doesn’t see them.

Can anyone else verify that this problem is or is not happening for them?  I am using the nightly build of the scala plugin.

Thanks,
Mark

Re: Objects not visible in mixed Eclipse Project

by Miles Sabin :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Mon, Aug 4, 2008 at 11:02 PM, Bastian, Mark <mbastia@...> wrote:

> When I add the Scala nature to a Java Project in Eclipse by right-clicking
> and selecting Scala => Add Scala Nature everything seems to work fine and I
> can now mix my .java and .scala class files for compilation.  I can mix my
> classes across languages.  However, this only seems to work for classes and
> not for objects.  When I create a standalone object or try to refer to a
> class companion object with ObjectName$.MODULE$ Eclipse is unable to locate
> the object.  Autocomplete pops up the classes from my .scala files but none
> of the objects.  If I just type the objects in an error occurs.  I can see
> the object .class files in the bin directory, but Eclipse just doesn't see
> them.
>
> Can anyone else verify that this problem is or is not happening for them?  I
> am using the nightly build of the scala plugin.

Yes, I can confirm this behaviour. I haven't had the time to get to
the bottom of it yet, but my hunch is that scalac is marking
ObjectName$.MODULE$ as a synthetic field and the JDT is refusing to
let Java code reference it.

Cheers,


Miles

Re: Objects not visible in mixed Eclipse Project

by Iulian Dragos-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Miles Sabin wrote:
> On Mon, Aug 4, 2008 at 11:02 PM, Bastian, Mark <mbastia@...> wrote:
>>
>> Can anyone else verify that this problem is or is not happening for them?  I
>> am using the nightly build of the scala plugin.
>
> Yes, I can confirm this behaviour. I haven't had the time to get to
> the bottom of it yet, but my hunch is that scalac is marking
> ObjectName$.MODULE$ as a synthetic field and the JDT is refusing to
> let Java code reference it.

MODULE$ is not marked as synthetic (at least not by scalac in the trunk,
which is the same since we're talking about the plugin). There must be
something else. As long as there's no companion class, scalac should
emit a 'mirror class' which has static forwarders to the MODULE$
instance, with the same name as the object. That doesn't work either?

Iulian


Re: Re: Objects not visible in mixed Eclipse Project

by Bastian, Mark :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Re: [scala-user]  Re: Objects not visible in mixed Eclipse Project That’s what I mean by ObjectName$ in ObjectName$.MODULE$.  ObjectName would be a class called ObjectName with a companion object of ObjectName in the same file.  When you follow this pattern, nether ObjectName$ nor ObjectName$.MODULE$ are visible.  You can’t see top level objects, either.  As an aside, if you set bin as a class folder on your class path you can see the missing items.

-Mark

On 8/6/08 3:42 AM, "Iulian Dragos" <iulian.dragos@...> wrote:

Miles Sabin wrote:
> On Mon, Aug 4, 2008 at 11:02 PM, Bastian, Mark <mbastia@...> wrote:
>>
>> Can anyone else verify that this problem is or is not happening for them?  I
>> am using the nightly build of the scala plugin.
>
> Yes, I can confirm this behaviour. I haven't had the time to get to
> the bottom of it yet, but my hunch is that scalac is marking
> ObjectName$.MODULE$ as a synthetic field and the JDT is refusing to
> let Java code reference it.

MODULE$ is not marked as synthetic (at least not by scalac in the trunk,
which is the same since we're talking about the plugin). There must be
something else. As long as there's no companion class, scalac should
emit a 'mirror class' which has static forwarders to the MODULE$
instance, with the same name as the object. That doesn't work either?

Iulian





Re: Objects not visible in mixed Eclipse Project

by Seth Tisue :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

>>>>> "Miles" == Miles Sabin <miles@...> writes:

 Miles> Yes, I can confirm this behaviour. I haven't had the time to get
 Miles> to the bottom of it yet, but my hunch is that scalac is marking
 Miles> ObjectName$.MODULE$ as a synthetic field and the JDT is refusing
 Miles> to let Java code reference it.

Not sure, but perhaps https://lampsvn.epfl.ch/trac/scala/ticket/1210
(which I filed just now) is relevant.  Note the workaround.

--
Seth Tisue / http://tisue.net
lead developer, NetLogo: http://ccl.northwestern.edu/netlogo/