getting various results from Organize Imports

47 views
Skip to first unread message

Sean Wolfe

unread,
May 13, 2015, 1:57:43 AM5/13/15
to scala-i...@googlegroups.com
Is it possible to use cmd-shift-O to pull Java imports for a Scala file?

More generally -- could somebody point me towards detailed information on how Organize Imports (cmd-shift-O) works behind the scenes for scalaide?

Context: I'm working with a Java-based game framework called Libgdx. I think the .classpath file has all the necessary dependencies. However, when I press cmd-shift-O I get no response. It's like I didn't even press the keys. Now, it *is* working in these scenarios:

Organize Imports *is* working correctly under these conditions:
* basic Java project
* basic Scala project
* base Libgdx example code

Any thoughts? Could this be based on the fact that the libgdx project uses Gradle for its dependencies, and now I'm using SBT when converted to Scala?

I'd love more information in general about the guts of organize imports in scalaide -- even a sourcecode reference.

Thanks!

Sean Wolfe

unread,
May 13, 2015, 2:09:24 AM5/13/15
to scala-i...@googlegroups.com
Found some leads here --> https://github.com/scala-ide/scala-ide/search?utf8=✓&q=Organize+Imports

processing ... processing ...

Mirko Stocker

unread,
May 13, 2015, 2:44:14 AM5/13/15
to scala-i...@googlegroups.com
Hi Sean

On Tuesday 12 May 2015 22.57:43 Sean Wolfe wrote:
> Is it possible to use cmd-shift-O to pull Java imports for a Scala file?

Just to make sure I'm getting this right: you have a Scala source file and want
to use Organize Imports to import some Java types?

> More generally -- could somebody point me towards detailed information on
> how Organize Imports (cmd-shift-O) works behind the scenes for scalaide?

Well, only the code tells the truth: the code is split between an IDE part [1]
and the Scala Refactoring project [2]. But I hope there's an easier solution
than having to go through all that code :-)

[1] https://github.com/scala-ide/scala-ide/blob/master/org.scala-ide.sdt.core/src/org/scalaide/refactoring/internal/OrganizeImports.scala

[2] https://github.com/scala-ide/scala-refactoring/blob/master/org.scala-refactoring.library/src/main/scala/scala/tools/refactoring/implementations/OrganizeImports.scala

> Context: I'm working with a Java-based game framework called Libgdx. I
> think the .classpath file has all the necessary dependencies. However, when
> I press cmd-shift-O I get no response. It's like I didn't even press the
> keys.

Is there something in Eclipse's error log?

> Any thoughts? Could this be based on the fact that the libgdx project uses
> Gradle for its dependencies, and now I'm using SBT when converted to Scala?

This shouldn't make any difference, Organize Imports doesn't care where a class
comes from, as long as it's part of the classpath.

Cheers

Mirko

--
Mirko Stocker | mi...@stocker.email
Work: http://ifs.hsr.ch | http://infoq.com
Personal: http://misto.ch | http://twitter.com/m_st

Sean Wolfe

unread,
May 13, 2015, 3:11:30 AM5/13/15
to scala-i...@googlegroups.com, mi...@stocker.email


On Tuesday, May 12, 2015 at 11:44:14 PM UTC-7, Mirko Stocker wrote:
Hi Sean

On Tuesday 12 May 2015 22.57:43 Sean Wolfe wrote:
> Is it possible to use cmd-shift-O to pull Java imports for a Scala file?

Just to make sure I'm getting this right: you have a Scala source file and want
to use Organize Imports to import some Java types?


Yep, that's correct. I'm writing my code in Scala, but leveraging a game framework of Java classes.
 
> Context: I'm working with a Java-based game framework called Libgdx. I
> think the .classpath file has all the necessary dependencies. However, when
> I press cmd-shift-O I get no response. It's like I didn't even press the
> keys.

Is there something in Eclipse's error log?


Is that workspace/.metadata/.plugins/org.eclipse.cdt.core/.log ? if so I'm only getting a single line of output when I close Eclipse -- maybe I need to turn up the loglevel. Is there another error file? Lemme google that for me ...
 
> Any thoughts? Could this be based on the fact that the libgdx project uses
> Gradle for its dependencies, and now I'm using SBT when converted to Scala?

This shouldn't make any difference, Organize Imports doesn't care where a class
comes from, as long as it's part of the classpath.

Cheers

Mirko


Thanks Mirko for the quick reply -- I'll do some more digging and get back to you. Really appreciate it ! 

Sean Wolfe

unread,
May 13, 2015, 3:25:40 AM5/13/15
to scala-i...@googlegroups.com, mi...@stocker.email


On Tuesday, May 12, 2015 at 11:44:14 PM UTC-7, Mirko Stocker wrote:
Hi Sean

Is there something in Eclipse's error log?


Okay, I found the log under workspace/.metadata/.log . However the verbosity is pretty tight. Is there a facility to set the logging level for Eclipse itself? I'll take as verbose as I can get ! 

Simon Schäfer

unread,
May 13, 2015, 4:44:58 AM5/13/15
to scala-i...@googlegroups.com
Scala IDE has its own log in "Scala > Open the log". Ensure that you set the log level to debug in "Preferences > Scala > Logging".
--
You received this message because you are subscribed to the Google Groups "Scala IDE User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-ide-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/scala-ide-user/483c2024-2a7d-4f72-9e8b-3c4dc53d07a9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Sean Wolfe

unread,
May 13, 2015, 7:05:31 PM5/13/15
to scala-i...@googlegroups.com


On Wednesday, May 13, 2015 at 1:44:58 AM UTC-7, Simon Schäfer wrote:

Scala IDE has its own log in "Scala > Open the log". Ensure that you set the log level to debug in "Preferences > Scala > Logging".


Okay cool - so now I am seeing the following error when I try and organize imports with the troublesome file, Start.scala:

2015-05-13 16:02:53,136 INFO [Worker-20] - ScalaOccurrencesFinder - No valid MarkOccurrences index.
2015-05-13 16:02:53,139 DEBUG [Worker-20] - Utils$ - Time elapsed for building mark occurrences index in source Start.scala: 3 ms

Any thoughts? Thanks!

Sean Wolfe

unread,
May 13, 2015, 7:31:38 PM5/13/15
to scala-i...@googlegroups.com
Taking a closer look now -- I seem to have *no* IDE oriented features with this file. If I add a syntax error, I don't get the squiggle underscore showing there's a problem. I *do* get the squiggle in a simple Scala project however.

Where is this functionality supported in the project? I'm looking at .classpath and .project but they are very similar.

Sean Wolfe

unread,
May 13, 2015, 8:34:06 PM5/13/15
to scala-i...@googlegroups.com
Aha! I nearly have it working now. Had to do a few things:

* add my src directories as entries in .classpath
* add external jarfile to my build path.

Currently, Ctrl-Shift-O is triggering the organize -- and eclipse is throwing an exception 'an unhandled exception occurred while creating a change object' followed by the warning 'There are errors in the file. Organizing Imports might produce incorrect results'

I'm seeing this in the debug info. What does 'missing unit' mean in this context?

------------------
2015-05-13 17:27:38,712  INFO [main] - ScalaPresentationCompiler - Missing unit for file /home/sean/stuffs/android-scala/scratchpad/libgdx_scalaide/core/src/main/scala/Start.scala when retrieving errors. Errors will not be shown in this file
2015-05-13 17:27:38,712  INFO [main] - ScalaPresentationCompiler - Map(/LibgdxScalaide/core/src/main/scala/Start.scala -> Start.scala)
------------------

Thanks!


Simon Schäfer

unread,
May 16, 2015, 7:22:22 AM5/16/15
to scala-i...@googlegroups.com


On 05/14/2015 02:34 AM, Sean Wolfe wrote:
Aha! I nearly have it working now. Had to do a few things:

* add my src directories as entries in .classpath
* add external jarfile to my build path.
This sounds like you are managing your classpath manually. You should consider using a build tool, this way you ensure everything is correct and the IDE gets all the information it needs.


Currently, Ctrl-Shift-O is triggering the organize -- and eclipse is throwing an exception 'an unhandled exception occurred while creating a change object' followed by the warning 'There are errors in the file. Organizing Imports might produce incorrect results'
There is probably an exception logged in the Error Log View, could you please show that one?


I'm seeing this in the debug info. What does 'missing unit' mean in this context?

------------------
2015-05-13 17:27:38,712  INFO [main] - ScalaPresentationCompiler - Missing unit for file /home/sean/stuffs/android-scala/scratchpad/libgdx_scalaide/core/src/main/scala/Start.scala when retrieving errors. Errors will not be shown in this file
2015-05-13 17:27:38,712  INFO [main] - ScalaPresentationCompiler - Map(/LibgdxScalaide/core/src/main/scala/Start.scala -> Start.scala)
------------------
It means that the file is not yet cached by the IDE. Maybe that is due to the fact that your classpath was not correct (and still may not be correct).

Thanks!


--
You received this message because you are subscribed to the Google Groups "Scala IDE User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-ide-use...@googlegroups.com.

Sean Wolfe

unread,
Oct 20, 2015, 7:18:07 PM10/20/15
to Scala IDE User
Just checking in here -- FYI to all, I have been able to resolve my issues by indeed working with a proper classpath management tool.

I  updated my project to use a better g8 template here:

And added sbteclipse from here:

Running `sbt eclipse` set up my eclipse project files, and importing the project, I now have command-shift-O functionality.

For the record, this is OSX 10.9.5, Scalaide 4.2.0, and Mars 4.5.1 .

Thanks everybody for your help.

Reply all
Reply to author
Forward
0 new messages