jhipster / prettier-java

Prettier Java Plugin
http://www.jhipster.tech/prettier-java/
Apache License 2.0
1.09k stars 103 forks source link

Lambda expression formatting encountered a bug, some code is missing。 #529

Closed creasy2010 closed 2 years ago

creasy2010 commented 2 years ago

Prettier-Java 1.6.1

Input:

package com.example;

import java.util.ArrayList;
import java.util.stream.Collectors;

public class LambdaTest{
    public void test() throws Exception {

        new ArrayList<>().stream().map(item->{
          return item;
        }).collect(Collectors.toList());
    }
}

Output:

package com.example;

      import java.util.ArrayList;
      import java.util.stream.Collectors;

      public class LambdaTest {

        public void test() throws Exception {
          new ArrayList<>()
            .stream()
            .map(item -> )
            .collect(Collectors.toList());
        }
      }

Expected behavior:


package com.example;

      import java.util.ArrayList;
      import java.util.stream.Collectors;

      public class LambdaTest {

        public void test() throws Exception {
          new ArrayList<>()
            .stream()
            .map(tem->{
                        return item;
             }))
            .collect(Collectors.toList());
        }
      }
pascalgrimaud commented 2 years ago

I don't have problem with prettier-plugin-java 1.6.1 :

image

creasy2010 commented 2 years ago

I know the cause of the problem. Prettier-java161 with prettier 1.16.4 will reproduce the problem; If I upgrade prettier to 2.5.1, the problem is solved!

Thank you for your timely response! 

pascalgrimaud commented 2 years ago

Thanks for the feedback So I think we can close the ticket :)