mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-10-06 06:21:16 +07:00
Java8MapApiInspectionTest: true unit test for getNameCandidate instead of full inspect-and-fix test
This commit is contained in:
+23
-23
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user