Skip to content

Commit 4754141

Browse files
committed
Add cleanups for various redundant modifiers/expressions/statements.
Signed-off-by: Roland Grunberg <rgrunber@redhat.com>
1 parent d71d0a4 commit 4754141

File tree

2 files changed

+116
-1
lines changed

2 files changed

+116
-1
lines changed

document/_java.learnMoreAboutCleanUps.md

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,3 +473,113 @@ switch (x) {
473473
}
474474
}
475475
```
476+
477+
### `redundantComparisonStatement`
478+
479+
Remove redundant comparison statement.
480+
481+
For example:
482+
483+
```java
484+
if (i != 123) {
485+
return i;
486+
} else {
487+
return 123;
488+
}
489+
```
490+
491+
becomes:
492+
493+
```java
494+
return i;
495+
```
496+
497+
### `redundantFallingThroughBlockEnd`
498+
499+
Remove redundant end of block with jump statement.
500+
501+
For example:
502+
503+
```java
504+
if (0 < i) {
505+
System.out.println("Doing something");
506+
return i + 10;
507+
}
508+
return i + 10;
509+
```
510+
511+
becomes:
512+
513+
```java
514+
if (0 < i) {
515+
System.out.println("Doing something");
516+
}
517+
return i + 10;
518+
```
519+
520+
### `redundantIfCondition`
521+
522+
Remove redundant if condition.
523+
524+
For example:
525+
526+
```java
527+
if (isValid) {
528+
return 0;
529+
} else if (!isValid) {
530+
return -1;
531+
}
532+
```
533+
534+
becomes:
535+
536+
```java
537+
if (isValid) {
538+
return 0;
539+
} else {
540+
return -1;
541+
}
542+
```
543+
544+
### `redundantModifiers`
545+
546+
Remove redundant modifiers.
547+
548+
For example:
549+
550+
```java
551+
public abstract interface IFoo {
552+
public static final int MAGIC_NUMBER = 646;
553+
public abstract int foo ();
554+
public int bar (int bazz);
555+
}
556+
```
557+
558+
becomes:
559+
560+
```java
561+
public interface IFoo {
562+
int MAGIC_NUMBER = 646;
563+
int foo ();
564+
int bar (int bazz);
565+
}
566+
```
567+
568+
### `redundantSuperCall`
569+
570+
Remove redundant `super()` class in constructor.
571+
572+
For example:
573+
574+
```java
575+
MyClass() {
576+
super();
577+
}
578+
```
579+
580+
becomes:
581+
582+
```java
583+
MyClass() {
584+
}
585+
```

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1316,7 +1316,12 @@
13161316
"renameFileToType",
13171317
"organizeImports",
13181318
"renameUnusedLocalVariables",
1319-
"useSwitchForInstanceofPattern"
1319+
"useSwitchForInstanceofPattern",
1320+
"redundantComparisonStatement",
1321+
"redundantFallingThroughBlockEnd",
1322+
"redundantIfCondition",
1323+
"redundantModifiers",
1324+
"redundantSuperCall"
13201325
]
13211326
},
13221327
"default": [

0 commit comments

Comments
 (0)