mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
NullableStuffInspection: report only property accessors that refer to correctly named fields (IDEA-202754)
This commit is contained in:
+2
-2
@@ -448,7 +448,7 @@ public class NullableStuffInspectionBase extends AbstractBaseJavaLocalInspection
|
||||
final PsiMethod getter = PropertyUtilBase.findPropertyGetter(field.getContainingClass(), propName, isStatic, false);
|
||||
final PsiIdentifier nameIdentifier = getter == null ? null : getter.getNameIdentifier();
|
||||
if (nameIdentifier != null && nameIdentifier.isPhysical()) {
|
||||
if (PropertyUtil.isSimpleGetter(getter)) {
|
||||
if (PropertyUtil.getFieldOfGetter(getter) == field) {
|
||||
AnnotateMethodFix getterAnnoFix = new AnnotateMethodFix(anno, ArrayUtil.toStringArray(annoToRemove));
|
||||
if (REPORT_NOT_ANNOTATED_GETTER) {
|
||||
if (!manager.hasNullability(getter) && !TypeConversionUtil.isPrimitiveAndNotNull(getter.getReturnType())) {
|
||||
@@ -468,7 +468,7 @@ public class NullableStuffInspectionBase extends AbstractBaseJavaLocalInspection
|
||||
|
||||
final PsiClass containingClass = field.getContainingClass();
|
||||
final PsiMethod setter = PropertyUtilBase.findPropertySetter(containingClass, propName, isStatic, false);
|
||||
if (setter != null && setter.isPhysical() && PropertyUtil.isSimpleSetter(setter)) {
|
||||
if (setter != null && setter.isPhysical() && PropertyUtil.getFieldOfSetter(setter) == field) {
|
||||
final PsiParameter[] parameters = setter.getParameterList().getParameters();
|
||||
assert parameters.length == 1 : setter.getText();
|
||||
final PsiParameter parameter = parameters[0];
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
class NotNullGetterTest {
|
||||
|
||||
@NotNull
|
||||
private final Object foo;
|
||||
|
||||
@Nullable
|
||||
private Object bar;
|
||||
|
||||
public NotNullGetterTest(@NotNull Object foo, @Nullable Object bar) {
|
||||
this.foo = foo;
|
||||
this.bar = bar;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Object getFoo() {
|
||||
return foo;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Object getBar() {
|
||||
return foo;
|
||||
}
|
||||
|
||||
void setBar(@NotNull Object bar) {
|
||||
this.bar = bar;
|
||||
}
|
||||
|
||||
void setFoo(@NotNull Object bar) {
|
||||
this.bar = bar;
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -93,7 +93,8 @@ public class NullableStuffInspectionTest extends LightCodeInsightFixtureTestCase
|
||||
|
||||
public void testGetterSetterProblems() { doTest(); }
|
||||
public void testNonTrivialGettersSetters() { doTest(); }
|
||||
|
||||
public void testGetterSetterFieldMismatch() { doTest(); }
|
||||
|
||||
public void testOverriddenMethods() {
|
||||
myInspection.REPORT_ANNOTATION_NOT_PROPAGATED_TO_OVERRIDERS = true;
|
||||
doTest();
|
||||
|
||||
Reference in New Issue
Block a user