diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/resolver/JavaFunctionResolver.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/resolver/JavaFunctionResolver.java index f04277d464c..34180186270 100644 --- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/resolver/JavaFunctionResolver.java +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/resolver/JavaFunctionResolver.java @@ -361,6 +361,7 @@ public final class JavaFunctionResolver { SimpleFunctionDescriptor constructorFunction = SingleAbstractMethodUtils.createSamConstructorFunction(ownerDescriptor, klass); trace.record(BindingContext.SAM_CONSTRUCTOR_TO_INTERFACE, constructorFunction, klass); + trace.record(BindingContext.SOURCE_DESCRIPTOR_FOR_SYNTHESIZED, constructorFunction, klass); return constructorFunction; } } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/BindingContext.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/BindingContext.java index 4aa98e3fb5b..1f821036d34 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/BindingContext.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/BindingContext.java @@ -256,6 +256,7 @@ public interface BindingContext { WritableSlice IS_DECLARED_IN_JAVA = Slices.createSimpleSlice(); WritableSlice SAM_CONSTRUCTOR_TO_INTERFACE = Slices.createSimpleSlice(); + WritableSlice SOURCE_DESCRIPTOR_FOR_SYNTHESIZED = Slices.createSimpleSlice(); @SuppressWarnings("UnusedDeclaration") @Deprecated // This field is needed only for the side effects of its initializer diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/BindingContextUtils.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/BindingContextUtils.java index c70e27d8ac4..9ed613a5664 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/BindingContextUtils.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/BindingContextUtils.java @@ -177,7 +177,8 @@ public class BindingContextUtils { @Nullable public static PsiElement callableDescriptorToDeclaration(@NotNull BindingContext context, @NotNull CallableMemberDescriptor callable) { if (callable.getKind() == CallableMemberDescriptor.Kind.SYNTHESIZED) { - return null; + DeclarationDescriptor source = context.get(BindingContext.SOURCE_DESCRIPTOR_FOR_SYNTHESIZED, callable); + return source != null ? descriptorToDeclaration(context, source) : null; } if (callable.getKind() == CallableMemberDescriptor.Kind.DECLARATION) { @@ -196,7 +197,8 @@ public class BindingContextUtils { @NotNull private static List callableDescriptorToDeclarations(@NotNull BindingContext context, @NotNull CallableMemberDescriptor callable) { if (callable.getKind() == CallableMemberDescriptor.Kind.SYNTHESIZED) { - return Collections.emptyList(); + DeclarationDescriptor source = context.get(BindingContext.SOURCE_DESCRIPTOR_FOR_SYNTHESIZED, callable); + return source != null ? descriptorToDeclarations(context, source) : Collections.emptyList(); } if (callable.getKind() == CallableMemberDescriptor.Kind.DECLARATION) { diff --git a/idea/testData/editor/optimizeImports/SamConstructor.kt b/idea/testData/editor/optimizeImports/SamConstructor.kt new file mode 100644 index 00000000000..4a5253f9406 --- /dev/null +++ b/idea/testData/editor/optimizeImports/SamConstructor.kt @@ -0,0 +1,3 @@ +import java.util.* + +val c = Comparator {(x: Int, y: Int) -> 1} diff --git a/idea/testData/editor/optimizeImports/SamConstructor_after.kt b/idea/testData/editor/optimizeImports/SamConstructor_after.kt new file mode 100644 index 00000000000..4a5253f9406 --- /dev/null +++ b/idea/testData/editor/optimizeImports/SamConstructor_after.kt @@ -0,0 +1,3 @@ +import java.util.* + +val c = Comparator {(x: Int, y: Int) -> 1} diff --git a/idea/testData/resolve/SamConstructor.kt b/idea/testData/resolve/SamConstructor.kt new file mode 100644 index 00000000000..f3690a75b1d --- /dev/null +++ b/idea/testData/resolve/SamConstructor.kt @@ -0,0 +1 @@ +val c = java.util.Comparator {(x: Int, y: Int) -> 1} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/jet/plugin/importOptimizer/OptimizeImportsTest.java b/idea/tests/org/jetbrains/jet/plugin/importOptimizer/OptimizeImportsTest.java index 7824311e972..3ee8ca7396e 100644 --- a/idea/tests/org/jetbrains/jet/plugin/importOptimizer/OptimizeImportsTest.java +++ b/idea/tests/org/jetbrains/jet/plugin/importOptimizer/OptimizeImportsTest.java @@ -81,6 +81,10 @@ public class OptimizeImportsTest extends LightCodeInsightTestCase { doTest(); } + public void testSamConstructor() throws Exception { + doTest(); + } + public void doTest() throws Exception { configureByFile(fileName()); invokeFormatFile(); diff --git a/idea/tests/org/jetbrains/jet/resolve/ResolveBaseTest.java b/idea/tests/org/jetbrains/jet/resolve/ResolveBaseTest.java index 7bd49c9d651..eb3b855717a 100644 --- a/idea/tests/org/jetbrains/jet/resolve/ResolveBaseTest.java +++ b/idea/tests/org/jetbrains/jet/resolve/ResolveBaseTest.java @@ -50,6 +50,10 @@ public class ResolveBaseTest extends LightCodeInsightTestCase { doSingleResolveTest("test1"); } + public void testSamConstructor() throws Exception { + doSingleResolveTest("(java.util).Comparator"); + } + public void testSeveralOverrides() throws Exception { doMultiResolveTest(); }