From 6311bb2b020515b12b4cd92b9d9838a0b53da456 Mon Sep 17 00:00:00 2001 From: Andrey Vlasovskikh Date: Tue, 17 Feb 2015 19:07:23 +0300 Subject: [PATCH] Prevent exponential growth of union types of PyJavaClassType (PY-15055) For Java method references in the context of Jython multi-resolve returns all the overloaded methods. Return types of these methods are joined as a union type. If there is no equality for PyJavaClassType, then the chain of builder-style calls to overloaded methods results in exponential growth of the union type. --- .../python/psi/impl/PyJavaClassType.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/python/pluginSrc/com/jetbrains/python/psi/impl/PyJavaClassType.java b/python/pluginSrc/com/jetbrains/python/psi/impl/PyJavaClassType.java index f7252658b53a..bd0f820b34fd 100644 --- a/python/pluginSrc/com/jetbrains/python/psi/impl/PyJavaClassType.java +++ b/python/pluginSrc/com/jetbrains/python/psi/impl/PyJavaClassType.java @@ -163,4 +163,24 @@ public class PyJavaClassType implements PyClassLikeType { public PsiClass getPsiClass() { return myClass; } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof PyJavaClassType)) return false; + + PyJavaClassType type = (PyJavaClassType)o; + + if (myDefinition != type.myDefinition) return false; + if (myClass != null ? !myClass.equals(type.myClass) : type.myClass != null) return false; + + return true; + } + + @Override + public int hashCode() { + int result = myClass != null ? myClass.hashCode() : 0; + result = 31 * result + (myDefinition ? 1 : 0); + return result; + } }