diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/provider/MembersCache.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/provider/MembersCache.java index 51b7b559c11..f74b5d21538 100644 --- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/provider/MembersCache.java +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/provider/MembersCache.java @@ -16,7 +16,9 @@ package org.jetbrains.jet.lang.resolve.java.provider; +import com.google.common.collect.ImmutableSet; import com.intellij.psi.*; +import com.intellij.psi.util.PsiFormatUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.lang.resolve.java.*; @@ -31,7 +33,11 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import static com.intellij.psi.util.PsiFormatUtilBase.*; + public final class MembersCache { + private static final ImmutableSet OBJECT_METHODS = ImmutableSet.of("hashCode()", "equals(java.lang.Object)", "toString()"); + @NotNull private final Map namedMembersMap = new HashMap(); @@ -147,6 +153,10 @@ public final class MembersCache { return false; } + if (isObjectMethodInInterface(member.getPsiMember())) { + return false; + } + return true; } @@ -291,4 +301,20 @@ public final class MembersCache { getOrCreateEmpty(identifier); } } + + private static boolean isObjectMethodInInterface(@NotNull PsiMember member) { + if (!(member instanceof PsiMethod)) { + return false; + } + PsiClass containingClass = member.getContainingClass(); + assert containingClass != null : "containing class is null for " + member; + + if (!containingClass.isInterface()) { + return false; + } + + String formattedMethod = PsiFormatUtil.formatMethod( + (PsiMethod) member, PsiSubstitutor.EMPTY, SHOW_NAME | SHOW_PARAMETERS, SHOW_TYPE | SHOW_FQ_CLASS_NAMES); + return OBJECT_METHODS.contains(formattedMethod); + } } diff --git a/compiler/testData/loadJava/compiledJava/singleAbstractMethod/InterfaceWithObjectMethod.java b/compiler/testData/loadJava/compiledJava/singleAbstractMethod/InterfaceWithObjectMethod.java new file mode 100644 index 00000000000..57bdf6131e3 --- /dev/null +++ b/compiler/testData/loadJava/compiledJava/singleAbstractMethod/InterfaceWithObjectMethod.java @@ -0,0 +1,5 @@ +package test; + +public interface InterfaceWithObjectMethod { + String toString(); +} diff --git a/compiler/testData/loadJava/compiledJava/singleAbstractMethod/InterfaceWithObjectMethod.txt b/compiler/testData/loadJava/compiledJava/singleAbstractMethod/InterfaceWithObjectMethod.txt new file mode 100644 index 00000000000..540ccd08d20 --- /dev/null +++ b/compiler/testData/loadJava/compiledJava/singleAbstractMethod/InterfaceWithObjectMethod.txt @@ -0,0 +1,4 @@ +package test + +public trait InterfaceWithObjectMethod : java.lang.Object { +} diff --git a/compiler/tests/org/jetbrains/jet/jvm/compiler/LoadJavaTestGenerated.java b/compiler/tests/org/jetbrains/jet/jvm/compiler/LoadJavaTestGenerated.java index f7703f0c080..2eb50924b61 100644 --- a/compiler/tests/org/jetbrains/jet/jvm/compiler/LoadJavaTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/jvm/compiler/LoadJavaTestGenerated.java @@ -1135,6 +1135,11 @@ public class LoadJavaTestGenerated extends AbstractLoadJavaTest { doTestCompiledJava("compiler/testData/loadJava/compiledJava/singleAbstractMethod/FilenameFilter.java"); } + @TestMetadata("InterfaceWithObjectMethod.java") + public void testInterfaceWithObjectMethod() throws Exception { + doTestCompiledJava("compiler/testData/loadJava/compiledJava/singleAbstractMethod/InterfaceWithObjectMethod.java"); + } + @TestMetadata("Runnable.java") public void testRunnable() throws Exception { doTestCompiledJava("compiler/testData/loadJava/compiledJava/singleAbstractMethod/Runnable.java");