Skip to content

Commit ff02145

Browse files
committed
Optional additional performance improvement
1 parent b401790 commit ff02145

File tree

5 files changed

+6
-4
lines changed

5 files changed

+6
-4
lines changed

check_api/src/main/java/com/google/errorprone/VisitorState.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,7 @@ private static final class SharedState {
771771
* Like {@link Elements#getConstantExpression}, but doesn't over-escape single quotes in strings.
772772
*/
773773
public String getConstantExpression(Object value) {
774-
if (!(value instanceof String str)) {
774+
if (!(value instanceof CharSequence str)) {
775775
return getElements().getConstantExpression(value);
776776
}
777777

core/src/main/java/com/google/errorprone/bugpatterns/RobolectricShadowDirectlyOn.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState
7373
MethodSymbol symbol = getSymbol(parent);
7474
String argReplacement =
7575
Streams.concat(
76-
Stream.of(state.getConstantExpression(symbol.getSimpleName().toString())),
76+
Stream.of(state.getConstantExpression(symbol.getSimpleName())),
7777
Streams.zip(
7878
symbol.getParameters().stream(),
7979
parent.getArguments().stream(),

core/src/main/java/com/google/errorprone/bugpatterns/flogger/FloggerArgumentToString.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ Description unwrapArguments(
351351
if (!fixed) {
352352
return NO_MATCH;
353353
}
354-
fix.replace(tree.getArguments().get(0), state.getConstantExpression(sb.toString()));
354+
fix.replace(tree.getArguments().get(0), state.getConstantExpression(sb));
355355
return describeMatch(tree, fix.build());
356356
}
357357

core/src/main/java/com/google/errorprone/bugpatterns/flogger/FloggerStringConcatenation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ protected Void defaultAction(Tree tree, Void unused) {
112112
tree,
113113
SuggestedFix.replace(
114114
argument,
115-
state.getConstantExpression(formatString.toString())
115+
state.getConstantExpression(formatString)
116116
+ ", "
117117
+ formatArguments.stream().map(state::getSourceForNode).collect(joining(", "))));
118118
}

core/src/test/java/com/google/errorprone/VisitorStateTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ public void getConstantExpression() {
106106
assertThat(visitorState.getConstantExpression("hello \n world"))
107107
.isEqualTo("\"hello \\n world\"");
108108
assertThat(visitorState.getConstantExpression('\'')).isEqualTo("'\\''");
109+
assertThat(visitorState.getConstantExpression(new StringBuilder("hello ' world")))
110+
.isEqualTo("\"hello ' world\"");
109111
}
110112

111113
// The following is taken from ErrorProneJavacPluginTest. There may be an easier way.

0 commit comments

Comments
 (0)