Use StringJoiner where possible to simplify String joining
This commit is contained in:
committed by
Juergen Hoeller
parent
e44d3dabc4
commit
5e29ea30a3
@@ -24,6 +24,8 @@ import org.springframework.expression.spel.ExpressionState;
|
||||
import org.springframework.expression.spel.SpelEvaluationException;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
import java.util.StringJoiner;
|
||||
|
||||
/**
|
||||
* Represents a DOT separated expression sequence, such as
|
||||
* {@code 'property1.property2.methodOne()'}.
|
||||
@@ -104,14 +106,11 @@ public class CompoundExpression extends SpelNodeImpl {
|
||||
|
||||
@Override
|
||||
public String toStringAST() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
StringJoiner sj = new StringJoiner(".");
|
||||
for (int i = 0; i < getChildCount(); i++) {
|
||||
if (i > 0) {
|
||||
sb.append(".");
|
||||
}
|
||||
sb.append(getChild(i).toStringAST());
|
||||
sj.add(getChild(i).toStringAST());
|
||||
}
|
||||
return sb.toString();
|
||||
return sj.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.springframework.expression.spel.ast;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.StringJoiner;
|
||||
|
||||
import org.springframework.core.convert.TypeDescriptor;
|
||||
import org.springframework.lang.Nullable;
|
||||
@@ -36,22 +37,16 @@ abstract class FormatHelper {
|
||||
* @return a nicely formatted representation, e.g. {@code foo(String,int)}
|
||||
*/
|
||||
public static String formatMethodForMessage(String name, List<TypeDescriptor> argumentTypes) {
|
||||
StringBuilder sb = new StringBuilder(name);
|
||||
sb.append("(");
|
||||
for (int i = 0; i < argumentTypes.size(); i++) {
|
||||
if (i > 0) {
|
||||
sb.append(",");
|
||||
}
|
||||
TypeDescriptor typeDescriptor = argumentTypes.get(i);
|
||||
StringJoiner sj = new StringJoiner(",", "(", ")");
|
||||
for (TypeDescriptor typeDescriptor : argumentTypes) {
|
||||
if (typeDescriptor != null) {
|
||||
sb.append(formatClassNameForMessage(typeDescriptor.getType()));
|
||||
sj.add(formatClassNameForMessage(typeDescriptor.getType()));
|
||||
}
|
||||
else {
|
||||
sb.append(formatClassNameForMessage(null));
|
||||
sj.add(formatClassNameForMessage(null));
|
||||
}
|
||||
}
|
||||
sb.append(")");
|
||||
return sb.toString();
|
||||
return name + sj.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.springframework.expression.spel.ast;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.StringJoiner;
|
||||
|
||||
import org.springframework.asm.MethodVisitor;
|
||||
import org.springframework.core.MethodParameter;
|
||||
@@ -139,16 +140,11 @@ public class FunctionReference extends SpelNodeImpl {
|
||||
|
||||
@Override
|
||||
public String toStringAST() {
|
||||
StringBuilder sb = new StringBuilder("#").append(this.name);
|
||||
sb.append("(");
|
||||
StringJoiner sj = new StringJoiner(",", "(", ")");
|
||||
for (int i = 0; i < getChildCount(); i++) {
|
||||
if (i > 0) {
|
||||
sb.append(",");
|
||||
}
|
||||
sb.append(getChild(i).toStringAST());
|
||||
sj.add(getChild(i).toStringAST());
|
||||
}
|
||||
sb.append(")");
|
||||
return sb.toString();
|
||||
return '#' + this.name + sj.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -24,6 +24,7 @@ import java.lang.reflect.Modifier;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.StringJoiner;
|
||||
|
||||
import org.springframework.asm.MethodVisitor;
|
||||
import org.springframework.core.convert.TypeDescriptor;
|
||||
@@ -320,15 +321,11 @@ public class Indexer extends SpelNodeImpl {
|
||||
|
||||
@Override
|
||||
public String toStringAST() {
|
||||
StringBuilder sb = new StringBuilder("[");
|
||||
StringJoiner sj = new StringJoiner(",", "[", "]");
|
||||
for (int i = 0; i < getChildCount(); i++) {
|
||||
if (i > 0) {
|
||||
sb.append(",");
|
||||
}
|
||||
sb.append(getChild(i).toStringAST());
|
||||
sj.add(getChild(i).toStringAST());
|
||||
}
|
||||
sb.append("]");
|
||||
return sb.toString();
|
||||
return sj.toString();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ import java.lang.reflect.Proxy;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.StringJoiner;
|
||||
|
||||
import org.springframework.asm.Label;
|
||||
import org.springframework.asm.MethodVisitor;
|
||||
@@ -259,16 +260,11 @@ public class MethodReference extends SpelNodeImpl {
|
||||
|
||||
@Override
|
||||
public String toStringAST() {
|
||||
StringBuilder sb = new StringBuilder(this.name);
|
||||
sb.append("(");
|
||||
StringJoiner sj = new StringJoiner(",", "(", ")");
|
||||
for (int i = 0; i < getChildCount(); i++) {
|
||||
if (i > 0) {
|
||||
sb.append(",");
|
||||
}
|
||||
sb.append(getChild(i).toStringAST());
|
||||
sj.add(getChild(i).toStringAST());
|
||||
}
|
||||
sb.append(")");
|
||||
return sb.toString();
|
||||
return this.name + sj.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user