Browse Source

Use StringBuilder/StringJoiner for concatenation String's in loop

tags/V1_9_8
Andrey Turbanov 2 years ago
parent
commit
be522b7e8a

+ 6
- 6
ajde/src/main/java/org/aspectj/ajde/internal/LstBuildConfigFileUpdater.java View 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) {

+ 3
- 3
ajde/src/main/java/org/aspectj/ajde/ui/internal/UserPreferencesStore.java View 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();
}


+ 29
- 24
ajdoc/src/main/java/org/aspectj/tools/ajdoc/HtmlDecorator.java View 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) {

+ 4
- 6
org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/internal/core/builder/AsmElementFormatter.java View 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) {

+ 5
- 6
taskdefs/src/main/java/org/aspectj/tools/ant/taskdefs/Ajdoc.java View 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) {

Loading…
Cancel
Save