forked from checkstyle/checkstyle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue checkstyle#14872: no violation on casting fix
- Loading branch information
Showing
7 changed files
with
364 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 119 additions & 0 deletions
119
...ls/checkstyle/checks/coding/unnecessaryparentheses/InputUnnecessaryParenthesesCasts1.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
/* | ||
UnnecessaryParentheses | ||
tokens = (default)EXPR, IDENT, NUM_DOUBLE, NUM_FLOAT, NUM_INT, NUM_LONG, \ | ||
STRING_LITERAL, LITERAL_NULL, LITERAL_FALSE, LITERAL_TRUE, ASSIGN, \ | ||
BAND_ASSIGN, BOR_ASSIGN, BSR_ASSIGN, BXOR_ASSIGN, DIV_ASSIGN, \ | ||
MINUS_ASSIGN, MOD_ASSIGN, PLUS_ASSIGN, SL_ASSIGN, SR_ASSIGN, STAR_ASSIGN, \ | ||
LAMBDA, TEXT_BLOCK_LITERAL_BEGIN, LAND, LITERAL_INSTANCEOF, GT, LT, GE, \ | ||
LE, EQUAL, NOT_EQUAL, UNARY_MINUS, UNARY_PLUS, INC, DEC, LNOT, BNOT, \ | ||
POST_INC, POST_DEC, TYPECAST | ||
*/ | ||
package com.puppycrawl.tools.checkstyle.checks.coding.unnecessaryparentheses; | ||
public class InputUnnecessaryParenthesesCasts1 { | ||
public void valid1() { | ||
int x = 23; | ||
int y = 44; | ||
float k = 12f; | ||
|
||
int d = ((int) 100f) + 100 * 2 / ((int) 12.5) + (int) 90f; | ||
// 2 violations above: | ||
// 'Unnecessary parentheses around expression' | ||
// 'Unnecessary parentheses around expression' | ||
int p = (int) 110f + 10 * 2 / (int) 10f + (int) 32.2; | ||
|
||
y = (int) (22.2 * 2) / ((int) 8f + 5); | ||
|
||
double arg2 = 23.2; | ||
int i = (int) arg2; | ||
i = ((int) arg2); // violation 'Unnecessary parentheses around assignment right-hand side' | ||
p = (int) arg2; | ||
|
||
x = (2 * 2 /((int) k)); | ||
// 2 violations above: | ||
// 'Unnecessary parentheses around assignment right-hand side' | ||
// 'Unnecessary parentheses around expression' | ||
x = 2 * 2 / (int) k; | ||
|
||
int par = ((int)2f * 2) / 4; | ||
y = ((Integer) x).hashCode(); | ||
|
||
int py = 12; | ||
float xy = 40f; | ||
int yp = 0; | ||
boolean finished = true; | ||
boolean result = false; | ||
|
||
if(py >= ((int)xy) || (yp ==1 | py >=1)) { | ||
// violation above 'Unnecessary parentheses around expression.' | ||
xy--; | ||
} | ||
else if(yp >= (int)xy || (py ==1 | py >=1)) { | ||
xy++; | ||
} | ||
|
||
if (!((int) xy > yp) && py < 20) { | ||
py++; | ||
} | ||
|
||
if (35 + (int)'a' == 100) { | ||
py++; | ||
} | ||
|
||
boolean checkone = true; | ||
if (!((boolean) checkone)) { | ||
// violation above 'Unnecessary parentheses around expression.' | ||
checkone = false; | ||
} | ||
else if ((boolean) checkone) { | ||
checkone = !checkone; | ||
} | ||
|
||
double limit = 3.2; | ||
for (int j = 0; j >= ((int) limit); j++) { | ||
// violation above 'Unnecessary parentheses around expression.' | ||
yp +=1; | ||
} | ||
for (int j =0; j >= (int) limit; j++) { | ||
py--; | ||
break; | ||
} | ||
|
||
for(int j = 10; !finished && !((boolean) (j > 5)) ; j++){ | ||
// violation above 'Unnecessary parentheses around expression.' | ||
break; | ||
} | ||
for(int jp = 9; !finished || !(boolean) (jp >5); jp++){ | ||
checkone = false; | ||
break; | ||
} | ||
|
||
// violation below 'Unnecessary parentheses around expression.' | ||
long p1 = ((long) ((20 >> 24 ) & 0xFF)) << 24; | ||
long p2 = (long) ((20 >> 24 ) & 0xFF) << 24; | ||
|
||
float f4 = -((float) 42); // violation 'Unnecessary parentheses around expression.' | ||
float f5 = -(float) 90; | ||
|
||
// violation below 'Unnecessary parentheses around expression.' | ||
long shiftedbytwo = ((long)900) << 2; | ||
long shiftedbythree = (long)899 << 3; | ||
|
||
// violation below 'Unnecessary parentheses around expression.' | ||
short complement = (short) ~((short) 87777); | ||
short bcomplement = (short) ~(short) 90122; | ||
|
||
// violation below 'Unnecessary parentheses around expression.' | ||
int numSlices1 = (int) Math.max(Math.ceil(((double) 20) / 10), 1); | ||
int numSlices2 = (int) Math.max(Math.ceil((double) 20 / 10), 1); | ||
} | ||
|
||
private long getLong1(int start, int end) { | ||
// violation below 'Unnecessary parentheses around expression.' | ||
return (((long) start) << 32) | 0xFFFFFFFFL & end; | ||
} | ||
private long getLong2(int start, int end) { | ||
return ((long) start << 32) | 0xFFFFFFFFL & end; | ||
} | ||
} |
Oops, something went wrong.