Clover coverage report - PMD - 3.9
Coverage timestamp: Tue Dec 19 2006 09:38:44 EST
file stats: LOC: 95   Methods: 8
NCLOC: 75   Classes: 2
 
 Source file Conditionals Statements Methods TOTAL
IDEAJRenderer.java 25% 34.3% 37.5% 32.7%
coverage coverage
 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.IRuleViolation;
 7    import net.sourceforge.pmd.PMD;
 8    import net.sourceforge.pmd.Report;
 9   
 10    import java.io.IOException;
 11    import java.io.Writer;
 12    import java.util.HashSet;
 13    import java.util.Iterator;
 14    import java.util.Set;
 15    import java.util.StringTokenizer;
 16   
 17    public class IDEAJRenderer extends AbstractRenderer {
 18   
 19    private static final String FILE_SEPARATOR = System.getProperty("file.separator");
 20    private static final String PATH_SEPARATOR = System.getProperty("path.separator");
 21   
 22    private static class SourcePath {
 23   
 24    private Set paths = new HashSet();
 25   
 26  0 public SourcePath(String sourcePathString) {
 27  0 for (StringTokenizer st = new StringTokenizer(sourcePathString, PATH_SEPARATOR); st.hasMoreTokens();) {
 28  0 paths.add(st.nextToken());
 29    }
 30    }
 31   
 32  0 public String clipPath(String fullFilename) {
 33  0 for (Iterator i = paths.iterator(); i.hasNext();) {
 34  0 String path = (String) i.next();
 35  0 if (fullFilename.startsWith(path)) {
 36  0 return fullFilename.substring(path.length() + 1);
 37    }
 38    }
 39  0 throw new RuntimeException("Couldn't find src path for " + fullFilename);
 40    }
 41    }
 42   
 43    private String[] args;
 44   
 45  6 public IDEAJRenderer(String[] args) {
 46  6 this.args = args;
 47    }
 48   
 49  5 public void render(Writer writer, Report report) throws IOException {
 50  5 if (args[4].equals(".method")) {
 51    // working on a directory tree
 52  0 String sourcePath = args[3];
 53  0 render(writer, report, sourcePath);
 54  0 return;
 55    }
 56    // working on one file
 57  5 String classAndMethodName = args[4];
 58  5 String singleFileName = args[5];
 59  5 render(writer, report, classAndMethodName, singleFileName);
 60    }
 61   
 62  0 private void render(Writer writer, Report report, String sourcePathString) throws IOException {
 63  0 SourcePath sourcePath = new SourcePath(sourcePathString);
 64  0 StringBuffer buf = new StringBuffer();
 65  0 for (Iterator i = report.iterator(); i.hasNext();) {
 66  0 buf.setLength(0);
 67  0 IRuleViolation rv = (IRuleViolation) i.next();
 68  0 buf.append(rv.getDescription() + PMD.EOL);
 69  0 buf.append(" at ").append(getFullyQualifiedClassName(rv.getFilename(), sourcePath)).append(".method(");
 70  0 buf.append(getSimpleFileName(rv.getFilename())).append(':').append(rv.getBeginLine()).append(')').append(PMD.EOL);
 71  0 writer.write(buf.toString());
 72    }
 73    }
 74   
 75  5 private void render(Writer writer, Report report, String classAndMethod, String file) throws IOException {
 76  5 StringBuffer buf = new StringBuffer();
 77  5 for (Iterator i = report.iterator(); i.hasNext();) {
 78  3 buf.setLength(0);
 79  3 IRuleViolation rv = (IRuleViolation) i.next();
 80  3 buf.append(rv.getDescription()).append(PMD.EOL);
 81  3 buf.append(" at ").append(classAndMethod).append('(').append(file).append(':').append(rv.getBeginLine()).append(')').append(PMD.EOL);
 82  3 writer.write(buf.toString());
 83    }
 84    }
 85   
 86  0 private String getFullyQualifiedClassName(String in, SourcePath sourcePath) {
 87  0 String classNameWithSlashes = sourcePath.clipPath(in);
 88  0 String className = classNameWithSlashes.replace(FILE_SEPARATOR.charAt(0), '.');
 89  0 return className.substring(0, className.length() - 5);
 90    }
 91   
 92  0 private String getSimpleFileName(String in) {
 93  0 return in.substring(in.lastIndexOf(FILE_SEPARATOR) + 1);
 94    }
 95    }