Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.selesse.jxlint.actions;
  
 
 import java.util.List;

Class that is knowledgeable about com.selesse.jxlint.model.rules.LintRules. The corresponding static methods print out their knowledge, and exit the program using com.selesse.jxlint.ProgramExitter.
 
 public class LintRuleInformationDisplayer {
    
List all of the com.selesse.jxlint.model.rules.LintRules, in summary form:
     "Lint Rule 1" : This rule looks at source code.
     "Lint Rule 2" : This rule looks at source code comments.
 
 
     public static void listRules() {
         List<StringoutputBuffer = Lists.newArrayList();
 
         LintRules lintRules = LintRulesImpl.getInstance();
         if (lintRules.getAllRules().size() == 0) {
             outputBuffer.add("There are no rules defined.");
         }
         for (LintRule lintRule : lintRules.getAllRules()) {
             outputBuffer.add(lintRule.getSummaryOutput());
         }
 
         ProgramExitter.exitProgramWithMessage(Joiner.on("\n").join(outputBuffer), .);
     }

    
 
     public static void showRules(ProgramOptions programOptions) {
         try {
             StringBuilder outputBuffer = new StringBuilder();
             if (programOptions.hasOption(.) && programOptions.getOption(.) == null) {
                 for (LintRule rule : LintRulesImpl.getInstance().getAllRules()) {
                     outputBuffer.append(rule.getDetailedOutput()).append("\n\n");
                 }
                 outputBuffer.append("There are ").append(
                         LintRulesImpl.getInstance().getAllRules().size()).append(" rules.");
             }
             else {
                 Splitter splitter = Splitter.on(",").trimResults().omitEmptyStrings();
 
                 List<Stringrules = splitter.splitToList(programOptions.getOption(.));
                 for (String rule : rules) {
                     LintRule lintRule = LintRulesImpl.getInstance().getLintRule(rule.trim());
                     outputBuffer.append(lintRule.getDetailedOutput()).append("\n\n");
                 }
             }
             ProgramExitter.exitProgramWithMessage(outputBuffer.toString(), .);
         }
         catch (NonExistentLintRuleException e) {
             ProgramExitter.exitProgramWithMessage(String.format("'%s' is not a valid rule."e.getRuleName()),
                     .);
         }
     }
 
     public static void printMarkdownRuleReport(ProgramSettings settings) {
         StringBuilder outputStringBuilder = new StringBuilder();
         String headerString =
                 String.format("Rules for %s - %s"settings.getProgramName(), settings.getProgramVersion());
         outputStringBuilder.append(underline(headerString"=")).append("\n\n");
 
         List<LintRuleallRules = LintRulesImpl.getInstance().getAllRules();
         for (int i = 0; i < allRules.size(); i++) {
             LintRule lintRule = allRules.get(i);
             outputStringBuilder.append(getMarkdownString(lintRule)).append("\n");
             if (i + 1 < allRules.size()) {
                 outputStringBuilder.append("---");
             }
             outputStringBuilder.append("\n\n");
         }
 
         ProgramExitter.exitProgramWithMessage(outputStringBuilder.toString(), .);
     }
 
     private static String underline(String stringString underlineCharacter) {
         int numberOfChars = string.length();
 
         StringBuilder underLineChar = new StringBuilder();
 
        for (int i = 0; i < numberOfCharsi++) {
            underLineChar.append(underlineCharacter);
        }
        return string + "\n" + underLineChar.toString();
    }
    private static String getMarkdownString(LintRule lintRule) {
        StringBuilder outputStringBuilder = new StringBuilder();
        // Name of a rule
        // --------------
        // **Summary** : summary
        // **Category** : CATEGORY
        // **Severity** : Severity
        // **Enabled by default?** : yes
        //
        // **Detailed description** :
        //
        // detailedExplanation
        outputStringBuilder.append(underline(lintRule.getName(), "-")).append("\n");
        outputStringBuilder.append("**Summary** : ").append(lintRule.getSummary()).append("\n\n");
        outputStringBuilder.append("**Category** : ").append(lintRule.getCategory()).append("\n\n");
        outputStringBuilder.append("**Severity** : ").append(lintRule.getSeverity()).append("\n\n");
        outputStringBuilder.append("**Enabled by default?** : ").
                append(lintRule.isEnabled() ? "yes" : "no").append("\n\n");
        outputStringBuilder.append("\n").append("**Detailed description** :").append("\n\n");
        String explanation = lintRule.getDetailedDescription();
        outputStringBuilder.append(explanation).append("\n");
        return outputStringBuilder.toString();
    }
New to GrepCode? Check out our FAQ X