File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -452,12 +452,15 @@ task enforceRules {
452
452
def illegalImport = ~/ ^import (sun|java.awt|org.slf4j)/
453
453
def missingNewline = ~/ ^\s *}\s *(else|catch|finally)/
454
454
def lowerEll = ~/ \b\d +l\b /
455
+ def equals = ~/ boolean +equals\( (@?\w + )*Object \w +\) /
456
+ def hashCode = ~/ int +hashCode\(\) /
455
457
def errors = 0
456
458
def tree = fileTree(" src/main/java/" )
457
459
tree. include " **/*.java"
458
460
tree. each { file ->
459
461
def lineNum = 0
460
462
def shortName = file. path. substring(rootDir. path. length())
463
+ def equalsMinusHashcode = 0
461
464
file. eachLine { line ->
462
465
lineNum++
463
466
if (line =~ illegalImport) {
@@ -472,6 +475,22 @@ task enforceRules {
472
475
errors++
473
476
logger. error(" Lowercase long literal in ${ shortName} \n ${ lineNum} : ${ line} " )
474
477
}
478
+ if (! line. startsWith(" //" )) { // ignore commented-out code
479
+ if (line =~ equals) {
480
+ equalsMinusHashcode ++
481
+ }
482
+ if (line =~ hashCode) {
483
+ equalsMinusHashcode --
484
+ }
485
+ }
486
+ }
487
+ if (equalsMinusHashcode> 0 ) {
488
+ errors++
489
+ logger. error(" Equals with missing hash code in ${ shortName} " )
490
+ }
491
+ if (equalsMinusHashcode< 0 ) {
492
+ errors++
493
+ logger. error(" Hash code with missing equals in ${ shortName} " )
475
494
}
476
495
}
477
496
if ( errors> 0 ) {
You can’t perform that action at this time.
0 commit comments