View Javadoc
1   //a comment //indent:0 exp:0
2   package com.puppycrawl.tools.checkstyle.checks.indentation.indentation; //indent:0 exp:0
3   
4   import java.util.Arrays; //indent:0 exp:0
5   import java.util.List; //indent:0 exp:0
6   import java.util.Optional; //indent:0 exp:0
7   import java.util.function.BinaryOperator; //indent:0 exp:0
8   import java.util.function.Consumer; //indent:0 exp:0
9   import java.util.stream.Collectors; //indent:0 exp:0
10  import java.util.stream.Stream; //indent:0 exp:0
11  
12  
13  public class InputIndentationLambda3 { //indent:0 exp:0
14  	public <T> Consumer<Integer> par(Consumer<Integer> f1, Consumer<Integer> f2) { //indent:4 exp:4
15  			return f2; //indent:12 exp:8 warn
16  	} //indent:4 exp:4
17  
18  	private void print(int i) { //indent:4 exp:4
19  	} //indent:4 exp:4
20  
21  	public Consumer<Integer> returnFunctionOfLambda() { //indent:4 exp:4
22  		return par( //indent:8 exp:8
23  					(x) -> print(x * 1), //indent:20 exp:20
24  				(x) -> print(x * 2) //indent:16 exp:16
25  		); //indent:8 exp:8
26  	} //indent:4 exp:4
27  
28  	public static <T> BinaryOperator<T> returnLambda() { //indent:4 exp:4
29  			return (t1, t2) -> { //indent:12 exp:8 warn
30  			return t1; //indent:12 exp:16 warn
31  		}; //indent:8 exp:12 warn
32  	} //indent:4 exp:4
33  
34  	class TwoParams { //indent:4 exp:4
35  		TwoParams(Consumer<Integer> c1, Consumer<Integer> c2) { //indent:8 exp:8
36  		} //indent:8 exp:8
37  	} //indent:4 exp:4
38  
39  	public void makeTwoParams() { //indent:4 exp:4
40  		TwoParams t0 = new TwoParams( //indent:8 exp:8
41  				intValueA //indent:16 exp:16
42  						-> print(intValueA * 1), //indent:24 exp:24
43  					(x) -> //indent:20 exp:20
44  						print(x * 2) //indent:24 exp:24
45  		); //indent:8 exp:8
46  
47  		TwoParams t1 = new TwoParams( //indent:8 exp:8
48  				x //indent:16 exp:16
49  						-> print(x * 1), //indent:24 exp:24
50  				(aggregateValue) -> //indent:16 exp:16
51  						print(aggregateValue * 2)); //indent:24 exp:24
52  	} //indent:4 exp:4
53  
54  	// see https://github.com/checkstyle/checkstyle/issues/5969 //indent:4 exp:4
55  	List<Integer> test(List<String> input) { //indent:4 exp:4
56  		return input.stream() //indent:8 exp:8
57  				.flatMap(each -> Arrays.stream(each.split(""))) //indent:16 exp:16
58  				.flatMap(in -> Arrays.stream(in.split(""))) //indent:16 exp:16
59  				// only 2 char parameter has violation //indent:16 exp:16
60  				.map(Integer::valueOf) //indent:16 exp:16
61  				.collect(Collectors.toList()); //indent:16 exp:16
62  	} //indent:4 exp:4
63  
64  	String test2(String input) { //indent:4 exp:4
65  			return Optional.ofNullable(input) //indent:12 exp:8 warn
66  				.filter(in //indent:16 exp:16
67  							-> //indent:28 exp:28
68  					in.contains("e")) //indent:20 exp:20
69  			.filter(inp -> inp.contains("e")) //indent:12 exp:12
70  				// only 3 char parameter has violation //indent:16 exp:16
71  				.orElse(null); //indent:16 exp:16
72  	} //indent:4 exp:4
73  
74  	// see https://github.com/checkstyle/checkstyle/issues/7675 //indent:4 exp:4
75  	public void test(Stream<Inner<?>> stream) { //indent:4 exp:4
76  		stream //indent:8 exp:8
77  .sorted() //indent:0 exp:0
78  .filter(ps -> ps instanceof Inner) //indent:0 exp:0
79  				.map(ps -> ((Inner<?>) ps).getPropertyNames()) //indent:16 exp:16
80  				// This line above originally breaks //indent:16 exp:16
81  				.forEach(System.out::println); //indent:16 exp:16
82  	} //indent:4 exp:4
83  
84  	private static class Inner<T> { //indent:4 exp:4
85  		String[] getPropertyNames() { //indent:8 exp:8
86  			return new String[] {"a", "b"}; //indent:12 exp:12
87  			} //indent:12 exp:8 warn
88  	} //indent:4 exp:4
89  } //indent:0 exp:0