1
2
3
4
5 package com.qulice.pmd;
6
7 import net.sourceforge.pmd.Report.ConfigurationError;
8 import net.sourceforge.pmd.Report.ProcessingError;
9 import net.sourceforge.pmd.RuleViolation;
10
11
12
13
14
15
16 public interface PmdError {
17
18
19
20
21
22 String name();
23
24
25
26
27
28
29 String fileName();
30
31
32
33
34
35
36 String lines();
37
38
39
40
41
42 String description();
43
44
45
46
47
48 final class OfRuleViolation implements PmdError {
49
50
51
52 private final RuleViolation violation;
53
54
55
56
57
58 public OfRuleViolation(final RuleViolation violation) {
59 this.violation = violation;
60 }
61
62 @Override
63 public String name() {
64 return this.violation.getRule().getName();
65 }
66
67 @Override
68 public String fileName() {
69 return this.violation.getFilename();
70 }
71
72 @Override
73 public String lines() {
74 return String.format(
75 "%d-%d",
76 this.violation.getBeginLine(), this.violation.getEndLine()
77 );
78 }
79
80 @Override
81 public String description() {
82 return this.violation.getDescription();
83 }
84 }
85
86
87
88
89
90 final class OfProcessingError implements PmdError {
91
92
93
94 private final ProcessingError error;
95
96
97
98
99
100 public OfProcessingError(final ProcessingError error) {
101 this.error = error;
102 }
103
104 @Override
105 public String name() {
106 return "ProcessingError";
107 }
108
109 @Override
110 public String fileName() {
111 return this.error.getFile();
112 }
113
114 @Override
115 public String lines() {
116 return "unknown";
117 }
118
119 @Override
120 public String description() {
121 return new StringBuilder()
122 .append(this.error.getMsg())
123 .append(": ")
124 .append(this.error.getDetail())
125 .toString();
126 }
127 }
128
129
130
131
132
133 final class OfConfigError implements PmdError {
134
135
136
137 private final ConfigurationError error;
138
139
140
141
142
143 public OfConfigError(final ConfigurationError error) {
144 this.error = error;
145 }
146
147 @Override
148 public String name() {
149 return "ProcessingError";
150 }
151
152 @Override
153 public String fileName() {
154 return "unknown";
155 }
156
157 @Override
158 public String lines() {
159 return "unknown";
160 }
161
162 @Override
163 public String description() {
164 return this.error.issue();
165 }
166 }
167 }