mirror of
https://github.com/jlengrand/error-prone-support.git
synced 2026-03-10 08:11:25 +00:00
Introduce NewStringFromCharArray{,SubSequence} Refaster rules (#1012)
Resolves #1001.
This commit is contained in:
committed by
GitHub
parent
1f71ccccf7
commit
b5ace6e044
@@ -162,6 +162,39 @@ final class StringRules {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prefer direct invocation of {@link String#String(char[], int, int)} over the indirection
|
||||
* introduced by alternatives.
|
||||
*/
|
||||
static final class NewStringFromCharArraySubSequence {
|
||||
@BeforeTemplate
|
||||
String before(char[] data, int offset, int count) {
|
||||
return Refaster.anyOf(
|
||||
String.valueOf(data, offset, count), String.copyValueOf(data, offset, count));
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
String after(char[] data, int offset, int count) {
|
||||
return new String(data, offset, count);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prefer direct invocation of {@link String#String(char[])} over the indirection introduced by
|
||||
* alternatives.
|
||||
*/
|
||||
static final class NewStringFromCharArray {
|
||||
@BeforeTemplate
|
||||
String before(char[] data) {
|
||||
return Refaster.anyOf(String.valueOf(data), new String(data, 0, data.length));
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
String after(char[] data) {
|
||||
return new String(data);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prefer direct delegation to {@link String#valueOf(Object)} over the indirection introduced by
|
||||
* {@link Objects#toString(Object)}.
|
||||
|
||||
@@ -73,6 +73,18 @@ final class StringRulesTest implements RefasterRuleCollectionTestCase {
|
||||
return Objects.toString("foo");
|
||||
}
|
||||
|
||||
ImmutableSet<String> testNewStringFromCharArraySubSequence() {
|
||||
return ImmutableSet.of(
|
||||
String.valueOf(new char[] {'f', 'o', 'o'}, 0, 1),
|
||||
String.copyValueOf(new char[] {'b', 'a', 'r'}, 2, 3));
|
||||
}
|
||||
|
||||
ImmutableSet<String> testNewStringFromCharArray() {
|
||||
return ImmutableSet.of(
|
||||
String.valueOf(new char[] {'f', 'o', 'o'}),
|
||||
new String(new char[] {'b', 'a', 'r'}, 0, new char[] {'b', 'a', 'r'}.length));
|
||||
}
|
||||
|
||||
Function<Object, String> testStringValueOfMethodReference() {
|
||||
return Objects::toString;
|
||||
}
|
||||
|
||||
@@ -75,6 +75,16 @@ final class StringRulesTest implements RefasterRuleCollectionTestCase {
|
||||
return String.valueOf("foo");
|
||||
}
|
||||
|
||||
ImmutableSet<String> testNewStringFromCharArraySubSequence() {
|
||||
return ImmutableSet.of(
|
||||
new String(new char[] {'f', 'o', 'o'}, 0, 1), new String(new char[] {'b', 'a', 'r'}, 2, 3));
|
||||
}
|
||||
|
||||
ImmutableSet<String> testNewStringFromCharArray() {
|
||||
return ImmutableSet.of(
|
||||
new String(new char[] {'f', 'o', 'o'}), new String(new char[] {'b', 'a', 'r'}));
|
||||
}
|
||||
|
||||
Function<Object, String> testStringValueOfMethodReference() {
|
||||
return String::valueOf;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user