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

This page was automatically generated by Maven