From 84b0547cd77d8fa7a776b858cfdb3ba0efd98900 Mon Sep 17 00:00:00 2001 From: Brian Remedios Date: Sat, 24 Sep 2011 20:50:43 +0000 Subject: [PATCH] StringBuffer -> StringBuilder switchovers git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@7342 51baf565-9d33-0410-a72c-fc3788e3496d --- .../dfa/report/ReportHTMLPrintVisitor.java | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/pmd/src/net/sourceforge/pmd/lang/dfa/report/ReportHTMLPrintVisitor.java b/pmd/src/net/sourceforge/pmd/lang/dfa/report/ReportHTMLPrintVisitor.java index ffa62cb107..23aacce4dc 100644 --- a/pmd/src/net/sourceforge/pmd/lang/dfa/report/ReportHTMLPrintVisitor.java +++ b/pmd/src/net/sourceforge/pmd/lang/dfa/report/ReportHTMLPrintVisitor.java @@ -2,6 +2,7 @@ package net.sourceforge.pmd.lang.dfa.report; import net.sourceforge.pmd.RuleViolation; import net.sourceforge.pmd.PMD; +import net.sourceforge.pmd.util.IOUtil; import net.sourceforge.pmd.util.StringUtil; import java.io.BufferedWriter; @@ -21,9 +22,9 @@ import java.io.IOException; public class ReportHTMLPrintVisitor extends ReportVisitor { @SuppressWarnings("PMD.AvoidStringBufferField") - private StringBuffer packageBuf = new StringBuffer(); + private StringBuilder packageBuf = new StringBuilder(); @SuppressWarnings("PMD.AvoidStringBufferField") - private StringBuffer classBuf = new StringBuffer(); + private StringBuilder classBuf = new StringBuilder(); private int length; private String baseDir; @@ -36,10 +37,10 @@ public class ReportHTMLPrintVisitor extends ReportVisitor { /** * Writes the buffer to file. */ - private void write(String filename, StringBuffer buf) throws IOException { + private void write(String filename, StringBuilder buf) throws IOException { BufferedWriter bw = new BufferedWriter(new FileWriter(new File(baseDir + FILE_SEPARATOR + filename))); bw.write(buf.toString(), 0, buf.length()); - bw.close(); + IOUtil.closeQuietly(bw); } /** @@ -47,7 +48,7 @@ public class ReportHTMLPrintVisitor extends ReportVisitor { */ private String displayRuleViolation(RuleViolation vio) { - StringBuffer sb = new StringBuffer(200); + StringBuilder sb = new StringBuilder(200); sb.append(""); renderViolationRow(sb, "Rule:", vio.getRule().getName()); renderViolationRow(sb, "Description:", vio.getDescription()); @@ -67,7 +68,7 @@ public class ReportHTMLPrintVisitor extends ReportVisitor { } // TODO - join the 21st century, include CSS attributes :) - private void renderViolationRow(StringBuffer sb, String fieldName, String fieldData) { + private void renderViolationRow(StringBuilder sb, String fieldName, String fieldData) { sb.append(""); } @@ -83,7 +84,7 @@ public class ReportHTMLPrintVisitor extends ReportVisitor { * The first node of result tree. */ if (node.getParent() == null) { - this.packageBuf.insert(0, + packageBuf.insert(0, "" + " " + " PMD" + @@ -97,7 +98,7 @@ public class ReportHTMLPrintVisitor extends ReportVisitor { "" + " " + PMD.EOL); - this.length = this.packageBuf.length(); + length = packageBuf.length(); } @@ -133,14 +134,14 @@ public class ReportHTMLPrintVisitor extends ReportVisitor { try { - this.write(str + ".html", classBuf); + write(str + ".html", classBuf); } catch (Exception e) { throw new RuntimeException("Error while writing HTML report: " + e.getMessage()); } - classBuf = new StringBuffer(); + classBuf = new StringBuilder(); - this.packageBuf.insert(this.length, + packageBuf.insert(this.length, "" + " " + " " + @@ -160,7 +161,7 @@ public class ReportHTMLPrintVisitor extends ReportVisitor { node.getParent().addNumberOfViolation(node.getNumberOfViolations()); } - this.packageBuf.insert(this.length, + packageBuf.insert(length, "" + " " + " " + @@ -168,9 +169,9 @@ public class ReportHTMLPrintVisitor extends ReportVisitor { } // The first node of result tree. if (node.getParent() == null) { - this.packageBuf.append("
").append(fieldName).append("").append(fieldData).append("
#
-" + str + "
" + str + "-" + node.getNumberOfViolations() + "
"); + packageBuf.append(" "); try { - this.write("index.html", this.packageBuf); + write("index.html", packageBuf); } catch (Exception e) { throw new RuntimeException("Error while writing HTML report: " + e.getMessage()); }