2121
2222import java .io .IOException ;
2323import java .io .InputStream ;
24- import java .lang .reflect .Method ;
2524import java .nio .charset .StandardCharsets ;
2625import java .util .ArrayList ;
2726import java .util .Arrays ;
4241import com .google .common .collect .ImmutableList ;
4342import com .puppycrawl .tools .checkstyle .meta .ModuleDetails ;
4443import com .puppycrawl .tools .checkstyle .meta .ModulePropertyDetails ;
44+ import com .puppycrawl .tools .checkstyle .meta .ModuleType ;
4545import com .puppycrawl .tools .checkstyle .meta .XmlMetaReader ;
4646
4747public class CheckstyleMetadata {
@@ -85,11 +85,12 @@ public void createRulesWithMetadata() {
8585 new DefaultDebtRemediationFunction (DebtRemediationFunction .Type .CONSTANT_ISSUE ,
8686 null , "0d 0h 5min" );
8787
88- metadataRepo
89- .forEach ((checkKey , metadata ) -> {
90- final ModuleDetails moduleDetails = metadataRepo .get (checkKey );
88+ metadataRepo .entrySet ().stream ()
89+ .filter (entry -> entry .getValue ().getModuleType () == ModuleType .CHECK )
90+ .forEach (check -> {
91+ final ModuleDetails moduleDetails = check .getValue ();
9192 final SonarRulePropertyLoader .AdditionalRuleProperties additionalDetails =
92- additionalRuleData .get (checkKey );
93+ additionalRuleData .get (check . getKey () );
9394 final RulesDefinition .NewRule rule =
9495 repository .createRule (moduleDetails .getFullQualifiedName ());
9596 rule .setHtmlDescription (moduleDetails .getDescription ())
@@ -105,7 +106,7 @@ public void createRulesWithMetadata() {
105106 if (tag != null ) {
106107 rule .setTags (tag );
107108 }
108- if (isTemplateRule (moduleDetails . getFullQualifiedName () )) {
109+ if (isTemplateRule (moduleDetails )) {
109110 rule .setTemplate (true );
110111 }
111112
@@ -135,14 +136,14 @@ private Class<?> getClass(String checkName) {
135136 }
136137
137138 /**
138- * Determine whether the check is a template rule based on the method types of the check.
139+ * Determine whether the check is a template rule based on the number of the properties of
140+ * check.
139141 *
140- * @param checkName check name
142+ * @param moduleDetails module
141143 * @return true if check is a template rule
142144 */
143- private boolean isTemplateRule (String checkName ) {
144- return Arrays .stream (getClass (checkName ).getMethods ())
145- .anyMatch (CheckstyleMetadata ::isSetter );
145+ private static boolean isTemplateRule (ModuleDetails moduleDetails ) {
146+ return !moduleDetails .getProperties ().isEmpty ();
146147 }
147148
148149 /**
@@ -303,17 +304,6 @@ private static String getRuleTag(String checkPackage,
303304 return additionalDetails ;
304305 }
305306
306- /**
307- * Check if the provided method is a setter.
308- *
309- * @param method class method
310- * @return true if the method is a setter
311- */
312- public static boolean isSetter (Method method ) {
313- return method .getName ().startsWith ("set" )
314- && method .getParameterTypes ().length == 1 ;
315- }
316-
317307 /**
318308 * It converts the name received from ModuleDetails to Sonar rule name format
319309 * e.g. RightCurlyCheck -> Right Curly Check
0 commit comments