Java8MapApiInspectionTest: true unit test for getNameCandidate instead of full inspect-and-fix test

This commit is contained in:
Tagir Valeev
2016-12-01 10:38:45 +07:00
parent 6dd5450366
commit cd4f73b277
6 changed files with 38 additions and 115 deletions
@@ -309,6 +309,29 @@ public class Java8MapApiInspection extends BaseJavaBatchLocalInspectionTool {
return new MapCheckCondition(valueReference, mapExpression, keyExpression, fullCondition, negated, containsKey);
}
@NotNull
static String getNameCandidate(String name) {
// Either last uppercase letter (if it's not the last letter) or the first letter, removing leading underscores
// token -> t
// myAccessToken -> t
// SQL -> s
// __name -> n
// __1 -> k
String nameCandidate;
name = name.replaceFirst("^[_\\d]+", "");
if (name.isEmpty()) return "k";
nameCandidate = name.substring(0, 1);
for (int pos = name.length() - 1; pos > 0; pos--) {
if (Character.isUpperCase(name.charAt(pos))) {
if (pos != name.length() - 1) {
nameCandidate = name.substring(pos, pos + 1);
}
break;
}
}
return nameCandidate.toLowerCase(Locale.ENGLISH);
}
private static class ReplaceWithSingleMapOperation implements LocalQuickFix {
private final String myMethodName;
private final SmartPsiElementPointer<PsiMethodCallExpression> myCallPointer;
@@ -411,29 +434,6 @@ public class Java8MapApiInspection extends BaseJavaBatchLocalInspectionTool {
}
CodeStyleManager.getInstance(project).reformat(result);
}
@NotNull
private static String getNameCandidate(String name) {
// Either last uppercase letter (if it's not the last letter) or the first letter, removing leading underscores
// token -> t
// myAccessToken -> t
// SQL -> s
// __name -> n
// __1 -> k
String nameCandidate;
name = name.replaceFirst("^[_\\d]+", "");
if (name.isEmpty()) return "k";
nameCandidate = name.substring(0, 1);
for (int pos = name.length() - 1; pos > 0; pos--) {
if (Character.isUpperCase(name.charAt(pos))) {
if (pos != name.length() - 1) {
nameCandidate = name.substring(pos, pos + 1);
}
break;
}
}
return nameCandidate.toLowerCase(Locale.ENGLISH);
}
}
class MapCheckCondition {