Navigation: Resolve typealiased SAM-references to type alias declaration

#KT-15302 Fixed
This commit is contained in:
Alexey Sedunov
2018-02-26 15:02:45 +03:00
parent 5bff4b9f39
commit 4609b2ae37
9 changed files with 45 additions and 3 deletions
@@ -17,17 +17,22 @@
package org.jetbrains.kotlin.load.java.sam
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.descriptors.DeclarationDescriptorWithNavigationSubstitute
import org.jetbrains.kotlin.descriptors.TypeAliasDescriptor
import org.jetbrains.kotlin.descriptors.impl.SimpleFunctionDescriptorImpl
import org.jetbrains.kotlin.load.java.descriptors.JavaClassDescriptor
interface SamTypeAliasConstructorDescriptor : SamConstructorDescriptor {
interface SamTypeAliasConstructorDescriptor : SamConstructorDescriptor, DeclarationDescriptorWithNavigationSubstitute {
val typeAliasDescriptor: TypeAliasDescriptor
override val substitute: DeclarationDescriptor
get() = typeAliasDescriptor
}
class SamTypeAliasConstructorDescriptorImpl(
override val typeAliasDescriptor: TypeAliasDescriptor,
private val samInterfaceConstructorDescriptor: SamConstructorDescriptor
override val typeAliasDescriptor: TypeAliasDescriptor,
private val samInterfaceConstructorDescriptor: SamConstructorDescriptor
) : SimpleFunctionDescriptorImpl(
typeAliasDescriptor.containingDeclaration,
null,
@@ -31,6 +31,11 @@ import java.util.*
object DescriptorToSourceUtils {
private fun collectEffectiveReferencedDescriptors(result: MutableList<DeclarationDescriptor>, descriptor: DeclarationDescriptor) {
if (descriptor is DeclarationDescriptorWithNavigationSubstitute) {
collectEffectiveReferencedDescriptors(result, descriptor.substitute)
return
}
if (descriptor is CallableMemberDescriptor) {
val kind = descriptor.kind
if (kind != DECLARATION && kind != SYNTHESIZED) {
@@ -0,0 +1,10 @@
/*
* Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.descriptors
interface DeclarationDescriptorWithNavigationSubstitute : DeclarationDescriptor {
val substitute: DeclarationDescriptor
}
@@ -0,0 +1,3 @@
public interface Runnable {
public abstract void run();
}
@@ -0,0 +1,2 @@
typealias S = Runnable
val r1 = S {}
@@ -0,0 +1,3 @@
public interface Runnable {
public abstract void run();
}
@@ -0,0 +1,2 @@
typealias /*rename*/R = Runnable
val r1 = R {}
@@ -0,0 +1,6 @@
{
"type": "MARKED_ELEMENT",
"mainFile": "test/test.kt",
"newName": "S",
"withRuntime": "true"
}
@@ -1285,6 +1285,12 @@ public class RenameTestGenerated extends AbstractRenameTest {
doTest(fileName);
}
@TestMetadata("samConstructorTypeAlias/samConstructorTypeAlias.test")
public void testSamConstructorTypeAlias_SamConstructorTypeAlias() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/rename/samConstructorTypeAlias/samConstructorTypeAlias.test");
doTest(fileName);
}
@TestMetadata("secondaryCnstructorParameterRedeclaration/secondaryConstructorParameterRedeclaration.test")
public void testSecondaryCnstructorParameterRedeclaration_SecondaryConstructorParameterRedeclaration() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/rename/secondaryCnstructorParameterRedeclaration/secondaryConstructorParameterRedeclaration.test");