Groovy Deprecated Methods and Eclipse - sort - eclipse

I've got the following code which I wrote in groovy 1.8
someListOfLists.flatten().sort().unique()
I've moved over to groovy 2.3.x, and eclipse (using e4.4 GroovyEclipse plugin for Juno from snapshot release) is showing me the sort() method is now deprecated for sort(Collection<T> self), to which the advice is to use the sort(Iterable<T> self).
How do I now chain methods like this together to avoid the deprecation warnings?
My thinking was that as flatten() is returning an ArrayList (which is an Iterable) it should be fine. Also, I see doing
((Iterable) someListOfLists.flatten()).sort().unique()
removes the warning, but looks ugly.
So is this just eclipse not seeing that the correct sort will actually be used, or is there some other way to express my chain of methods?

The deprecation warnings are due to the fact that Eclipse is mapping Groovy methods to the mostly deprecated DefaultGroovyMethods class, which was just replaced by many separate other classes such as StringGroovyMethods, ResourceGroovyMethods etc.
It seems that in version 2.7.1 of the Groovy plugin, this was fixed... check your version of the plugin, maybe you just need to upgrade.
If that does not solve the problem, unfortunately, unless you can make the Groovy plugin change the methods mapping, you won't be able to get rid of the warnings, as far as I know. In IntelliJ I have the same problem.

Related

Scala # IntelliJ 12 - Can't fetch docs / some functions are not shown in dropdown. [BUGS]

I've been searching for a long time now to find a decent IDE for Scala.
Eclipse is not satisfying at all, as auto completion doesn't work, somehow. Also, I can't modify the libraries at all in the build path e.g. set the docs/source.
IntelliJ seems better, however, there are some major bugs:
When the drop down menu appears that lists all the function, some of them are sometimes just not shown! I think it's because of scala-library / scala-compiler, it mixes them up or something...
The docs cannot be fetched, I get this message over and over again (here the functions are listed, strange enough...):
This is the library window:
The dependencies and the compiler are set right, I strongly suppose.
Does anyone know what the problem is? And how to fix it? Or is it a known bug?
Is there an IDE that can handle Scala?
Regards!
Typically, searching for names (values/classes/functions/etc.) for auto-complete can be quite slow compared to Java in IntelliJ simply because the automatically imported namespace can be quite large, and it also searches through all implicit conversions. However, I've never seen it refuse to show functions like your screenshot, what version of IntelliJ and Scala plugin are you using?
I've never gotten the pop-up docs to work via attaching JavaDocs (I haven't tried remote fetching), so I'd recommend just ctrl+click to go through to the source to read the documentation there. (However, the function/type definition does popup correctly when sources are attached). I'd suggest posting an issue at http://youtrack.jetbrains.com/issues/SCL if you have the opportunity.
To your final question, the answer is unfortunately no. The tooling for Scala is nowhere near that of Java, but both Scala IDE for Eclipse and IntelliJ are making great progress in changing that, and both are strong in some areas while weak in others. In the end, you'll get limited support either way, so choose whichever fits you best.
I have found the solution to the problem:
The bug was caused by Java Decompiler Plugin. It tried to decompile the binaries of Scala's class-files, which obviously failed. This led to that error message and further led to the Scala plugin not working as it should, thus not displaying some of the functions.
This took me a long time to figure out, I installed 2 other versions of IntelliJ (which apparently imported the JD plugin), NetBeans and downloaded several builds of the Scala Plugin, only to discover this cause. Deactivating Java Decompiler solved it.
Regards.

Run Scala application in Scala IDE with compilation errors

Is there a way to run a Scala application or unit test within the Scala IDE 2.0.2 (Eclipse 3.7) if there are (unrelated!) compilation errors in the project?
In Java, this is no problem, but Scala IDE keeps telling me:
Project contains compilation errors (therefore, no binaries have been produced).
All I want to do is to run a small test during a major refactoring process, but I can't fix all compilation errors right now. And I don't want to start commenting things out, as those compilation errors are good reminders of tasks that still need to be done.
Currently the Scala IDE does not support this behavior, but it would be nice if it could.
To be aware of this, I created a ticket:
JDT allows to execute Java code despite of compilation problems in the sources. Internally JDT replaces the defective code with an exception, which is thrown if the relevant code is executed. But if the defective code is never called during execution, nothing bad happens. It would be nice if SDT supports similar behavior.
If you are using Scala 2.10, a good option is to use the newly introduced ??? notation. This way your code will compile even if the function is not yet implemented.
There is certainly a better way but this one will still be better than commenting code.
As suggested by Jesper, you can still implement ??? if you are working with previous versions of Scala:
def ??? : Nothing = throw new Error("Not implemented")

Groovy eclipse plugin, strikethroughs everywhere

I just tried the Groovy-Eclipse plugin , and everything is working fine, except the syntax highlighting is behaving really strange.
Basically, it sees to think pretty much everything is deprecated. I get strike-troughs everywhere.
For example, toURL is striked through when using
"http://stackoverflow.com".toURL()
I see this with loads of methods, including eachLine , getText and many many more. These methods aren't deprecated, what is going on?
I'm running Eclipse 4.2, 2.7.0.xx-20120703-1400-e42-RELEASE and Groovy 2.0
These methods are deprecated because they moved to other classes and your plugin is not aware of that. There're many methods deprecated:
You can look up the deprecated API's for the new main version of Groovy here.
You can read about the similar question here:
An answer from the STS/Groovy-Eclipse side of things.
This is fixed in the latest 2.7.1 snapshot.
Earlier versions of Groovy-Eclipse were not aware of StringGroovyMethod,
but this has been fixed.

Running Eclipse Scala Plugin with previous version of Scala

The scala plugin seems to automatically download version 2.8 of Scala. I'l like to try out the Gridgain 3.0-beta, which currently only works with Scala 2.7.7. Since Gridgain 3.0-beta already provides scala-compiler-2.7.7.jar and scala-library-2.7.7.jar, is it possible to get the Eclipse Scala Plugin to compile to Scala 2.7.7?
I tried removing the Scala Library 2.8 from the project build path and added both the 2.7 jars, but this didn't seem to work.
Would this be easier if I switched to Netbeans?
Both the Eclipse plugin and the NetBeans plugin use the Scala Compiler for a lot of things from the simple stuff like syntax highlighting to stuff like type inference, resolution and display of implicits to more involved stuff like automated type-driven refactorings and semantic highlighting.
And more specifically, they use the 2.8 compiler, because the 2.8 compiler has a completely refactored API and a new framework (the so-called presentation compiler), which is specifically designed for IDEs, so that they can get all the information they need out of the compiler, but also can feed information (like in the case of refactorings) back into the compiler.
So, in short: the version of the plugin is closely coupled to the version of the compiler, and the compiler in turn only supports one version of the language. In particular, the IDE plugins require a 2.8 version of the compiler, because they use the new presentation compiler framework, and the 2.8 compiler does not support the 2.7 language.
This tight coupling is of course not a good thing, and it will get broken up in the future, but for now, you are stuck.
You could try the IntelliJ IDEA IDE and their Scala plugin. As far as I know, they have written their own compiler (well, at least the parts they need for syntax highlighting and refactoring purposes) purely from the Scala Language Specification, without using any of the Scala Compiler APIs. The Scala Plugin does work with the Community Edition.
The best place for questions like this is the Scala IDE user mailing list. But in brief, the Eclipse tooling for Scala doesn't support the use of other versions of the Scala compiler and libraries than the ones which it ships with. This is unlikely to change in the foreseeable future.

How to become more productive using Scala? (Tools, IDEs)

What Tools do you people use to work with Scala? For my learning phase, I used the Scala REPL and hacked some code with TextMate and compiled it with the scalac CLI. But as the projects grow in size, much more sophisticated tools are required.
I am aware of the Scala plugins for Elipse, IntelliJ and Netbeans and I tried them all. The best one is IMHO IntelliJ, but still far away from being perfect.
The major issue I have is the lack of auto completion. As a not-so-advanced Scala coder, I still dont know the whole standard API and have to switch between the Scaladoc and IDE regularly. This feels like "killing productivity". But they all fail to auto-complete method arguments. (I heard that method arguments are not included in compiled scala code, but what about attaching source to do auto completion?)
Another very annoying issue is the build process. I am using Maven to build my Scala projects and manage their dependencies. But nevertheless, I have to do a full rebuild to test my changes. Maybe I am spoiled by Eclipses incremental rebuild available in the Java world, but it feels like a big issue to me.
I like Scala very much and I feel way more productive while coding, but the lack of sophisticed tools let me feel less productive. And both seem to cancel out themselves.
So, whats my question? I doubt every single Scala programmer uses good ol' vim or emacs along with scalac to do their work. So what tools do you use? What workflows have you developed to bring speed into developing with the Scala language?
Edit
Clarification what I ment with auto-completion of method arguments.
val myList = "foo" :: "all your base" :: Nil
myList.partition(_.length > 3)
For the code above, IntelliJ fail to provide me with the information that partition requires that I have to pass a () => Boolean function. In fact, IntelliJ does not check for this contraint. I can pass a String and IntelliJ will not indicate my error until I do a compile.
scalac
Get familiar with command line options to Scalac.
-deprecation
-Xprint:all: watch your code progress through compiler phases, very useful to see what implicits are applied.
-help / -X' /-Y` list all options.
The latest nightly builds of scalac include a bash completion file that makes these easier to use.
IntelliJ IDEA
Method completion with Javadoc (CTRL-Space, CTRL-Q/Apple-J) Screenshot
Parameter Info for the example in the question (CTRL-P) Screenshot
Method Argument Completion (CTRL-SHIFT-Space). Screenshot
You need to have the source or javadocs linked into the dependencies in IntelliJ to see the Javadoc.
It doesn't currently highlight type errors on the fly, as there are still too many false-positives in complex code. This is coming, though.
Simple Build Tool
SBT keeps the compiler resident, and analyzes dependencies between classes to allow incremental recompilation. It can also monitor for changes to source files and automatically trigger recompilation and/or test execution.
Continous Compilation: >~compile
Continuous Compilation + Test: ~test-quick
I have SBT and IntelliJ project configured in http://github.com/scalaz/scalaz, you could use this as a reference.
I've been using Scala daily for the last six months. I'm still using vim (and ctags to find stuff), and Maven for builds. I've gotten some good mileage out of JRebel when working on Lift web apps -- it will reload changes on the fly without server restarts.
I spent some time looking into IDEs, but it got depressing really fast. I really missed a lot of Eclipse features at first, but after a period of adjustment I don't think I'm significantly less productive now.
I've heard some rumblings that NetBeans is the current champ for Scala IDEs, but I haven't tried it first hand.
One simple way is to use fsc, an offline compiler. It maintains caches of information, and the standard compiler will talk to fsc (running as a daemon) and use its cached information during compilation, thus speeding up your compilation cycle.
Here's my answer on a similar thread. After giving about an hour to Ensime. I just can't help but get the word out. I must say it's very, very well written for an Emacs package.
I am afraid you have to wait for Scala to become rock-solid.
I had exactly the same issue with Java ten years ago. It was even worse.
I also tried them all. For Scala 2.7.7 IntelliJ is the winner, but for Scala 2.8.0-SNAPSHOT Eclipse is not that bad.
Wait half of a year after 2.8.0 is released and check again. It should become bearable.
With Scala 2.8, please see this for getting better performance out of Maven.
You should also give Netbeans 6.8 a try with the nightly Scala build. I am very satisfied programming Scala with this IDE. For building, I sometimes also use Ant. The best thing about NB Scala plugin is that it is fast and code-completion works flawlessly.
For the example you gave: NB gives me this error
code-completion:
The Eclipse Scala IDE is quite mature now (as of 3.0).