1 /*
2 UnnecessaryParentheses
3 tokens = EXPR, IDENT, NUM_DOUBLE, NUM_FLOAT, NUM_INT, NUM_LONG, \
4 STRING_LITERAL, LITERAL_NULL, LITERAL_FALSE, LITERAL_TRUE, ASSIGN, \
5 BAND_ASSIGN, BOR_ASSIGN, BSR_ASSIGN, BXOR_ASSIGN, DIV_ASSIGN, \
6 MINUS_ASSIGN, MOD_ASSIGN, PLUS_ASSIGN, SL_ASSIGN, SR_ASSIGN, STAR_ASSIGN, \
7 LAMBDA, TEXT_BLOCK_LITERAL_BEGIN, LAND, LITERAL_INSTANCEOF, GT, LT, GE, \
8 LE, EQUAL, NOT_EQUAL, UNARY_MINUS, UNARY_PLUS, INC, DEC, LNOT, BNOT, \
9 POST_INC, POST_DEC, BOR, BAND, BXOR
10
11
12 */
13
14 package com.puppycrawl.tools.checkstyle.checks.coding.unnecessaryparentheses;
15
16 public class InputUnnecessaryParenthesesOperator2 {
17
18 void method() {
19 boolean a = true;
20 boolean b = false;
21
22 if ((b || a) &
23 (b || a)) {
24 }
25 if ((b && a) &
26 (b && a)) {
27 }
28 if ((b || a) |
29 (b && a)) {
30 }
31
32 int c = 1;
33 int d = 12;
34 if(a || (c ^ d) >> 1 == 1 || b) {
35 }
36
37 if ((b || a) &
38 (b || a)) {
39 }
40 if ((b || a) |
41 (b || a)) {
42 }
43 if ((b || a) ^
44 (b || a)) {
45 }
46 if ((b && a) &
47 (b && a)) {
48 }
49 if ((b && a) |
50 (b && a)) {
51 }
52 if ((b && a) ^
53 (b && a)) {
54 }
55 if ((b || a) &
56 (b && a)) {
57 }
58 }
59
60 public void test2() {
61 int a = 9;
62 int b = 10;
63 if (a > b) {
64 System.out.println("a is greater then b");
65 }
66 else if ((b < a) & ( // violation 'Unnecessary parentheses around expression'
67 (8>9) | // violation 'Unnecessary parentheses around expression'
68 (!m3()))) { // violation 'Unnecessary parentheses around expression'
69 System.out.println();
70 }
71
72 }
73
74 boolean m3() {
75 return true;
76 }
77
78 void method3() {
79 int x = 10, y = 5, z = 5;
80
81 if (x == ((y<z) ? y : z) &
82 ((x>y & y>z) // violation 'Unnecessary parentheses around expression'
83 | (!(x<z) & y>z))) { // violation 'Unnecessary parentheses around expression'
84 return;
85 }
86 if(x>= 0 & (x<=8 | y<=11) & y>=8) {
87 return;
88 }
89 if(x>= 0 ^ (x<=8 | y<=11) ^ y>=8) {
90 return;
91 }
92 if(x>= 0 || (x<=8 & y<=11) && y>=8) {
93 return; // violation above 'Unnecessary parentheses around expression'
94 }
95 if(x> 0 & (x<=8 & y<=11) & y>=8) { // violation 'Unnecessary parentheses around expression'
96 return;
97 }
98 if(x>= 0 ^ (x<=8 & y<=11) ^ y>=8) {
99 return; // violation above 'Unnecessary parentheses around expression'
100 }
101 if(x>= 0 || (x<=8 & y<=11) && y>=8) {
102 return; // violation above 'Unnecessary parentheses around expression'
103 }
104 if(x>= 0 & (x<=8 ^ y<=11) & y>=8) {
105 return;
106 }
107 if(x>= 0 ^ (x<=8 ^ y<=11) ^ y>=8) {
108 return; // violation above 'Unnecessary parentheses around expression'
109 }
110 if(x>= 0 || (x<=8 ^ y<=11) && y>=8) {
111 return; // violation above 'Unnecessary parentheses around expression'
112 }
113 if(x>= 0 != (x<=8 ^ y<=11) && y>=8) {
114 return;
115 }
116 if(true || (4 | 4) >> 1 == 1 || false) {
117 }
118 }
119 }