applyGetClassRelation: minor simplification; test for new object (IDEA-CR-50564)

GitOrigin-RevId: 439a327d7276a0d28e3ebc41f01646a828305022
This commit is contained in:
Tagir Valeev
2019-07-24 06:52:25 +03:00
committed by intellij-monorepo-bot
parent e77596602d
commit f9be4584e5
2 changed files with 10 additions and 8 deletions
@@ -1124,15 +1124,12 @@ public class DfaMemoryStateImpl implements DfaMemoryState {
DfaPsiType dfaType = myFactory.createDfaType(value);
TypeConstraint constraint = TypeConstraint.exact(dfaType);
PsiClass psiClass = PsiUtil.resolveClassInClassTypeOnly(value);
if (!negated) {
if (psiClass != null && (psiClass.isInterface() || psiClass.hasModifierProperty(PsiModifier.ABSTRACT))) {
// getClass() result cannot be an interface or an abstract class
return ThreeState.NO;
}
return ThreeState.fromBoolean(applyFact(qualifier, DfaFactType.TYPE_CONSTRAINT, constraint));
}
if (psiClass != null && (psiClass.isInterface() || psiClass.hasModifierProperty(PsiModifier.ABSTRACT))) {
return ThreeState.YES;
// getClass() result cannot be an interface or an abstract class
return ThreeState.fromBoolean(negated);
}
if (!negated) {
return ThreeState.fromBoolean(applyFact(qualifier, DfaFactType.TYPE_CONSTRAINT, constraint));
}
TypeConstraint existingConstraint = getValueFact(qualifier, DfaFactType.TYPE_CONSTRAINT);
if (existingConstraint != null && existingConstraint.isExact()) {
@@ -20,6 +20,11 @@ class GetClass {
}
void testNew() {
Object x = new HashSet();
if (<warning descr="Condition 'x.getClass() == HashSet.class' is always 'true'">x.getClass() == HashSet.class</warning>) {}
}
void testInstanceOfInterop(Object obj) {
if (obj instanceof CharSequence) {
if (<warning descr="Condition 'obj.getClass() == Integer.class' is always 'false'">obj.getClass() == Integer.class</warning>) {}