View Javadoc
1 package net.sourceforge.pmd; 2 3 import java.util.Comparator; 4 5 public class RuleViolation { 6 7 public static class RuleViolationComparator implements Comparator { 8 // 9 // Changed logic of Comparator so that rules in the same file 10 // get grouped together in the output report. 11 // DDP 7/11/2002 12 // 13 public int compare(Object o1, Object o2) { 14 RuleViolation r1 = (RuleViolation) o1; 15 RuleViolation r2 = (RuleViolation) o2; 16 if (!r1.getFilename().equals(r2.getFilename())) { 17 return r1.getFilename().compareTo(r2.getFilename()); 18 } 19 20 if (r1.getLine() != r2.getLine()) 21 return r1.getLine() - r2.getLine(); 22 23 if (r1.getDescription() != null && r2.getDescription() != null && !r1.getDescription().equals(r2.getDescription())) { 24 return r1.getDescription().compareTo(r2.getDescription()); 25 } 26 // line number diff maps nicely to compare() 27 return r1.getLine() - r2.getLine(); 28 } 29 } 30 31 private int line; 32 private Rule rule; 33 private String description; 34 private String filename; 35 36 public RuleViolation(Rule rule, int line, RuleContext ctx) { 37 this(rule, line, rule.getMessage(), ctx); 38 } 39 40 public RuleViolation(Rule rule, int line, String specificDescription, RuleContext ctx) { 41 this.line = line; 42 this.rule = rule; 43 this.description = specificDescription; 44 this.filename = ctx.getSourceCodeFilename(); 45 } 46 47 public Rule getRule() { 48 return rule; 49 } 50 51 public int getLine() { 52 return line; 53 } 54 55 public String getDescription() { 56 return description; 57 } 58 59 public String getFilename() { 60 return filename; 61 } 62 }

This page was automatically generated by Maven