Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Converting Java8 lambdas #77

Open
khajavi opened this issue Apr 26, 2015 · 4 comments
Open

Converting Java8 lambdas #77

khajavi opened this issue Apr 26, 2015 · 4 comments

Comments

@khajavi
Copy link

khajavi commented Apr 26, 2015

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);
    }
}
@gervaisb
Copy link

👍 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> ... ... "(" ... "!" ... "~" ... "++" ... "--" ... "+" ... "-" ...

The latest release support java 8 syntax :

The project now supports parsing Java 1.8
-- https://github.com/javaparser/javaparser#history

@metasim
Copy link

metasim commented Oct 6, 2015

+1

@nightscape
Copy link

I started a WIP PR for this here: #83

@nightscape
Copy link

New PR #84 supports Java 8 and comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants