Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Groovy Deprecated Methods and Eclipse - sort

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?

like image 705
Mark Fisher Avatar asked Sep 29 '14 11:09

Mark Fisher


1 Answers

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.

like image 195
Renato Avatar answered Oct 31 '22 15:10

Renato