Use StringBuilder to concatenate strings. #1555

Fixes `StringReplaceableByStringBuffer` inspection violations.

Description:
Reports any variables declared as java.lang.String which are repeatedly appended to. Such variables may be more efficiently declared as java.lang.StringBuffer or java.lang.StringBuilder.
This commit is contained in:
Michal Kordas 2015-08-07 23:44:25 +02:00 committed by Roman Ivanov
parent b550547318
commit bf6735ce4b
1 changed files with 3 additions and 2 deletions

View File

@ -233,6 +233,7 @@ public class ImportOrderCheck
for (int i = 0; i < packageGroups.length; i++) {
String pkg = packageGroups[i];
final StringBuilder pkgBuilder = new StringBuilder(pkg);
Pattern grp;
// if the pkg name is the wildcard, make it match zero chars
@ -249,9 +250,9 @@ public class ImportOrderCheck
}
else {
if (!Utils.endsWithChar(pkg, '.')) {
pkg += ".";
pkgBuilder.append('.');
}
grp = Pattern.compile("^" + Pattern.quote(pkg));
grp = Pattern.compile("^" + Pattern.quote(pkgBuilder.toString()));
}
groups[i] = grp;