@@ -63,6 +63,9 @@ public CheckstyleMetadata(RulesDefinition.NewRepository repository) {
6363 });
6464 }
6565
66+ /**
67+ * Update all the metadata from sonar rule database with checkstyle metadata.
68+ */
6669 public void updateRulesWithMetadata () {
6770 repository .rules ().forEach (rule -> {
6871 final ModuleDetails moduleDetails = metadataRepo .get (rule .key ());
@@ -82,6 +85,9 @@ public void updateRulesWithMetadata() {
8285 });
8386 }
8487
88+ /**
89+ * Create checkstyle metadata for checks which are not present in rules.xml.
90+ */
8591 public void createRulesWithMetadata () {
8692 final Set <String > existingChecks = repository .rules ().stream ()
8793 .map (RulesDefinition .NewRule ::key )
@@ -134,6 +140,12 @@ public void createRulesWithMetadata() {
134140 });
135141 }
136142
143+ /**
144+ * Get class with the given check name.
145+ *
146+ * @param checkName check name
147+ * @return check class
148+ */
137149 private Class <?> getClass (String checkName ) {
138150 final ClassLoader loader = getClass ().getClassLoader ();
139151 try {
@@ -145,11 +157,23 @@ private Class<?> getClass(String checkName) {
145157 }
146158 }
147159
160+ /**
161+ * Determine whether the check is a template rule based on the method types of the check.
162+ *
163+ * @param checkName check name
164+ * @return true if check is a template rule
165+ */
148166 private boolean isTemplateRule (String checkName ) {
149167 return Arrays .stream (getClass (checkName ).getMethods ())
150168 .anyMatch (CheckstyleMetadata ::isSetter );
151169 }
152170
171+ /**
172+ * Get enum values for the provided enum class name.
173+ *
174+ * @param enumName enum class name
175+ * @return enum values
176+ */
153177 private List <String > getEnumValues (String enumName ) {
154178 final Class <?> loadedClass = getClass (enumName );
155179 final Object [] vals = loadedClass .getEnumConstants ();
@@ -160,6 +184,13 @@ private List<String> getEnumValues(String enumName) {
160184 return enumVals ;
161185 }
162186
187+ /**
188+ * Construct check parameter metadata.
189+ *
190+ * @param checkName check name
191+ * @param param parameter details fetched from sonar database
192+ * @param modulePropertyDetails constructed new parameter metadata
193+ */
163194 private void constructParams (String checkName , RulesDefinition .NewParam param ,
164195 ModulePropertyDetails modulePropertyDetails ) {
165196 param .setDescription (modulePropertyDetails .getDescription ())
@@ -203,6 +234,13 @@ else if (paramType.endsWith(OPTION_STRING)) {
203234 }
204235 }
205236
237+ /**
238+ * Get rule tags for checks, either based on package type or from the YML config(if provided).
239+ *
240+ * @param checkPackage check name
241+ * @param configData additional metadata from YML config
242+ * @return the determined rule tag
243+ */
206244 private static String getRuleTag (String checkPackage ,
207245 SonarRulePropertyLoader .AdditionalRuleProperties configData ) {
208246 String result = null ;
@@ -224,6 +262,12 @@ private static String getRuleTag(String checkPackage,
224262 return result ;
225263 }
226264
265+ /**
266+ * Fetch additional module details from a YML config.
267+ *
268+ * @param fileName YML config file
269+ * @return map of additional metadata
270+ */
227271 private static Map <String , SonarRulePropertyLoader .AdditionalRuleProperties >
228272 getAdditionalDetails (String fileName ) {
229273
@@ -245,6 +289,12 @@ private static String getRuleTag(String checkPackage,
245289 return additionalDetails ;
246290 }
247291
292+ /**
293+ * Check if the provided method is a setter.
294+ *
295+ * @param method class method
296+ * @return true if the method is a setter
297+ */
248298 public static boolean isSetter (Method method ) {
249299 return method .getName ().startsWith ("set" )
250300 && method .getParameterTypes ().length == 1 ;
@@ -269,6 +319,12 @@ public static String getFullCheckName(String checkName) {
269319 return result .toString ();
270320 }
271321
322+ /**
323+ * Create internal key composed of parents of module.
324+ *
325+ * @param moduleDetails module metadata
326+ * @return internalKey
327+ */
272328 public static String getInternalKey (ModuleDetails moduleDetails ) {
273329 String result = "Checker/" ;
274330 if ("com.puppycrawl.tools.checkstyle.Checker" .equals (moduleDetails .getParent ())) {
0 commit comments