Skip to content

Commit 476907c

Browse files
Use streams
1 parent c4aa792 commit 476907c

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

java-checks/src/main/java/org/sonar/java/checks/DiamondOperatorCheck.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@
1616
*/
1717
package org.sonar.java.checks;
1818

19+
import java.util.Arrays;
1920
import java.util.Collections;
2021
import java.util.List;
22+
import java.util.stream.Stream;
2123
import javax.annotation.CheckForNull;
2224
import javax.annotation.Nullable;
2325
import org.sonar.check.Rule;
@@ -54,20 +56,20 @@
5456
@Rule(key = "S2293")
5557
public class DiamondOperatorCheck extends SubscriptionVisitor implements JavaVersionAwareVisitor {
5658

59+
/** Nodes to check in Java 7. */
5760
private static final Tree.Kind[] JAVA_7_KINDS = new Tree.Kind[] {
5861
Tree.Kind.VARIABLE,
5962
Tree.Kind.TYPE_CAST,
6063
Tree.Kind.RETURN_STATEMENT,
6164
Tree.Kind.ASSIGNMENT
6265
};
6366

64-
private static final Tree.Kind[] JAVA_8_KINDS = new Tree.Kind[] {
65-
Tree.Kind.VARIABLE,
66-
Tree.Kind.TYPE_CAST,
67-
Tree.Kind.RETURN_STATEMENT,
68-
Tree.Kind.ASSIGNMENT,
69-
Tree.Kind.CONDITIONAL_EXPRESSION
70-
};
67+
/** Nodes to check in Java 8 and up. */
68+
private static final Tree.Kind[] JAVA_8_KINDS =
69+
Stream.concat(
70+
Arrays.stream(JAVA_7_KINDS),
71+
Stream.of(Tree.Kind.CONDITIONAL_EXPRESSION)
72+
).toArray(Tree.Kind[]::new);
7173

7274
private Tree.Kind[] expressionKindsToCheck = JAVA_7_KINDS;
7375

0 commit comments

Comments
 (0)