Extraction Engine: Properly retrieve declaration for overriden/delegated Java synthetic properties

#KT-9554 Fixed
This commit is contained in:
Alexey Sedunov
2015-10-16 18:58:33 +03:00
parent 84aa4e7664
commit bdd495460b
8 changed files with 71 additions and 7 deletions
@@ -43,7 +43,6 @@ import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValueFactory
import org.jetbrains.kotlin.resolve.calls.tasks.isSynthesizedInvoke
import org.jetbrains.kotlin.resolve.descriptorUtil.isExtension
import org.jetbrains.kotlin.resolve.scopes.receivers.ThisReceiver
import org.jetbrains.kotlin.resolve.source.getPsi
import org.jetbrains.kotlin.synthetic.SyntheticJavaPropertyDescriptor
import org.jetbrains.kotlin.types.KotlinType
import java.util.*
@@ -126,17 +125,14 @@ data class ExtractionData(
return function == null || !function.isInsideOf(originalElements)
}
fun getSyntheticPropertyAccessorDeclarationIfAny(descriptor: DeclarationDescriptor): PsiNameIdentifierOwner? {
return (descriptor as? SyntheticJavaPropertyDescriptor ?: return null).getMethod.source.getPsi() as? PsiNameIdentifierOwner
}
fun getDeclaration(descriptor: DeclarationDescriptor, context: BindingContext): PsiNameIdentifierOwner? {
tailrec fun getDeclaration(descriptor: DeclarationDescriptor, context: BindingContext): PsiNameIdentifierOwner? {
(DescriptorToSourceUtilsIde.getAnyDeclaration(project, descriptor) as? PsiNameIdentifierOwner)?.let { return it }
return when {
isExtractableIt(descriptor, context) -> itFakeDeclaration
isSynthesizedInvoke(descriptor) -> synthesizedInvokeDeclaration
else -> getSyntheticPropertyAccessorDeclarationIfAny(descriptor)
descriptor is SyntheticJavaPropertyDescriptor -> getDeclaration(descriptor.getMethod, context)
else -> null
}
}
@@ -0,0 +1,6 @@
import org.jetbrains.annotations.NotNull;
interface Named {
@NotNull
String getName();
}
@@ -0,0 +1,11 @@
// WITH_RUNTIME
// PARAM_DESCRIPTOR: private final fun NamedEx.foo(): [@org.jetbrains.annotations.NotNull] String defined in Test
// PARAM_TYPES: NamedEx
// SIBLING:
public class Test {
private fun NamedEx.foo() = <selection>name</selection>
}
public class NamedEx : Named by object : Named {
override fun getName(): String = "foo"
}
@@ -0,0 +1,13 @@
// WITH_RUNTIME
// PARAM_DESCRIPTOR: private final fun NamedEx.foo(): [@org.jetbrains.annotations.NotNull] String defined in Test
// PARAM_TYPES: NamedEx
// SIBLING:
public class Test {
private fun NamedEx.foo() = s()
}
private fun NamedEx.s() = name
public class NamedEx : Named by object : Named {
override fun getName(): String = "foo"
}
@@ -0,0 +1,10 @@
import org.jetbrains.annotations.NotNull;
interface Named {
@NotNull
String getName();
}
interface NamedEx extends Named {
}
@@ -0,0 +1,7 @@
// WITH_RUNTIME
// PARAM_DESCRIPTOR: private final fun NamedEx.foo(): [@org.jetbrains.annotations.NotNull] String defined in Test
// PARAM_TYPES: NamedEx
// SIBLING:
public class Test {
private fun NamedEx.foo() = <selection>name</selection>
}
@@ -0,0 +1,9 @@
// WITH_RUNTIME
// PARAM_DESCRIPTOR: private final fun NamedEx.foo(): [@org.jetbrains.annotations.NotNull] String defined in Test
// PARAM_TYPES: NamedEx
// SIBLING:
public class Test {
private fun NamedEx.foo() = s()
}
private fun NamedEx.s() = name
@@ -1997,6 +1997,18 @@ public class JetExtractionTestGenerated extends AbstractJetExtractionTest {
doExtractFunctionTest(fileName);
}
@TestMetadata("javaSyntheticPropertyWithDelegation.kt")
public void testJavaSyntheticPropertyWithDelegation() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/refactoring/extractFunction/parameters/extractThis/javaSyntheticPropertyWithDelegation.kt");
doExtractFunctionTest(fileName);
}
@TestMetadata("javaSyntheticPropertyWithOverride.kt")
public void testJavaSyntheticPropertyWithOverride() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/refactoring/extractFunction/parameters/extractThis/javaSyntheticPropertyWithOverride.kt");
doExtractFunctionTest(fileName);
}
@TestMetadata("missingReceiver.kt")
public void testMissingReceiver() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/refactoring/extractFunction/parameters/extractThis/missingReceiver.kt");