scalagen
scalagen copied to clipboard
Converting Java8 lambdas
Scalagen cannot Convert program like this:
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
public class Java8CompareClient {
public static void main(String[] args) {
List<String> srcList = Arrays.asList("defg", "defg", "x", "xyz", "zzzzzzzz", "abc", "abcde");
List<String> srcList1 = new ArrayList(srcList);
List<String> srcList2 = new ArrayList(srcList);
Comparator<String> comparator = (x, y) -> x.length() - y.length();
Collections.sort(srcList1, comparator);
System.out.println("srcList1: " + srcList1);
Collections.sort(srcList2, (x, y) -> x.length() - y.length());
System.out.println("srcList2: " + srcList2);
}
}
:+1: It seems that javaparser library fail on the lambda syntax;
package hello;
import java.util.Optional;
class HelloWorldApp {
public static void main(String[] args) {
Optional<String> opt = Optional.empty();
opt.map(s -> s.length());
}
}
japa.parser.ParseException: Encountered " ">" "> "" at line 10, column 20. Was expecting one of: "boolean" ... "byte" ... "char" ... "double" ... "false" ... "float" ... "int" ... "long" ... "new" ... "null" ... "short" ... "super" ... "this" ... "true" ... "void" ... <LONG_LITERAL> ... <INTEGER_LITERAL> ... <FLOATING_POINT_LITERAL> ... <CHARACTER_LITERAL> ... <STRING_LITERAL> ... <IDENTIFIER> ... "(" ... "!" ... "~" ... "++" ... "--" ... "+" ... "-" ...
The latest release support java 8 syntax :
The project now supports parsing Java 1.8 -- https://github.com/javaparser/javaparser#history
+1
I started a WIP PR for this here: https://github.com/timowest/scalagen/pull/83
New PR https://github.com/timowest/scalagen/pull/84 supports Java 8 and comments.