Clover coverage report - PMD - 3.7 Coverage timestamp: Wed May 31 2006 09:25:59 EDT FRAMES NO FRAMES |
file stats: | LOC: | 86 |  | Methods: | 8
| NCLOC: | 67 |  | Classes: | 2
Source file | Conditionals | Statements | Methods | TOTAL
IDEAJRenderer.java | 0% | 3.2% | 12.5% | 3.9% |

1 |  | /**
2 |  | * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
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.HashSet;
11 |  | import java.util.Iterator;
12 |  | import java.util.Set;
13 |  | import java.util.StringTokenizer;
14 |  |
15 |  | public class IDEAJRenderer extends AbstractRenderer implements Renderer {
16 |  |
17 |  | private static class SourcePath {
18 |  |
19 |  | private Set paths = new HashSet();
20 |  |
21 | 0 | public SourcePath(String sourcePathString) {
22 | 0 | for (StringTokenizer st = new StringTokenizer(sourcePathString, System.getProperty("path.separator")); st.hasMoreTokens();) {
23 | 0 | paths.add(st.nextToken());
24 |  | }
25 |  | }
26 |  |
27 | 0 | public String clipPath(String fullFilename) {
28 | 0 | for (Iterator i = paths.iterator(); i.hasNext();) {
29 | 0 | String path = (String) i.next();
30 | 0 | if (fullFilename.startsWith(path)) {
31 | 0 | return fullFilename.substring(path.length() + 1);
32 |  | }
33 |  | }
34 | 0 | throw new RuntimeException("Couldn't find src path for " + fullFilename);
35 |  | }
36 |  | }
37 |  |
38 |  | private String[] args;
39 |  |
40 | 1 | public IDEAJRenderer(String[] args) {
41 | 1 | this.args = args;
42 |  | }
43 |  |
44 | 0 | public String render(Report report) {
45 | 0 | if (args[4].equals(".method")) {
46 |  | // working on a directory tree
47 | 0 | String sourcePath = args[3];
48 | 0 | return render(report, sourcePath);
49 |  | }
50 |  | // working on one file
51 | 0 | String classAndMethodName = args[4];
52 | 0 | String singleFileName = args[5];
53 | 0 | return render(report, classAndMethodName, singleFileName);
54 |  | }
55 |  |
56 | 0 | private String render(Report report, String sourcePathString) {
57 | 0 | SourcePath sourcePath = new SourcePath(sourcePathString);
58 | 0 | StringBuffer buf = new StringBuffer();
59 | 0 | for (Iterator i = report.iterator(); i.hasNext();) {
60 | 0 | IRuleViolation rv = (IRuleViolation) i.next();
61 | 0 | buf.append(rv.getDescription() + PMD.EOL);
62 | 0 | buf.append(" at " + getFullyQualifiedClassName(rv.getFilename(), sourcePath) + ".method(" + getSimpleFileName(rv.getFilename()) + ":" + rv.getBeginLine() + ")" + PMD.EOL);
63 |  | }
64 | 0 | return buf.toString();
65 |  | }
66 |  |
67 | 0 | private String render(Report report, String classAndMethod, String file) {
68 | 0 | StringBuffer buf = new StringBuffer();
69 | 0 | for (Iterator i = report.iterator(); i.hasNext();) {
70 | 0 | IRuleViolation rv = (IRuleViolation) i.next();
71 | 0 | buf.append(rv.getDescription() + PMD.EOL);
72 | 0 | buf.append(" at " + classAndMethod + "(" + file + ":" + rv.getBeginLine() + ")" + PMD.EOL);
73 |  | }
74 | 0 | return buf.toString();
75 |  | }
76 |  |
77 | 0 | private String getFullyQualifiedClassName(String in, SourcePath sourcePath) {
78 | 0 | String classNameWithSlashes = sourcePath.clipPath(in);
79 | 0 | String className = classNameWithSlashes.replace(System.getProperty("file.separator").charAt(0), '.');
80 | 0 | return className.substring(0, className.length() - 5);
81 |  | }
82 |  |
83 | 0 | private String getSimpleFileName(String in) {
84 | 0 | return in.substring(in.lastIndexOf(System.getProperty("file.separator")) + 1);
85 |  | }
86 |  | }