File tree Expand file tree Collapse file tree 1 file changed +10
-9
lines changed
custom-pmd/src/main/java/com/baeldung/pmd Expand file tree Collapse file tree 1 file changed +10
-9
lines changed Original file line number Diff line number Diff line change 11package com .baeldung .pmd ;
22
3- import net .sourceforge .pmd .lang .java .ast .ASTClassOrInterfaceDeclaration ;
4- import net .sourceforge .pmd .lang .java .rule .AbstractJavaRule ;
3+ import net .sourceforge .pmd .lang .java .ast .ASTClassDeclaration ;
4+ import net .sourceforge .pmd .lang .java .ast .JavaVisitorBase ;
5+ import net .sourceforge .pmd .reporting .RuleContext ;
56
67import java .util .Arrays ;
78import java .util .List ;
89import java .util .Objects ;
910
10- public class UnitTestNamingConventionRule extends AbstractJavaRule {
11+ public class UnitTestNamingConventionRule extends JavaVisitorBase < RuleContext , Void > {
1112
1213 private static List <String > allowedEndings = Arrays .asList (
1314 "IntegrationTest" ,
@@ -19,19 +20,19 @@ public class UnitTestNamingConventionRule extends AbstractJavaRule {
1920 "jmhTest" );
2021
2122 @ Override
22- public Object visit (ASTClassOrInterfaceDeclaration node , Object data ) {
23+ public Void visit (ASTClassDeclaration node , RuleContext ctx ) {
2324 String className = node .getSimpleName ();
2425 Objects .requireNonNull (className );
2526
2627 if (className .endsWith ("SpringContextTest" )) {
27- return data ;
28+ return null ;
2829 }
29-
30+
3031 if (className .endsWith ("Tests" )
31- || (className .endsWith ("Test" ) && allowedEndings .stream ().noneMatch (className ::endsWith ))) {
32- addViolation (data , node );
32+ || (className .endsWith ("Test" ) && allowedEndings .stream ().noneMatch (className ::endsWith ))) {
33+ ctx . addViolation (node );
3334 }
3435
35- return data ;
36+ return null ;
3637 }
3738}
You can’t perform that action at this time.
0 commit comments