IDEA-144519 (SuspiciousGetterSetter inspection should be less strict when returning static final field)

This commit is contained in:
Bas Leijdekkers
2015-08-31 14:57:02 +02:00
parent f1c14f15b2
commit 389b36e185
2 changed files with 13 additions and 4 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -105,8 +105,10 @@ public class SuspiciousGetterSetterInspection extends BaseInspection {
return;
}
final JavaCodeStyleManager codeStyleManager = JavaCodeStyleManager.getInstance(method.getProject());
final String computedFieldName = codeStyleManager.propertyNameToVariableName(decapitalize(extractedFieldName), VariableKind.FIELD);
if (fieldName.equalsIgnoreCase(computedFieldName)) {
final String decapitalized = decapitalize(extractedFieldName);
final String computedFieldName = codeStyleManager.propertyNameToVariableName(decapitalized, VariableKind.FIELD);
final String computedStaticFieldName = codeStyleManager.propertyNameToVariableName(decapitalized, VariableKind.STATIC_FINAL_FIELD);
if (fieldName.equals(computedFieldName) || fieldName.equals(computedStaticFieldName)) {
return;
}
if (onlyWarnWhenFieldPresent) {
@@ -114,7 +116,8 @@ public class SuspiciousGetterSetterInspection extends BaseInspection {
if (aClass == null) {
return;
}
if (aClass.findFieldByName(computedFieldName, true) == null) {
if (aClass.findFieldByName(computedFieldName, true) == null &&
aClass.findFieldByName(computedStaticFieldName, true) == null) {
return;
}
}
@@ -3,6 +3,8 @@ public class SuspiciousGetterSetter {
private String myOne;
private String myTwo;
private static final String MSG_KEY = "";
public String <warning descr="Getter 'getTwo()' returns field 'myOne'">getTwo</warning>() {
return myOne;
}
@@ -10,4 +12,8 @@ public class SuspiciousGetterSetter {
public void <warning descr="Setter 'setTwo()' assigns field 'myOne'">setTwo</warning>(String two) {
myOne = two;
}
String getMsgKey() { // suspicious getter
return MSG_KEY;
}
}