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 InputUnnecessaryParenthesesOperator { 17 boolean a = true; 18 boolean b = false; 19 void method() { 20 if(a || (b ^ a) || b) { // violation 'Unnecessary parentheses around expression' 21 } 22 if(a || (b | a) || b) { // violation 'Unnecessary parentheses around expression' 23 } 24 if(a || (b & a) || b) { // violation 'Unnecessary parentheses around expression' 25 } 26 if(a && (b ^ a) && b) { // violation 'Unnecessary parentheses around expression' 27 } 28 if(a && (b | a) && b) { // violation 'Unnecessary parentheses around expression' 29 } 30 if(a && (b & a) && b) { // violation 'Unnecessary parentheses around expression' 31 } 32 if(a && (b ^ a) || b) { // violation 'Unnecessary parentheses around expression' 33 } 34 if(a && (b | a) || b) { // violation 'Unnecessary parentheses around expression' 35 } 36 if(a && (b & a) || b) { // violation 'Unnecessary parentheses around expression' 37 } 38 if(a || (b ^ a) && b) { // violation 'Unnecessary parentheses around expression' 39 } 40 if(a || (b | a) && b) { // violation 'Unnecessary parentheses around expression' 41 } 42 if(a || (b & a) && b) { // violation 'Unnecessary parentheses around expression' 43 } 44 } 45 46 void method2() { 47 if(a || (((b ^ a))) || b) { // violation 'Unnecessary parentheses around expression' 48 } 49 if(a || ((b | a)) || b) { // violation 'Unnecessary parentheses around expression' 50 } 51 if(a || ((b & a)) || b) { // violation 'Unnecessary parentheses around expression' 52 } 53 if(a && (b ^ a) && b) { // violation 'Unnecessary parentheses around expression' 54 } 55 if(a && ((b | a)) && b) { // violation 'Unnecessary parentheses around expression' 56 } 57 if(a && (((b & a))) && b) { // violation 'Unnecessary parentheses around expression' 58 } 59 if(a && ((b ^ a)) || b) { // violation 'Unnecessary parentheses around expression' 60 } 61 if(a && (((b | a))) || b) { // violation 'Unnecessary parentheses around expression' 62 } 63 if(a && ((b & a)) || b) { // violation 'Unnecessary parentheses around expression' 64 } 65 if(a || ((b ^ a)) && b) { // violation 'Unnecessary parentheses around expression' 66 } 67 if(a || (((b | a))) && b) { // violation 'Unnecessary parentheses around expression' 68 } 69 if(a || ((b & a)) && b) { // violation 'Unnecessary parentheses around expression' 70 } 71 int x = 10, y = 38; 72 if(x>= 0 != (x<=8 ^ y<=11) && y>=8) { 73 return; 74 } 75 if(x>= 0 != (x<=8 || y<=11) && y>=8) { 76 return; 77 } 78 if(x== 0 != (x<=8 ^ y<=11) && y==8) { 79 return; 80 } 81 boolean v = true, w = false; 82 if ((v & w) != 83 (w | v)) { 84 } 85 if(x>= 0 | (x<=8 | y<=11) | y>=8) { 86 return; // violation above 'Unnecessary parentheses around expression' 87 } 88 } 89 90 void method3() { 91 int code1 = 9; 92 if ((code1 & 1) == 8) {} 93 if ((code1 | 1) == 8) {} 94 if ((code1 ^ 1) == 8) {} 95 96 if ((code1 & 1) != 8) {} 97 if ((code1 | 1) != 8) {} 98 if ((code1 ^ 1) != 8) {} 99 } 100 void method4() { 101 int a = 2; 102 if ((~a) < -27 // violation 'Unnecessary parentheses around expression' 103 && a-- < 30) { 104 return; 105 } 106 if ((~a) <= -27 // violation 'Unnecessary parentheses around expression' 107 && a-- < 30) { 108 return; 109 } 110 } 111 }