From be522b7e8a591ef54f71d574dd5c76799a2b5136 Mon Sep 17 00:00:00 2001 From: Andrey Turbanov Date: Sat, 18 Dec 2021 15:53:24 +0300 Subject: Use StringBuilder/StringJoiner for concatenation String's in loop --- .../org/aspectj/tools/ajdoc/HtmlDecorator.java | 53 ++++++++++++---------- 1 file changed, 29 insertions(+), 24 deletions(-) (limited to 'ajdoc') diff --git a/ajdoc/src/main/java/org/aspectj/tools/ajdoc/HtmlDecorator.java b/ajdoc/src/main/java/org/aspectj/tools/ajdoc/HtmlDecorator.java index 3f34d1b3d..8e2432092 100644 --- a/ajdoc/src/main/java/org/aspectj/tools/ajdoc/HtmlDecorator.java +++ b/ajdoc/src/main/java/org/aspectj/tools/ajdoc/HtmlDecorator.java @@ -572,8 +572,8 @@ class HtmlDecorator { static void decorateDocWithRel(IProgramElement node, StringBuilder fileContentsBuffer, int index, List targets, HtmlRelationshipKind relKind) { if (targets != null && !targets.isEmpty()) { - String adviceDoc = "" - + "
" + relKind.toString() + ""; + StringBuilder adviceDoc = new StringBuilder("" + + "
" + relKind.toString() + ""); String relativePackagePath = getRelativePathFromHere(node.getPackageName().replace('.', '/') + Config.DIR_SEP_CHAR); @@ -644,15 +644,15 @@ class HtmlDecorator { hrefLink += sbuff.toString() + ".html" + "#" + sb.toString(); if (!addedNames.contains(hrefName)) { - adviceDoc = adviceDoc + "" + hrefName.replace('/', '.') + ""; + adviceDoc.append("").append(hrefName.replace('/', '.')).append(""); if (it.hasNext()) - adviceDoc += ", "; + adviceDoc.append(", "); addedNames.add(hrefName); } } - adviceDoc += "
\n"; - fileContentsBuffer.insert(index, adviceDoc); + adviceDoc.append("
\n"); + fileContentsBuffer.insert(index, adviceDoc.toString()); } } @@ -710,24 +710,29 @@ class HtmlDecorator { } if (targets == null) return ""; - String entry = ""; + StringBuilder entry = new StringBuilder("
"); IProgramElement.Kind kind = decl.getKind(); if (kind.equals(IProgramElement.Kind.ADVICE)) { - entry += "
" + HtmlRelationshipKind.ADVISES.toString() - + ""; + entry.append("") + .append(HtmlRelationshipKind.ADVISES) + .append(""); } else if (kind.equals(IProgramElement.Kind.DECLARE_WARNING) || kind.equals(IProgramElement.Kind.DECLARE_ERROR)) { - entry += "" + HtmlRelationshipKind.MATCHED_BY.toString() - + ""; + entry.append("") + .append(HtmlRelationshipKind.MATCHED_BY) + .append(""); } else if (kind.isDeclareAnnotation()) { - entry += "" + HtmlRelationshipKind.ANNOTATES.toString() - + ""; + entry.append("") + .append(HtmlRelationshipKind.ANNOTATES) + .append(""); } else if (kind.equals(IProgramElement.Kind.DECLARE_SOFT)) { - entry += "" + HtmlRelationshipKind.SOFTENS.toString() - + ""; + entry.append("") + .append(HtmlRelationshipKind.SOFTENS) + .append(""); } else { - entry += "" + HtmlRelationshipKind.DECLARED_ON.toString() - + ""; + entry.append("") + .append(HtmlRelationshipKind.DECLARED_ON) + .append(""); } String relativePackagePath = getRelativePathFromHere(decl.getPackageName().replace('.', '/') + Config.DIR_SEP_CHAR); @@ -759,15 +764,15 @@ class HtmlDecorator { } if (!addedNames.contains(hrefName)) { - entry += "" + hrefName.replace('/', '.') + ""; // !!! don't replace + entry.append("").append(hrefName.replace('/', '.')).append(""); // !!! don't replace if (it.hasNext()) - entry += ", "; + entry.append(", "); addedNames.add(hrefName); } } } - entry += "
\n\n"; - return entry; + entry.append("\n\n"); + return entry.toString(); } /** @@ -873,7 +878,7 @@ class HtmlDecorator { if (comment == null) return ""; - String formattedComment = ""; + StringBuilder formattedComment = new StringBuilder(); // strip the comment markers int startIndex = comment.indexOf("/**"); @@ -909,12 +914,12 @@ class HtmlDecorator { // if ( linkIndex != -1 ) { // line = line.substring(0, linkIndex) + line.substring(linkIndex); // } - formattedComment += line; + formattedComment.append(line); } } catch (IOException ioe) { throw new Error("Couldn't format comment for declaration: " + decl.getName()); } - return formattedComment; + return formattedComment.toString(); } static public IProgramElement[] getProgramElements(AsmManager model, String filename) { -- cgit v1.2.3