@@ -10,27 +10,36 @@ using checkstyle.utils.FieldUtils;
1010class RedundantModifierCheck extends Check {
1111
1212 public var enforcePublicPrivate : Bool ;
13+ public var enforcePublic : Bool ;
14+ public var enforcePrivate : Bool ;
1315
1416 public function new () {
1517 super (AST );
1618 enforcePublicPrivate = false ;
19+ enforcePublic = false ;
20+ enforcePrivate = false ;
1721 categories = [Category .STYLE , Category .CLARITY ];
1822 points = 1 ;
1923 }
2024
2125 override function actualRun () {
26+ if (enforcePublicPrivate ) {
27+ enforcePrivate = true ;
28+ enforcePublic = true ;
29+ }
2230 forEachField (checkField );
2331 }
2432
2533 function checkField (f : Field , p : ParentType ) {
2634 var isDefaultPrivate = f .isDefaultPrivate (p );
2735 var implicitAccess = isDefaultPrivate ? " private" : " public" ;
28- if (enforcePublicPrivate ) {
29- if (! f . access . contains ( APublic ) && ! f . access . contains ( APrivate )) {
36+ if (! f . access . contains ( APublic ) && ! f . access . contains ( APrivate ) ) {
37+ if (( ! isDefaultPrivate && enforcePublic ) || ( isDefaultPrivate && enforcePrivate )) {
3038 logPos (' Missing " $implicitAccess " keyword for " ${f .name }"' , f .pos );
3139 }
3240 }
33- else if ((isDefaultPrivate && f .access .contains (APrivate )) || (! isDefaultPrivate && f .access .contains (APublic ))) {
41+
42+ if ((! enforcePrivate && isDefaultPrivate && f .access .contains (APrivate )) || (! enforcePublic && ! isDefaultPrivate && f .access .contains (APublic ))) {
3443 logPos (' " $implicitAccess " keyword is redundant for " ${f .name }"' , f .pos );
3544 }
3645 }
0 commit comments