IDEA-188088 Suspicious parameter/name combination does not work for camelCaseWords

This commit is contained in:
Tagir Valeev
2018-03-13 15:26:49 +07:00
parent e0fe481d65
commit 5a52307e5a
3 changed files with 27 additions and 11 deletions
@@ -61,7 +61,7 @@ public class SuspiciousNameCombinationInspectionBase extends AbstractBaseJavaLoc
myWordToGroupMap.clear();
}
protected void addNameGroup(@NonNls final String group) {
public void addNameGroup(@NonNls final String group) {
myNameGroups.add(group);
List<String> words = StringUtil.split(group, ",");
for(String word: words) {
@@ -197,15 +197,19 @@ public class SuspiciousNameCombinationInspectionBase extends AbstractBaseJavaLoc
}
String[] words = NameUtil.splitNameIntoWords(name);
String result = null;
for(String word: words) {
String group = myWordToGroupMap.get(canonicalize(word));
if (group != null) {
if (result == null) {
result = group;
}
else if (!result.equals(group)) {
result = null;
break;
for (int i = 0; i < words.length; i++) {
String word = "";
for (int j = i; j < words.length; j++) {
word += words[j];
String group = myWordToGroupMap.get(canonicalize(word));
if (group != null) {
if (result == null) {
result = group;
}
else if (!result.equals(group)) {
result = null;
break;
}
}
}
}
@@ -0,0 +1,9 @@
public class TwoWords {
public void test() {
int someWord = 0, theOtherWord = 1, someWord123 = 2;
int <warning descr="'someWord' should probably not be assigned to 'x'">x</warning> = someWord;
int <warning descr="'theOtherWord' should probably not be assigned to 'y'">y</warning> = theOtherWord;
someWord123 = someWord;
theOtherWord = someWord;
}
}
@@ -34,7 +34,9 @@ public class SuspiciousNameCombinationTest extends LightInspectionTestCase {
@Nullable
@Override
protected InspectionProfileEntry getInspection() {
return new SuspiciousNameCombinationInspection();
SuspiciousNameCombinationInspection inspection = new SuspiciousNameCombinationInspection();
inspection.addNameGroup("someWord,otherWord");
return inspection;
}
public void testAssignment() { doTest();}
@@ -42,4 +44,5 @@ public class SuspiciousNameCombinationTest extends LightInspectionTestCase {
public void testParameter() { doTest();}
public void testReturnValue() { doTest();}
public void testExcluded() { doTest();}
public void testTwoWords() { doTest();}
}