From 62d211a2fdac36cc452dde76892ef5fe5b14cce4 Mon Sep 17 00:00:00 2001 From: Daniil Ovchinnikov Date: Tue, 22 Jan 2019 19:46:19 +0300 Subject: [PATCH] [groovy] inference: get rid of Mixin.ID It didn't work anyway. ID is identity hashcode. Given two DfaType-s from two branches of, for example, instanceof expression, there were two InstanceofInstruction-s, which created two Mixin instances with different IDs, and then they were never merged. --- .../groovy/lang/psi/dataFlow/DFAType.java | 42 ++++++++++++------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/dataFlow/DFAType.java b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/dataFlow/DFAType.java index f5689b745652..37ed3ead13bf 100644 --- a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/dataFlow/DFAType.java +++ b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/dataFlow/DFAType.java @@ -13,47 +13,57 @@ import org.jetbrains.plugins.groovy.lang.psi.controlFlow.NegatingGotoInstruction import org.jetbrains.plugins.groovy.lang.psi.controlFlow.impl.ConditionInstruction; import org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.TypesUtil; -import java.util.ArrayList; -import java.util.List; -import java.util.ListIterator; -import java.util.Set; +import java.util.*; /** * @author Max Medvedev */ public class DFAType { + private static class Mixin { - private final int ID; private final @NotNull PsiType myType; private final @Nullable ConditionInstruction myCondition; private final boolean myNegated; private Mixin(@NotNull PsiType type, @Nullable ConditionInstruction condition, boolean negated) { - this(-1, type, condition, negated); - } - - private Mixin(int ID, @NotNull PsiType type, @Nullable ConditionInstruction condition, boolean negated) { - if (ID == -1) ID = hashCode(); - this.ID = ID; myType = type; myCondition = condition; myNegated = negated; } private Mixin negate() { - return new Mixin(ID, myType, myCondition, !myNegated); + return new Mixin(myType, myCondition, !myNegated); } @Override public String toString() { return "Mixin{" + - "ID=" + ID + - ", myType=" + myType + + "myType=" + myType + ", myCondition=" + myCondition + ", myNegated=" + myNegated + '}'; } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + Mixin mixin = (Mixin)o; + + if (!myType.equals(mixin.myType)) return false; + if (!Objects.equals(myCondition, mixin.myCondition)) return false; + + return true; + } + + @Override + public int hashCode() { + int result = myType.hashCode(); + result = 31 * result + (myCondition != null ? myCondition.hashCode() : 0); + return result; + } } private final PsiType primary; @@ -85,7 +95,7 @@ public class DFAType { for (Mixin mixin1 : mixins) { boolean contains = false; for (Mixin mixin2 : other.mixins) { - if (mixin1.ID == mixin2.ID) { + if (mixin1.equals(mixin2)) { contains = mixin1.myNegated == mixin2.myNegated; break; } @@ -154,7 +164,7 @@ public class DFAType { for (Mixin mixin1 : t1.mixins) { for (Mixin mixin2 : t2.mixins) { - if (mixin1.ID == mixin2.ID && mixin1.myNegated == mixin2.myNegated) { + if (mixin1.equals(mixin2) && mixin1.myNegated == mixin2.myNegated) { type.mixins.add(mixin1); } }