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



public void writeConfigFile(String filePath, List<BuildConfigNode> files, List<BuildConfigNode> importedNodes) { public void writeConfigFile(String filePath, List<BuildConfigNode> files, List<BuildConfigNode> importedNodes) {
// Set contentsSet = new TreeSet(fileContents); // Set contentsSet = new TreeSet(fileContents);
String fileContentsString = "";
StringBuilder fileContentsString = new StringBuilder();
// List filesToWrite = null; // List filesToWrite = null;
Set<String> includedFiles = new HashSet<>(); Set<String> includedFiles = new HashSet<>();
for (BuildConfigNode node : importedNodes) { for (BuildConfigNode node : importedNodes) {
fileContentsString += '@' + node.getResourcePath() + "\n";
fileContentsString.append('@').append(node.getResourcePath()).append("\n");
String parentPath = new File(filePath).getParent(); String parentPath = new File(filePath).getParent();
String importedFilePath = parentPath + File.separator + node.getResourcePath(); String importedFilePath = parentPath + File.separator + node.getResourcePath();
includedFiles.addAll(getIncludedFiles(importedFilePath, parentPath)); includedFiles.addAll(getIncludedFiles(importedFilePath, parentPath));


for (BuildConfigNode node : files) { for (BuildConfigNode node : files) {
if (node.getName().endsWith(".lst") && !node.getResourcePath().startsWith("..")) { if (node.getName().endsWith(".lst") && !node.getResourcePath().startsWith("..")) {
fileContentsString += '@';
fileContentsString += node.getResourcePath() + "\n";
fileContentsString.append('@');
fileContentsString.append(node.getResourcePath()).append("\n");
} else { } else {
if (!includedFiles.contains(node.getResourcePath())) { 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) { private List<String> getIncludedFiles(String path, String rootPath) {

+ 3
- 3
ajde/src/main/java/org/aspectj/ajde/ui/internal/UserPreferencesStore.java View File



@Override @Override
public void setProjectMultivalPreference(String name, List values) { public void setProjectMultivalPreference(String name, List values) {
String valuesString = "";
StringBuilder valuesString = new StringBuilder();
for (Object value : values) { for (Object value : values) {
valuesString += (String) value + ';';
valuesString.append((String)value).append(';');
} }
properties.setProperty(name, valuesString);
properties.setProperty(name, valuesString.toString());
saveProperties(); saveProperties();
} }



+ 29
- 24
ajdoc/src/main/java/org/aspectj/tools/ajdoc/HtmlDecorator.java View File

static void decorateDocWithRel(IProgramElement node, StringBuilder fileContentsBuffer, int index, List targets, static void decorateDocWithRel(IProgramElement node, StringBuilder fileContentsBuffer, int index, List targets,
HtmlRelationshipKind relKind) { HtmlRelationshipKind relKind) {
if (targets != null && !targets.isEmpty()) { 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); String relativePackagePath = getRelativePathFromHere(node.getPackageName().replace('.', '/') + Config.DIR_SEP_CHAR);


hrefLink += sbuff.toString() + ".html" + "#" + sb.toString(); hrefLink += sbuff.toString() + ".html" + "#" + sb.toString();


if (!addedNames.contains(hrefName)) { 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()) if (it.hasNext())
adviceDoc += ", ";
adviceDoc.append(", ");
addedNames.add(hrefName); addedNames.add(hrefName);
} }
} }
adviceDoc += "</TR></TD></TABLE>\n";
fileContentsBuffer.insert(index, adviceDoc);
adviceDoc.append("</TR></TD></TABLE>\n");
fileContentsBuffer.insert(index, adviceDoc.toString());
} }
} }


} }
if (targets == null) if (targets == null)
return ""; return "";
String entry = "<TABLE WIDTH=\"100%\" BGCOLOR=#FFFFFF><TR>";
StringBuilder entry = new StringBuilder("<TABLE WIDTH=\"100%\" BGCOLOR=#FFFFFF><TR>");


IProgramElement.Kind kind = decl.getKind(); IProgramElement.Kind kind = decl.getKind();
if (kind.equals(IProgramElement.Kind.ADVICE)) { 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)) { } 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()) { } 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)) { } 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 { } 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); String relativePackagePath = getRelativePathFromHere(decl.getPackageName().replace('.', '/') + Config.DIR_SEP_CHAR);
} }


if (!addedNames.contains(hrefName)) { 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()) if (it.hasNext())
entry += ", ";
entry.append(", ");
addedNames.add(hrefName); 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();
} }


/** /**
if (comment == null) if (comment == null)
return ""; return "";


String formattedComment = "";
StringBuilder formattedComment = new StringBuilder();
// strip the comment markers // strip the comment markers


int startIndex = comment.indexOf("/**"); int startIndex = comment.indexOf("/**");
// if ( linkIndex != -1 ) { // if ( linkIndex != -1 ) {
// line = line.substring(0, linkIndex) + line.substring(linkIndex); // line = line.substring(0, linkIndex) + line.substring(linkIndex);
// } // }
formattedComment += line;
formattedComment.append(line);
} }
} catch (IOException ioe) { } catch (IOException ioe) {
throw new Error("Couldn't format comment for declaration: " + decl.getName()); throw new Error("Couldn't format comment for declaration: " + decl.getName());
} }
return formattedComment;
return formattedComment.toString();
} }


static public IProgramElement[] getProgramElements(AsmManager model, String filename) { 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

import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.StringJoiner;


import org.aspectj.ajdt.internal.compiler.ast.AdviceDeclaration; import org.aspectj.ajdt.internal.compiler.ast.AdviceDeclaration;
import org.aspectj.ajdt.internal.compiler.ast.DeclareDeclaration; import org.aspectj.ajdt.internal.compiler.ast.DeclareDeclaration;
} }


private String genPrecedenceListLabel(TypePatternList list) { private String genPrecedenceListLabel(TypePatternList list) {
String tpList = "";
StringJoiner tpList = new StringJoiner(", ");
for (int i = 0; i < list.size(); i++) { 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) { // private String genArguments(MethodDeclaration md) {

+ 5
- 6
taskdefs/src/main/java/org/aspectj/tools/ant/taskdefs/Ajdoc.java View File

import java.util.Collections; import java.util.Collections;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.StringJoiner;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import java.util.Vector; import java.util.Vector;


} }
for (String title: groupMap.keySet()) { for (String title: groupMap.keySet()) {
List<String> packages = groupMap.get(title); 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("-group");
cmd.createArgument().setValue(title); cmd.createArgument().setValue(title);
cmd.createArgument().setValue(pkgstr);
cmd.createArgument().setValue(pkgstr.toString());
} }
if (argfiles != null) { if (argfiles != null) {
for (File file : argfiles) { for (File file : argfiles) {

Loading…
Cancel
Save