mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-04 08:51:02 +07:00
Ref-returning methods are not included into eq-classes, only variable state is tracked for them. Primitive-returning methods are handled like normal variables (their result is considered to be stable) Fixes IDEA-141547 ConstantConditions inspection reports false positive when using non getter method
43 lines
1.1 KiB
Java
43 lines
1.1 KiB
Java
import org.jetbrains.annotations.Contract;
|
|
import org.jetbrains.annotations.NotNull;
|
|
import org.jetbrains.annotations.Nullable;
|
|
|
|
// IDEA-141547
|
|
public class PureNoArgMethodAsVariable {
|
|
|
|
public enum Bar {
|
|
A, B;
|
|
|
|
@Nullable
|
|
@Contract(pure = true)
|
|
public String getGroup() {
|
|
return this == A ? null : "B";
|
|
}
|
|
|
|
@Nullable
|
|
@Contract(pure = true)
|
|
public String group() {
|
|
return this == A ? null : "B";
|
|
}
|
|
}
|
|
|
|
public void foo(Bar bar) {
|
|
if (bar.getGroup() != null && check(bar.getGroup())) { // NO inspection error, OK!
|
|
System.out.print("ok");
|
|
}
|
|
if (bar.group() != null && check(bar.group())) { // Inspection error, NOT OK!
|
|
System.out.print("ok");
|
|
}
|
|
}
|
|
|
|
void testIntValue(Integer x) {
|
|
if(<warning descr="Condition 'x.intValue() > 5 && x.intValue() < 0' is always 'false'">x.intValue() > 5 &&
|
|
<warning descr="Condition 'x.intValue() < 0' is always 'false' when reached">x.intValue() < 0</warning></warning>) {
|
|
System.out.println("impossible");
|
|
}
|
|
}
|
|
|
|
public boolean check(@NotNull String string) {
|
|
return string.length() > 2;
|
|
}
|
|
} |