File tree Expand file tree Collapse file tree 4 files changed +53
-7
lines changed
src/main/java/com/smlnskgmail/jaman/checkstyle/checks Expand file tree Collapse file tree 4 files changed +53
-7
lines changed Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ plugins {
55}
66
77group ' com.smlnskgmail.jaman.checkstyle'
8- version ' 1.0 .0'
8+ version ' 1.1 .0'
99
1010checkstyle {
1111 toolVersion ' 8.38'
3535 language = ' java'
3636}
3737
38+ cpdCheck {
39+ exclude ' *.java'
40+ }
41+
3842repositories {
3943 mavenCentral()
4044}
Original file line number Diff line number Diff line change @@ -24,11 +24,36 @@ public void visitToken(DetailAST ast) {
2424 log (ast );
2525 }
2626 break ;
27+ case "ImageButton" :
28+ if (!ast .findFirstToken (TokenTypes .IDENT ).getText ().startsWith ("ib" )) {
29+ log (ast );
30+ }
31+ break ;
2732 case "EditText" :
2833 if (!ast .findFirstToken (TokenTypes .IDENT ).getText ().startsWith ("et" )) {
2934 log (ast );
3035 }
3136 break ;
37+ case "Button" :
38+ if (!ast .findFirstToken (TokenTypes .IDENT ).getText ().startsWith ("btn" )) {
39+ log (ast );
40+ }
41+ break ;
42+ case "RecyclerView" :
43+ if (!ast .findFirstToken (TokenTypes .IDENT ).getText ().startsWith ("rv" )) {
44+ log (ast );
45+ }
46+ break ;
47+ case "AdaptiveRecyclerView" :
48+ if (!ast .findFirstToken (TokenTypes .IDENT ).getText ().startsWith ("arv" )) {
49+ log (ast );
50+ }
51+ break ;
52+ case "FloatingActionButton" :
53+ if (!ast .findFirstToken (TokenTypes .IDENT ).getText ().startsWith ("fab" )) {
54+ log (ast );
55+ }
56+ break ;
3257 }
3358 }
3459 }
Original file line number Diff line number Diff line change 77import java .util .Arrays ;
88import java .util .List ;
99
10+ @ SuppressWarnings ("CPD-START" )
1011public class MethodObjectReturnAnnotationCheck extends AbstractCheck {
1112
13+ private static final List <String > REQUIRED_ANNOTATIONS = Arrays .asList (
14+ "NonNull" ,
15+ "Nullable"
16+ );
17+
1218 private static final String MESSAGE_KEY = "MethodObjectReturnAnnotationCheck" ;
1319
1420 private static final List <Integer > EXCLUDED_TYPES = Arrays .asList (
@@ -27,11 +33,14 @@ public class MethodObjectReturnAnnotationCheck extends AbstractCheck {
2733 public void visitToken (DetailAST ast ) {
2834 final DetailAST returnType = ast .findFirstToken (TokenTypes .TYPE );
2935 if (!EXCLUDED_TYPES .contains (returnType .getFirstChild ().getType ())) {
30- // TODO: add annotations check
31- @ SuppressWarnings ("CPD-START" )
3236 final DetailAST modifiers = ast .findFirstToken (TokenTypes .MODIFIERS );
3337 if (modifiers .getChildCount (TokenTypes .ANNOTATION ) == 0 ) {
3438 log (ast .getLineNo (), MESSAGE_KEY );
39+ } else {
40+ String firstAnnotationName = modifiers .getFirstChild ().findFirstToken (TokenTypes .IDENT ).getText ();
41+ if (!REQUIRED_ANNOTATIONS .contains (firstAnnotationName )) {
42+ log (ast .getLineNo (), MESSAGE_KEY );
43+ }
3544 }
3645 }
3746 }
Original file line number Diff line number Diff line change 88import java .util .Arrays ;
99import java .util .List ;
1010
11+ @ SuppressWarnings ("CPD-START" )
1112public class MethodParametersAnnotationCheck extends AbstractCheck {
1213
14+ private static final List <String > REQUIRED_ANNOTATIONS = Arrays .asList (
15+ "NonNull" ,
16+ "Nullable"
17+ );
18+
1319 private static final List <Integer > EXCLUDED_TYPES = Arrays .asList (
1420 TokenTypes .LITERAL_BOOLEAN ,
1521 TokenTypes .LITERAL_CHAR ,
@@ -42,11 +48,13 @@ public void visitToken(DetailAST ast) {
4248 }
4349
4450 private boolean isInvalidParameter (DetailAST parameterAST ) {
51+ if (EXCLUDED_TYPES .contains (parameterAST .findFirstToken (TokenTypes .TYPE ).getFirstChild ().getType ())) {
52+ return false ;
53+ }
4554 final DetailAST modifiers = parameterAST .findFirstToken (TokenTypes .MODIFIERS );
46- // TODO: add annotations check
47- return modifiers != null
48- && !EXCLUDED_TYPES .contains (parameterAST .findFirstToken (TokenTypes .TYPE ).getFirstChild ().getType ())
49- && modifiers .findFirstToken (TokenTypes .ANNOTATION ) == null ;
55+ DetailAST firstAnnotation = modifiers .findFirstToken (TokenTypes .ANNOTATION );
56+ return firstAnnotation == null
57+ || !REQUIRED_ANNOTATIONS .contains (firstAnnotation .findFirstToken (TokenTypes .IDENT ).getText ());
5058 }
5159
5260 @ Override
You can’t perform that action at this time.
0 commit comments