From be0238a61ec03706df95f4f6a3dda2c9fb68aad9 Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Mon, 15 Apr 2013 20:51:40 +0400 Subject: [PATCH] Loading SAM adapters with wildcard types. --- .../lang/resolve/java/sam/SingleAbstractMethodUtils.java | 3 ++- .../adapter/NonTrivialFunctionType.java | 6 ++++++ .../singleAbstractMethod/adapter/NonTrivialFunctionType.txt | 3 +++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/sam/SingleAbstractMethodUtils.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/sam/SingleAbstractMethodUtils.java index 8ff359cde44..f9eeb2d488a 100644 --- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/sam/SingleAbstractMethodUtils.java +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/sam/SingleAbstractMethodUtils.java @@ -137,7 +137,8 @@ public class SingleAbstractMethodUtils { private static boolean isSamType(@NotNull JetType type) { ClassifierDescriptor classifier = type.getConstructor().getDeclarationDescriptor(); return classifier instanceof ClassDescriptorFromJvmBytecode && - ((ClassDescriptorFromJvmBytecode) classifier).isSamInterface(); + ((ClassDescriptorFromJvmBytecode) classifier).isSamInterface() && + getAbstractMembers(type).size() == 1; // Comparator<*> is not a SAM type, because substituted compare() method doesn't exist } public static boolean isSamAdapterNecessary(@NotNull SimpleFunctionDescriptor fun) { diff --git a/compiler/testData/loadJava/compiledJava/singleAbstractMethod/adapter/NonTrivialFunctionType.java b/compiler/testData/loadJava/compiledJava/singleAbstractMethod/adapter/NonTrivialFunctionType.java index 3f6e84a044e..40d6055b208 100644 --- a/compiler/testData/loadJava/compiledJava/singleAbstractMethod/adapter/NonTrivialFunctionType.java +++ b/compiler/testData/loadJava/compiledJava/singleAbstractMethod/adapter/NonTrivialFunctionType.java @@ -9,4 +9,10 @@ public class NonTrivialFunctionType { public void foo(Comparator comparator) { } + + public void wildcardUnbound(Comparator comparator) { + } + + public void wildcardBound(Comparator comparator) { + } } \ No newline at end of file diff --git a/compiler/testData/loadJava/compiledJava/singleAbstractMethod/adapter/NonTrivialFunctionType.txt b/compiler/testData/loadJava/compiledJava/singleAbstractMethod/adapter/NonTrivialFunctionType.txt index 0e32ea5d021..19dde4aa535 100644 --- a/compiler/testData/loadJava/compiledJava/singleAbstractMethod/adapter/NonTrivialFunctionType.txt +++ b/compiler/testData/loadJava/compiledJava/singleAbstractMethod/adapter/NonTrivialFunctionType.txt @@ -6,4 +6,7 @@ public open class NonTrivialFunctionType : java.lang.Object { public open /*synthesized*/ fun foo(/*0*/ p0 : ((jet.String?, jet.String?) -> jet.Int)?) : jet.Unit public open fun foo(/*0*/ p0 : java.io.FilenameFilter?) : jet.Unit public open fun foo(/*0*/ p0 : java.util.Comparator?) : jet.Unit + public open /*synthesized*/ fun wildcardBound(/*0*/ p0 : ((jet.CharSequence?, jet.CharSequence?) -> jet.Int)?) : jet.Unit + public open fun wildcardBound(/*0*/ p0 : java.util.Comparator?) : jet.Unit + public open fun wildcardUnbound(/*0*/ p0 : java.util.Comparator?) : jet.Unit }