Change Signature: Support members of header/impl classes

This commit is contained in:
Alexey Sedunov
2017-08-04 20:31:40 +03:00
parent e4f70a3568
commit 8439e15c6e
27 changed files with 407 additions and 1 deletions
@@ -21,7 +21,9 @@ import org.jetbrains.kotlin.idea.caches.resolve.findModuleDescriptor
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptor
import org.jetbrains.kotlin.idea.core.toDescriptor
import org.jetbrains.kotlin.idea.highlighter.sourceKind
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.psi.KtDeclaration
import org.jetbrains.kotlin.psi.psiUtil.containingClassOrObject
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
import org.jetbrains.kotlin.resolve.MultiTargetPlatform
import org.jetbrains.kotlin.resolve.checkers.HeaderImplDeclarationChecker
@@ -63,6 +65,9 @@ internal fun KtDeclaration.headerDeclarationIfAny(): KtDeclaration? {
return DescriptorToSourceUtils.descriptorToDeclaration(headerDescriptor) as? KtDeclaration
}
internal fun KtDeclaration.isHeaderOrHeaderClassMember() =
hasModifier(KtTokens.HEADER_KEYWORD) || (containingClassOrObject?.hasModifier(KtTokens.HEADER_KEYWORD) ?: false)
private fun DeclarationDescriptor.liftToHeader(): DeclarationDescriptor? {
if (this is MemberDescriptor) {
return when {
@@ -29,6 +29,7 @@ import org.jetbrains.kotlin.descriptors.impl.AnonymousFunctionDescriptor
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptor
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde
import org.jetbrains.kotlin.idea.highlighter.markers.headerImplementations
import org.jetbrains.kotlin.idea.highlighter.markers.isHeaderOrHeaderClassMember
import org.jetbrains.kotlin.idea.highlighter.markers.liftToHeader
import org.jetbrains.kotlin.idea.refactoring.changeSignature.usages.KotlinCallableDefinitionUsage
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers
@@ -101,7 +102,7 @@ class KotlinChangeSignatureData(
primaryCallables + primaryCallables.flatMapTo(HashSet<UsageInfo>()) { primaryFunction ->
val primaryDeclaration = primaryFunction.declaration as? KtCallableDeclaration ?: return@flatMapTo emptyList()
if (primaryDeclaration.hasModifier(KtTokens.HEADER_KEYWORD)) {
if (primaryDeclaration.isHeaderOrHeaderClassMember()) {
return@flatMapTo primaryDeclaration.headerImplementations().map {
KotlinCallableDefinitionUsage<PsiElement>(it, it.resolveToDescriptor() as CallableDescriptor, primaryFunction, null)
}
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="kotlin-language" name="Kotlin">
<configuration version="2" platform="Common (experimental) " useProjectSettings="false">
<compilerSettings/>
<compilerArguments/>
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
@@ -0,0 +1,13 @@
package test
header class C {
fun foo()
fun baz(n: Int)
fun bar(n: Int)
}
fun test(c: C) {
c.foo()
c.baz(1)
c.bar(1)
}
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="kotlin-language" name="Kotlin">
<configuration version="2" platform="JavaScript " useProjectSettings="false">
<compilerSettings/>
<compilerArguments/>
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="Common" />
</component>
</module>
@@ -0,0 +1,13 @@
package test
impl class C {
impl fun foo() { }
impl fun baz(n: Int) { }
impl fun bar(n: Int) { }
}
fun test(c: C) {
c.foo()
c.baz(1)
c.bar(1)
}
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="kotlin-language" name="Kotlin">
<configuration version="2" platform="JVM 1.6" useProjectSettings="false">
<compilerSettings/>
<compilerArguments/>
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="Common" />
</component>
</module>
@@ -0,0 +1,13 @@
package test
impl class C {
impl fun foo() { }
impl fun baz(n: Int) { }
impl fun bar(n: Int) { }
}
fun test(c: C) {
c.foo()
c.baz(1)
c.bar(1)
}
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="kotlin-language" name="Kotlin">
<configuration version="2" platform="Common (experimental) " useProjectSettings="false">
<compilerSettings/>
<compilerArguments/>
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
@@ -0,0 +1,13 @@
package test
header class C {
fun foo()
fun <caret>foo(n: Int)
fun bar(n: Int)
}
fun test(c: C) {
c.foo()
c.foo(1)
c.bar(1)
}
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="kotlin-language" name="Kotlin">
<configuration version="2" platform="JavaScript " useProjectSettings="false">
<compilerSettings/>
<compilerArguments/>
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="Common" />
</component>
</module>
@@ -0,0 +1,13 @@
package test
impl class C {
impl fun foo() { }
impl fun foo(n: Int) { }
impl fun bar(n: Int) { }
}
fun test(c: C) {
c.foo()
c.foo(1)
c.bar(1)
}
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="kotlin-language" name="Kotlin">
<configuration version="2" platform="JVM 1.6" useProjectSettings="false">
<compilerSettings/>
<compilerArguments/>
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="Common" />
</component>
</module>
@@ -0,0 +1,13 @@
package test
impl class C {
impl fun foo() { }
impl fun foo(n: Int) { }
impl fun bar(n: Int) { }
}
fun test(c: C) {
c.foo()
c.foo(1)
c.bar(1)
}
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="kotlin-language" name="Kotlin">
<configuration version="2" platform="Common (experimental) " useProjectSettings="false">
<compilerSettings/>
<compilerArguments/>
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
@@ -0,0 +1,13 @@
package test
header class C {
fun foo()
fun baz(n: Int)
fun bar(n: Int)
}
fun test(c: C) {
c.foo()
c.baz(1)
c.bar(1)
}
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="kotlin-language" name="Kotlin">
<configuration version="2" platform="JavaScript " useProjectSettings="false">
<compilerSettings/>
<compilerArguments/>
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="Common" />
</component>
</module>
@@ -0,0 +1,13 @@
package test
impl class C {
impl fun foo() { }
impl fun baz(n: Int) { }
impl fun bar(n: Int) { }
}
fun test(c: C) {
c.foo()
c.baz(1)
c.bar(1)
}
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="kotlin-language" name="Kotlin">
<configuration version="2" platform="JVM 1.6" useProjectSettings="false">
<compilerSettings/>
<compilerArguments/>
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="Common" />
</component>
</module>
@@ -0,0 +1,13 @@
package test
impl class C {
impl fun foo() { }
impl fun baz(n: Int) { }
impl fun bar(n: Int) { }
}
fun test(c: C) {
c.foo()
c.baz(1)
c.bar(1)
}
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="kotlin-language" name="Kotlin">
<configuration version="2" platform="Common (experimental) " useProjectSettings="false">
<compilerSettings/>
<compilerArguments/>
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
@@ -0,0 +1,13 @@
package test
header class C {
fun foo()
fun foo(n: Int)
fun bar(n: Int)
}
fun test(c: C) {
c.foo()
c.foo(1)
c.bar(1)
}
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="kotlin-language" name="Kotlin">
<configuration version="2" platform="JavaScript " useProjectSettings="false">
<compilerSettings/>
<compilerArguments/>
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="Common" />
</component>
</module>
@@ -0,0 +1,13 @@
package test
impl class C {
impl fun foo() { }
impl fun <caret>foo(n: Int) { }
impl fun bar(n: Int) { }
}
fun test(c: C) {
c.foo()
c.foo(1)
c.bar(1)
}
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="kotlin-language" name="Kotlin">
<configuration version="2" platform="JVM 1.6" useProjectSettings="false">
<compilerSettings/>
<compilerArguments/>
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="Common" />
</component>
</module>
@@ -0,0 +1,13 @@
package test
impl class C {
impl fun foo() { }
impl fun foo(n: Int) { }
impl fun bar(n: Int) { }
}
fun test(c: C) {
c.foo()
c.foo(1)
c.bar(1)
}
@@ -55,4 +55,12 @@ class KotlinMultiModuleChangeSignatureTest : KotlinMultiFileTestCase() {
fun testHeadersAndImplsByImplFun() = doTest("JS/src/test/test.kt") {
newName = "baz"
}
fun testHeadersAndImplsByHeaderClassMemberFun() = doTest("Common/src/test/test.kt") {
newName = "baz"
}
fun testHeadersAndImplsByImplClassMemberFun() = doTest("JS/src/test/test.kt") {
newName = "baz"
}
}