]> source.dussan.org Git - aspectj.git/commitdiff
Use StringBuilder/StringJoiner for concatenation String's in loop 110/head
authorAndrey Turbanov <turbanoff@gmail.com>
Sat, 18 Dec 2021 12:53:24 +0000 (15:53 +0300)
committerAndrey Turbanov <turbanoff@gmail.com>
Sat, 18 Dec 2021 12:53:24 +0000 (15:53 +0300)
ajde/src/main/java/org/aspectj/ajde/internal/LstBuildConfigFileUpdater.java
ajde/src/main/java/org/aspectj/ajde/ui/internal/UserPreferencesStore.java
ajdoc/src/main/java/org/aspectj/tools/ajdoc/HtmlDecorator.java
org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/internal/core/builder/AsmElementFormatter.java
taskdefs/src/main/java/org/aspectj/tools/ant/taskdefs/Ajdoc.java

index 5b83060b85e85aa48abb9a8205d95095bde137e2..fd2940c32f97fe0eb70126d941e1bf9f41af056d 100644 (file)
@@ -117,11 +117,11 @@ class LstBuildConfigFileUpdater {
 
        public void writeConfigFile(String filePath, List<BuildConfigNode> files, List<BuildConfigNode> importedNodes) {
                // Set contentsSet = new TreeSet(fileContents);
-               String fileContentsString = "";
+               StringBuilder fileContentsString = new StringBuilder();
                // List filesToWrite = null;
                Set<String> includedFiles = new HashSet<>();
                for (BuildConfigNode node : importedNodes) {
-                       fileContentsString += '@' + node.getResourcePath() + "\n";
+                       fileContentsString.append('@').append(node.getResourcePath()).append("\n");
                        String parentPath = new File(filePath).getParent();
                        String importedFilePath = parentPath + File.separator + node.getResourcePath();
                        includedFiles.addAll(getIncludedFiles(importedFilePath, parentPath));
@@ -129,15 +129,15 @@ class LstBuildConfigFileUpdater {
 
                for (BuildConfigNode node : files) {
                        if (node.getName().endsWith(".lst") && !node.getResourcePath().startsWith("..")) {
-                               fileContentsString += '@';
-                               fileContentsString += node.getResourcePath() + "\n";
+                               fileContentsString.append('@');
+                               fileContentsString.append(node.getResourcePath()).append("\n");
                        } else {
                                if (!includedFiles.contains(node.getResourcePath())) {
-                                       fileContentsString += node.getResourcePath() + "\n";
+                                       fileContentsString.append(node.getResourcePath()).append("\n");
                                }
                        }
                }
-               writeFile(fileContentsString, filePath);
+               writeFile(fileContentsString.toString(), filePath);
        }
 
        private List<String> getIncludedFiles(String path, String rootPath) {
index b8dc93332b80510b6ef8ce3bacee603edd141807..d774dadee796cb3cd1d4206ae396272f5b85c4f9 100644 (file)
@@ -74,11 +74,11 @@ public class UserPreferencesStore implements UserPreferencesAdapter {
 
        @Override
        public void setProjectMultivalPreference(String name, List values) {
-               String valuesString = "";
+               StringBuilder valuesString = new StringBuilder();
                for (Object value : values) {
-                       valuesString += (String) value + ';';
+                       valuesString.append((String)value).append(';');
                }
-               properties.setProperty(name, valuesString);
+               properties.setProperty(name, valuesString.toString());
                saveProperties();
        }
 
index 3f34d1b3d7770ea54d7c54a6339906c999b23b00..8e24320920811f9329737b87c5db0c13a5d2319a 100644 (file)
@@ -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 = "<TABLE WIDTH=\"100%\" BGCOLOR=#FFFFFF><TR>"
-                                       + "<TD width=\"15%\" bgcolor=\"#FFD8B0\"><B><FONT COLOR=000000>" + relKind.toString() + "</font></b></td><td>";
+                       StringBuilder adviceDoc = new StringBuilder("<TABLE WIDTH=\"100%\" BGCOLOR=#FFFFFF><TR>"
+                                       + "<TD width=\"15%\" bgcolor=\"#FFD8B0\"><B><FONT COLOR=000000>" + relKind.toString() + "</font></b></td><td>");
 
                        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 + "<A HREF=\"" + hrefLink + "\"><tt>" + hrefName.replace('/', '.') + "</tt></A>";
+                                       adviceDoc.append("<A HREF=\"").append(hrefLink).append("\"><tt>").append(hrefName.replace('/', '.')).append("</tt></A>");
 
                                        if (it.hasNext())
-                                               adviceDoc += ", ";
+                                               adviceDoc.append(", ");
                                        addedNames.add(hrefName);
                                }
                        }
-                       adviceDoc += "</TR></TD></TABLE>\n";
-                       fileContentsBuffer.insert(index, adviceDoc);
+                       adviceDoc.append("</TR></TD></TABLE>\n");
+                       fileContentsBuffer.insert(index, adviceDoc.toString());
                }
        }
 
@@ -710,24 +710,29 @@ class HtmlDecorator {
                }
                if (targets == null)
                        return "";
-               String entry = "<TABLE WIDTH=\"100%\" BGCOLOR=#FFFFFF><TR>";
+               StringBuilder entry = new StringBuilder("<TABLE WIDTH=\"100%\" BGCOLOR=#FFFFFF><TR>");
 
                IProgramElement.Kind kind = decl.getKind();
                if (kind.equals(IProgramElement.Kind.ADVICE)) {
-                       entry += "<TD width=\"10%\" bgcolor=\"#FFD8B0\"><B><FONT COLOR=000000>" + HtmlRelationshipKind.ADVISES.toString()
-                                       + "</b></font></td><td>";
+                       entry.append("<TD width=\"10%\" bgcolor=\"#FFD8B0\"><B><FONT COLOR=000000>")
+                                       .append(HtmlRelationshipKind.ADVISES)
+                                       .append("</b></font></td><td>");
                } else if (kind.equals(IProgramElement.Kind.DECLARE_WARNING) || kind.equals(IProgramElement.Kind.DECLARE_ERROR)) {
-                       entry += "<TD width=\"10%\" bgcolor=\"#FFD8B0\"><B><FONT COLOR=000000>" + HtmlRelationshipKind.MATCHED_BY.toString()
-                                       + "</b></font></td><td>";
+                       entry.append("<TD width=\"10%\" bgcolor=\"#FFD8B0\"><B><FONT COLOR=000000>")
+                                       .append(HtmlRelationshipKind.MATCHED_BY)
+                                       .append("</b></font></td><td>");
                } else if (kind.isDeclareAnnotation()) {
-                       entry += "<TD width=\"10%\" bgcolor=\"#FFD8B0\"><B><FONT COLOR=000000>" + HtmlRelationshipKind.ANNOTATES.toString()
-                                       + "</b></font></td><td>";
+                       entry.append("<TD width=\"10%\" bgcolor=\"#FFD8B0\"><B><FONT COLOR=000000>")
+                                       .append(HtmlRelationshipKind.ANNOTATES)
+                                       .append("</b></font></td><td>");
                } else if (kind.equals(IProgramElement.Kind.DECLARE_SOFT)) {
-                       entry += "<TD width=\"10%\" bgcolor=\"#FFD8B0\"><B><FONT COLOR=000000>" + HtmlRelationshipKind.SOFTENS.toString()
-                                       + "</b></font></td><td>";
+                       entry.append("<TD width=\"10%\" bgcolor=\"#FFD8B0\"><B><FONT COLOR=000000>")
+                                       .append(HtmlRelationshipKind.SOFTENS)
+                                       .append("</b></font></td><td>");
                } else {
-                       entry += "<TD width=\"10%\" bgcolor=\"#FFD8B0\"><B><FONT COLOR=000000>" + HtmlRelationshipKind.DECLARED_ON.toString()
-                                       + "</b></font></td><td>";
+                       entry.append("<TD width=\"10%\" bgcolor=\"#FFD8B0\"><B><FONT COLOR=000000>")
+                                       .append(HtmlRelationshipKind.DECLARED_ON)
+                                       .append("</b></font></td><td>");
                }
 
                String relativePackagePath = getRelativePathFromHere(decl.getPackageName().replace('.', '/') + Config.DIR_SEP_CHAR);
@@ -759,15 +764,15 @@ class HtmlDecorator {
                                }
 
                                if (!addedNames.contains(hrefName)) {
-                                       entry += "<A HREF=\"" + hrefLink + "\"><tt>" + hrefName.replace('/', '.') + "</tt></A>"; // !!! don't replace
+                                       entry.append("<A HREF=\"").append(hrefLink).append("\"><tt>").append(hrefName.replace('/', '.')).append("</tt></A>"); // !!! don't replace
                                        if (it.hasNext())
-                                               entry += ", ";
+                                               entry.append(", ");
                                        addedNames.add(hrefName);
                                }
                        }
                }
-               entry += "</B></FONT></TD></TR></TABLE>\n</TR></TD>\n";
-               return entry;
+               entry.append("</B></FONT></TD></TR></TABLE>\n</TR></TD>\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) {
index 5ce84dca79e38f12044016a818a1ef98dcf50880..699ffe3e0ad5041b12fa2e71161f5f6607e47b5d 100644 (file)
@@ -16,6 +16,7 @@ package org.aspectj.ajdt.internal.core.builder;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
+import java.util.StringJoiner;
 
 import org.aspectj.ajdt.internal.compiler.ast.AdviceDeclaration;
 import org.aspectj.ajdt.internal.compiler.ast.DeclareDeclaration;
@@ -256,14 +257,11 @@ public class AsmElementFormatter {
        }
 
        private String genPrecedenceListLabel(TypePatternList list) {
-               String tpList = "";
+               StringJoiner tpList = new StringJoiner(", ");
                for (int i = 0; i < list.size(); i++) {
-                       tpList += genTypePatternLabel(list.get(i));
-                       if (i < list.size() - 1) {
-                               tpList += ", ";
-                       }
+                       tpList.add(genTypePatternLabel(list.get(i)));
                }
-               return tpList;
+               return tpList.toString();
        }
 
        // private String genArguments(MethodDeclaration md) {
index c26c133098a42972bf20619dc64e5578cdeff537..e58db40f245fe5961af6d6c3b0a9c36e84281718 100644 (file)
@@ -20,9 +20,9 @@ import java.util.Collection;
 import java.util.Collections;
 import java.util.Enumeration;
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.StringJoiner;
 import java.util.StringTokenizer;
 import java.util.Vector;
 
@@ -636,14 +636,13 @@ public class Ajdoc extends MatchingTask {
         }
         for (String title: groupMap.keySet()) {
             List<String> packages = groupMap.get(title);
-            String pkgstr = "";
-            for (Iterator<String> j = packages.iterator(); j.hasNext();) {
-                pkgstr += j.next();
-                if (j.hasNext()) pkgstr += ",";
+            StringJoiner pkgstr = new StringJoiner(",");
+            for (String aPackage : packages) {
+                pkgstr.add(aPackage);
             }
             cmd.createArgument().setValue("-group");
             cmd.createArgument().setValue(title);
-            cmd.createArgument().setValue(pkgstr);
+            cmd.createArgument().setValue(pkgstr.toString());
         }
         if (argfiles != null) {
                        for (File file : argfiles) {