|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| package net.sourceforge.pmd.renderers; |
|
5 |
| |
|
6 |
| import net.sourceforge.pmd.PMD; |
|
7 |
| import net.sourceforge.pmd.Report; |
|
8 |
| import net.sourceforge.pmd.IRuleViolation; |
|
9 |
| |
|
10 |
| import java.util.Iterator; |
|
11 |
| |
|
12 |
| public class TextRenderer extends AbstractRenderer implements Renderer { |
|
13 |
| |
|
14 |
0
| public String render(Report report) {
|
|
15 |
0
| StringBuffer buf = new StringBuffer();
|
|
16 |
| |
|
17 |
0
| if (report.isEmpty()) {
|
|
18 |
0
| buf.append("No problems found!");
|
|
19 |
0
| if (showSuppressedViolations) {
|
|
20 |
0
| addSuppressed(report, buf);
|
|
21 |
| } |
|
22 |
0
| return buf.toString();
|
|
23 |
| } |
|
24 |
| |
|
25 |
0
| for (Iterator i = report.iterator(); i.hasNext();) {
|
|
26 |
0
| IRuleViolation rv = (IRuleViolation) i.next();
|
|
27 |
0
| buf.append(PMD.EOL + rv.getFilename());
|
|
28 |
0
| buf.append(":" + Integer.toString(rv.getBeginLine()));
|
|
29 |
0
| buf.append("\t" + rv.getDescription());
|
|
30 |
| } |
|
31 |
| |
|
32 |
0
| for (Iterator i = report.errors(); i.hasNext();) {
|
|
33 |
0
| Report.ProcessingError error = (Report.ProcessingError) i.next();
|
|
34 |
0
| buf.append(PMD.EOL + error.getFile());
|
|
35 |
0
| buf.append("\t-");
|
|
36 |
0
| buf.append("\t" + error.getMsg());
|
|
37 |
| } |
|
38 |
| |
|
39 |
0
| if (showSuppressedViolations) {
|
|
40 |
0
| addSuppressed(report, buf);
|
|
41 |
| } |
|
42 |
| |
|
43 |
0
| return buf.toString();
|
|
44 |
| } |
|
45 |
| |
|
46 |
0
| private void addSuppressed(Report report, StringBuffer buf) {
|
|
47 |
0
| for (Iterator i = report.getSuppressedRuleViolations().iterator(); i.hasNext();) {
|
|
48 |
0
| Report.SuppressedViolation excluded = (Report.SuppressedViolation) i.next();
|
|
49 |
0
| buf.append(PMD.EOL + excluded.getRuleViolation().getRule().getName() + " rule violation suppressed by " + (excluded.suppressedByNOPMD() ? "//NOPMD" : "Annotation") + " in " + excluded.getRuleViolation().getFilename());
|
|
50 |
| } |
|
51 |
| } |
|
52 |
| } |