IDEA-64875 "Constant conditions and exceptions" should eliminate false positives by analyzing static final constants

This commit is contained in:
peter
2012-09-07 19:08:42 +02:00
parent aba62f142b
commit d0efe00076
3 changed files with 18 additions and 4 deletions
@@ -74,10 +74,13 @@ public class DfaValueFactory {
DfaValue constValue = getConstFactory().create(variable);
if (constValue != null) return constValue;
if (!(psiSource instanceof PsiField)) {
PsiExpression initializer = variable.getInitializer();
if (initializer instanceof PsiPolyadicExpression && variable.hasModifierProperty(PsiModifier.FINAL)) {
PsiType type = initializer.getType();
PsiExpression initializer = variable.getInitializer();
if (initializer != null && variable.hasModifierProperty(PsiModifier.FINAL)) {
PsiType type = initializer.getType();
if (initializer instanceof PsiNewExpression) {
return getNotNullFactory().create(type);
}
if (initializer instanceof PsiPolyadicExpression) {
if (type != null && type.equalsToText(CommonClassNames.JAVA_LANG_STRING)) {
return getNotNullFactory().create(type);
}
@@ -0,0 +1,10 @@
import org.jetbrains.annotations.*;
class Class1 {
public void f(@Nullable Object o) {
o = o != null ? o : Class2.O;
o.toString();
}
}
class Class2 {
static final Object O = new Object();
}
@@ -74,5 +74,6 @@ public class DataFlowInspectionFixtureTest extends JavaCodeInsightFixtureTestCas
public void testVisitFinallyOnce() throws Throwable { doTest(); }
public void testNotEqualsDoesntImplyNotNullity() throws Throwable { doTest(); }
public void testEqualsEnumConstant() throws Throwable { doTest(); }
public void testEqualsConstant() throws Throwable { doTest(); }
}