diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/SamCodegenUtil.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/SamCodegenUtil.java index 19c2fbbbb32..af3409751e9 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/SamCodegenUtil.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/SamCodegenUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2015 JetBrains s.r.o. + * Copyright 2010-2016 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,18 +19,16 @@ package org.jetbrains.kotlin.codegen; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.kotlin.descriptors.FunctionDescriptor; +import org.jetbrains.kotlin.descriptors.synthetic.SyntheticMemberDescriptor; import org.jetbrains.kotlin.load.java.descriptors.SamAdapterDescriptor; import org.jetbrains.kotlin.synthetic.SamAdapterExtensionFunctionDescriptor; public class SamCodegenUtil { @Nullable public static FunctionDescriptor getOriginalIfSamAdapter(@NotNull FunctionDescriptor fun) { - if (fun instanceof SamAdapterDescriptor) { - return ((SamAdapterDescriptor) fun).getOriginForSam(); - } - - if (fun instanceof SamAdapterExtensionFunctionDescriptor) { - return ((SamAdapterExtensionFunctionDescriptor) fun).getSourceFunction(); + if (fun instanceof SamAdapterDescriptor || fun instanceof SamAdapterExtensionFunctionDescriptor) { + //noinspection unchecked + return ((SyntheticMemberDescriptor) fun).getBaseDescriptorForSynthetic(); } return null; diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/sam/SamAdapterConstructorDescriptor.java b/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/sam/SamAdapterConstructorDescriptor.java index 11e22200cf0..6f3931c67df 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/sam/SamAdapterConstructorDescriptor.java +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/sam/SamAdapterConstructorDescriptor.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2015 JetBrains s.r.o. + * Copyright 2010-2016 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,12 +18,14 @@ package org.jetbrains.kotlin.load.java.sam; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.jetbrains.kotlin.descriptors.*; +import org.jetbrains.kotlin.descriptors.ClassDescriptor; +import org.jetbrains.kotlin.descriptors.SourceElement; import org.jetbrains.kotlin.descriptors.annotations.Annotations; import org.jetbrains.kotlin.load.java.descriptors.JavaConstructorDescriptor; import org.jetbrains.kotlin.load.java.descriptors.SamAdapterDescriptor; -/* package */ class SamAdapterConstructorDescriptor extends JavaConstructorDescriptor implements SamAdapterDescriptor { +/* package */ class SamAdapterConstructorDescriptor extends JavaConstructorDescriptor + implements SamAdapterDescriptor { private final JavaConstructorDescriptor declaration; public SamAdapterConstructorDescriptor(@NotNull JavaConstructorDescriptor declaration) { @@ -61,7 +63,7 @@ import org.jetbrains.kotlin.load.java.descriptors.SamAdapterDescriptor; @NotNull @Override - public JavaConstructorDescriptor getOriginForSam() { + public JavaConstructorDescriptor getBaseDescriptorForSynthetic() { return declaration; } } diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/sam/SamAdapterFunctionDescriptor.java b/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/sam/SamAdapterFunctionDescriptor.java index 8cda92835f4..d47bf353e9e 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/sam/SamAdapterFunctionDescriptor.java +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/sam/SamAdapterFunctionDescriptor.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2015 JetBrains s.r.o. + * Copyright 2010-2016 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -45,12 +45,6 @@ import org.jetbrains.kotlin.name.Name; setParameterNamesStatus(declaration.hasStableParameterNames(), declaration.hasSynthesizedParameterNames()); } - @NotNull - @Override - public JavaMethodDescriptor getOriginForSam() { - return declaration; - } - @NotNull @Override protected JavaMethodDescriptor createSubstitutedCopy( @@ -63,4 +57,10 @@ import org.jetbrains.kotlin.name.Name; ) { return new SamAdapterFunctionDescriptor(newOwner, (SimpleFunctionDescriptor) original, kind, declaration); } + + @NotNull + @Override + public JavaMethodDescriptor getBaseDescriptorForSynthetic() { + return declaration; + } } diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/sam/SamAdapterOverridabilityCondition.java b/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/sam/SamAdapterOverridabilityCondition.java index 7b1e0ebefd2..d0ee9ea334a 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/sam/SamAdapterOverridabilityCondition.java +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/sam/SamAdapterOverridabilityCondition.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2015 JetBrains s.r.o. + * Copyright 2010-2016 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -106,7 +106,7 @@ public class SamAdapterOverridabilityCondition implements ExternalOverridability return null; } - SimpleFunctionDescriptor originalDeclarationOfSam = ((SamAdapterFunctionDescriptor) fun).getOriginForSam(); + SimpleFunctionDescriptor originalDeclarationOfSam = ((SamAdapterFunctionDescriptor) fun).getBaseDescriptorForSynthetic(); return ((SimpleFunctionDescriptor) originalDeclarationOfSam.substitute(TypeSubstitutor.create(declarationOrSynthesized.ownerType))); } diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/checkers/ProtectedSyntheticExtensionCallChecker.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/checkers/ProtectedSyntheticExtensionCallChecker.kt index dfda3aa9730..eba444166e3 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/checkers/ProtectedSyntheticExtensionCallChecker.kt +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/checkers/ProtectedSyntheticExtensionCallChecker.kt @@ -33,7 +33,7 @@ object ProtectedSyntheticExtensionCallChecker : SimpleCallChecker { val sourceFunction = when (descriptor) { is SyntheticJavaPropertyDescriptor -> descriptor.getMethod - is SamAdapterExtensionFunctionDescriptor -> descriptor.sourceFunction + is SamAdapterExtensionFunctionDescriptor -> descriptor.baseDescriptorForSynthetic else -> return } diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/synthetic/SamAdapterFunctionsScope.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/synthetic/SamAdapterFunctionsScope.kt index 443ccd3d3fe..191cd3901c6 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/synthetic/SamAdapterFunctionsScope.kt +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/synthetic/SamAdapterFunctionsScope.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2015 JetBrains s.r.o. + * Copyright 2010-2016 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,6 +20,7 @@ import com.intellij.util.SmartList import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.annotations.Annotations import org.jetbrains.kotlin.descriptors.impl.SimpleFunctionDescriptorImpl +import org.jetbrains.kotlin.descriptors.synthetic.SyntheticMemberDescriptor import org.jetbrains.kotlin.incremental.components.LookupLocation import org.jetbrains.kotlin.load.java.sam.SingleAbstractMethodUtils import org.jetbrains.kotlin.name.Name @@ -33,8 +34,8 @@ import org.jetbrains.kotlin.types.* import java.util.* import kotlin.properties.Delegates -interface SamAdapterExtensionFunctionDescriptor : FunctionDescriptor { - val sourceFunction: FunctionDescriptor +interface SamAdapterExtensionFunctionDescriptor : FunctionDescriptor, SyntheticMemberDescriptor { + override val baseDescriptorForSynthetic: FunctionDescriptor } class SamAdapterFunctionsScope(storageManager: StorageManager) : SyntheticScope { @@ -92,7 +93,7 @@ class SamAdapterFunctionsScope(storageManager: StorageManager) : SyntheticScope source: SourceElement ) : SamAdapterExtensionFunctionDescriptor, SimpleFunctionDescriptorImpl(containingDeclaration, original, annotations, name, kind, source) { - override var sourceFunction: FunctionDescriptor by Delegates.notNull() + override var baseDescriptorForSynthetic: FunctionDescriptor by Delegates.notNull() private set private var toSourceFunctionTypeParameters: Map? = null @@ -105,7 +106,7 @@ class SamAdapterFunctionsScope(storageManager: StorageManager) : SyntheticScope sourceFunction.name, CallableMemberDescriptor.Kind.SYNTHESIZED, sourceFunction.original.source) - descriptor.sourceFunction = sourceFunction + descriptor.baseDescriptorForSynthetic = sourceFunction val sourceTypeParams = (sourceFunction.typeParameters).toMutableList() val ownerClass = sourceFunction.containingDeclaration as ClassDescriptor @@ -138,8 +139,8 @@ class SamAdapterFunctionsScope(storageManager: StorageManager) : SyntheticScope } } - override fun hasStableParameterNames() = sourceFunction.hasStableParameterNames() - override fun hasSynthesizedParameterNames() = sourceFunction.hasSynthesizedParameterNames() + override fun hasStableParameterNames() = baseDescriptorForSynthetic.hasStableParameterNames() + override fun hasSynthesizedParameterNames() = baseDescriptorForSynthetic.hasSynthesizedParameterNames() override fun createSubstitutedCopy( newOwner: DeclarationDescriptor, @@ -152,7 +153,7 @@ class SamAdapterFunctionsScope(storageManager: StorageManager) : SyntheticScope return MyFunctionDescriptor( containingDeclaration, original as SimpleFunctionDescriptor?, annotations, newName ?: name, kind, source ).apply { - sourceFunction = this@MyFunctionDescriptor.sourceFunction + baseDescriptorForSynthetic = this@MyFunctionDescriptor.baseDescriptorForSynthetic } } @@ -176,7 +177,7 @@ class SamAdapterFunctionsScope(storageManager: StorageManager) : SyntheticScope TypeConstructorSubstitution.createByConstructorsMap( substitutionMap, configuration.substitution.approximateCapturedTypes()).buildSubstitutor() - descriptor.sourceFunction = original.sourceFunction.substitute(sourceFunctionSubstitutor) + descriptor.baseDescriptorForSynthetic = original.baseDescriptorForSynthetic.substitute(sourceFunctionSubstitutor) return descriptor } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DescriptorToSourceUtils.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DescriptorToSourceUtils.kt index 7a226537140..877c09ad60e 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DescriptorToSourceUtils.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DescriptorToSourceUtils.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2015 JetBrains s.r.o. + * Copyright 2010-2016 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,13 +17,11 @@ package org.jetbrains.kotlin.resolve import com.intellij.psi.PsiElement -import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor +import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor.Kind.DECLARATION import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor.Kind.SYNTHESIZED -import org.jetbrains.kotlin.descriptors.DeclarationDescriptor -import org.jetbrains.kotlin.descriptors.DeclarationDescriptorWithSource -import org.jetbrains.kotlin.descriptors.PropertyAccessorDescriptor import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor +import org.jetbrains.kotlin.descriptors.synthetic.SyntheticMemberDescriptor import org.jetbrains.kotlin.psi.KtAnnotationEntry import org.jetbrains.kotlin.psi.KtFile import org.jetbrains.kotlin.resolve.source.getPsi @@ -39,6 +37,10 @@ object DescriptorToSourceUtils { } return } + if (descriptor is SyntheticMemberDescriptor<*>) { + collectEffectiveReferencedDescriptors(result, descriptor.baseDescriptorForSynthetic) + return + } } result.add(descriptor) } diff --git a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/descriptors/SamAdapterDescriptor.java b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/descriptors/SamAdapterDescriptor.java index 390f93f49b7..3625a6eca42 100644 --- a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/descriptors/SamAdapterDescriptor.java +++ b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/descriptors/SamAdapterDescriptor.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2015 JetBrains s.r.o. + * Copyright 2010-2016 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,10 +16,9 @@ package org.jetbrains.kotlin.load.java.descriptors; -import org.jetbrains.annotations.NotNull; import org.jetbrains.kotlin.descriptors.FunctionDescriptor; +import org.jetbrains.kotlin.descriptors.synthetic.SyntheticMemberDescriptor; -public interface SamAdapterDescriptor extends FunctionDescriptor, JavaCallableMemberDescriptor { - @NotNull - D getOriginForSam(); +public interface SamAdapterDescriptor extends FunctionDescriptor, JavaCallableMemberDescriptor, + SyntheticMemberDescriptor { } diff --git a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/descriptors/SamConstructorDescriptor.kt b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/descriptors/SamConstructorDescriptor.kt index 1fef0437b0f..fc04321d8b0 100644 --- a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/descriptors/SamConstructorDescriptor.kt +++ b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/descriptors/SamConstructorDescriptor.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2015 JetBrains s.r.o. + * Copyright 2010-2016 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,14 +16,15 @@ package org.jetbrains.kotlin.load.java.descriptors -import org.jetbrains.kotlin.descriptors.impl.SimpleFunctionDescriptorImpl import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor import org.jetbrains.kotlin.descriptors.DeclarationDescriptor +import org.jetbrains.kotlin.descriptors.impl.SimpleFunctionDescriptorImpl +import org.jetbrains.kotlin.descriptors.synthetic.SyntheticMemberDescriptor import org.jetbrains.kotlin.resolve.scopes.DescriptorKindExclude class SamConstructorDescriptor( containingDeclaration: DeclarationDescriptor, - samInterface: JavaClassDescriptor + private val samInterface: JavaClassDescriptor ) : SimpleFunctionDescriptorImpl( containingDeclaration, null, @@ -31,7 +32,10 @@ class SamConstructorDescriptor( samInterface.name, CallableMemberDescriptor.Kind.SYNTHESIZED, samInterface.source -) +), SyntheticMemberDescriptor { + override val baseDescriptorForSynthetic: JavaClassDescriptor + get() = samInterface +} object SamConstructorDescriptorKindExclude : DescriptorKindExclude() { override fun excludes(descriptor: DeclarationDescriptor) = descriptor is SamConstructorDescriptor diff --git a/core/descriptors/src/org/jetbrains/kotlin/descriptors/synthetic/SyntheticMemberDescriptor.kt b/core/descriptors/src/org/jetbrains/kotlin/descriptors/synthetic/SyntheticMemberDescriptor.kt new file mode 100644 index 00000000000..b69e2cc48b7 --- /dev/null +++ b/core/descriptors/src/org/jetbrains/kotlin/descriptors/synthetic/SyntheticMemberDescriptor.kt @@ -0,0 +1,23 @@ +/* + * Copyright 2010-2016 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.kotlin.descriptors.synthetic + +import org.jetbrains.kotlin.descriptors.DeclarationDescriptor + +interface SyntheticMemberDescriptor { + val baseDescriptorForSynthetic: T +} \ No newline at end of file diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/LookupElementFactory.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/LookupElementFactory.kt index 6d1fede31ed..e68eaab1ff1 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/LookupElementFactory.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/LookupElementFactory.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2015 JetBrains s.r.o. + * Copyright 2010-2016 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -305,7 +305,7 @@ class LookupElementFactory( return callableWeight(descriptor.getMethod) } if (descriptor is SamAdapterExtensionFunctionDescriptor) { - return callableWeight(descriptor.sourceFunction) + return callableWeight(descriptor.baseDescriptorForSynthetic) } if (descriptor.overriddenDescriptors.isNotEmpty()) { diff --git a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/KotlinIndicesHelper.kt b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/KotlinIndicesHelper.kt index 6b806d77578..ea1d96ebd50 100644 --- a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/KotlinIndicesHelper.kt +++ b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/KotlinIndicesHelper.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2015 JetBrains s.r.o. + * Copyright 2010-2016 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -288,7 +288,7 @@ class KotlinIndicesHelper( // SAM-adapter container.staticScope.getContributedFunctions(descriptor.name, NoLookupLocation.FROM_IDE) .filterIsInstance>() - .firstOrNull { it.originForSam.original == descriptor.original } + .firstOrNull { it.baseDescriptorForSynthetic.original == descriptor.original } ?.let { processor(it) } } } diff --git a/idea/testData/resolve/referenceWithLib/overridingFunctionWithSamAdapter.kt b/idea/testData/resolve/referenceWithLib/overridingFunctionWithSamAdapter.kt new file mode 100644 index 00000000000..af6b13e1e2e --- /dev/null +++ b/idea/testData/resolve/referenceWithLib/overridingFunctionWithSamAdapter.kt @@ -0,0 +1,13 @@ +package test + +class MyClass: Test() { + +} + +fun test(m: MyClass) { + m.act { + + } +} + +// REF: (in test.Test).act(Action) \ No newline at end of file diff --git a/idea/testData/resolve/referenceWithLib/overridingFunctionWithSamAdapterSrc/Test.java b/idea/testData/resolve/referenceWithLib/overridingFunctionWithSamAdapterSrc/Test.java new file mode 100644 index 00000000000..25d50182e86 --- /dev/null +++ b/idea/testData/resolve/referenceWithLib/overridingFunctionWithSamAdapterSrc/Test.java @@ -0,0 +1,10 @@ +package test; + +public class Test { + public interface Action { + String doSmth(String other); + } + + void act(Action action) { + } +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/resolve/ReferenceResolveWithLibTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/resolve/ReferenceResolveWithLibTestGenerated.java index fe96eaa8e7a..8ee482d3e54 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/resolve/ReferenceResolveWithLibTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/resolve/ReferenceResolveWithLibTestGenerated.java @@ -77,6 +77,12 @@ public class ReferenceResolveWithLibTestGenerated extends AbstractReferenceResol doTest(fileName); } + @TestMetadata("overridingFunctionWithSamAdapter.kt") + public void testOverridingFunctionWithSamAdapter() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/resolve/referenceWithLib/overridingFunctionWithSamAdapter.kt"); + doTest(fileName); + } + @TestMetadata("packageOfLibDeclaration.kt") public void testPackageOfLibDeclaration() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/resolve/referenceWithLib/packageOfLibDeclaration.kt");