FIR IDE: Fix completion in property setters
Property consists of getter and setter (both optional). The setter have a single `value` parameter with type Because of it, we have to make a separate 'frankenstein setter' with original resolved header, but with the body of the fake one It seems that getters does not have such issues
This commit is contained in:
+22
@@ -79,3 +79,25 @@ inline fun buildPropertyAccessor(init: FirPropertyAccessorBuilder.() -> Unit): F
|
||||
}
|
||||
return FirPropertyAccessorBuilder().apply(init).build()
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalContracts::class)
|
||||
inline fun buildPropertyAccessorCopy(original: FirPropertyAccessor, init: FirPropertyAccessorBuilder.() -> Unit): FirPropertyAccessor {
|
||||
contract {
|
||||
callsInPlace(init, kotlin.contracts.InvocationKind.EXACTLY_ONCE)
|
||||
}
|
||||
val copyBuilder = FirPropertyAccessorBuilder()
|
||||
copyBuilder.source = original.source
|
||||
copyBuilder.session = original.session
|
||||
copyBuilder.resolvePhase = original.resolvePhase
|
||||
copyBuilder.origin = original.origin
|
||||
copyBuilder.returnTypeRef = original.returnTypeRef
|
||||
copyBuilder.valueParameters.addAll(original.valueParameters)
|
||||
copyBuilder.body = original.body
|
||||
copyBuilder.contractDescription = original.contractDescription
|
||||
copyBuilder.symbol = original.symbol
|
||||
copyBuilder.isGetter = original.isGetter
|
||||
copyBuilder.status = original.status
|
||||
copyBuilder.annotations.addAll(original.annotations)
|
||||
copyBuilder.typeParameters.addAll(original.typeParameters)
|
||||
return copyBuilder.apply(init).build()
|
||||
}
|
||||
|
||||
+1
@@ -206,6 +206,7 @@ object BuilderConfigurator : AbstractBuilderConfigurator<FirTreeBuilder>(FirTree
|
||||
defaultNull("body")
|
||||
default("contractDescription", "FirEmptyContractDescription")
|
||||
useTypes(emptyContractDescriptionType)
|
||||
withCopy()
|
||||
}
|
||||
|
||||
builder(whenExpression) {
|
||||
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// FIR_COMPARISON
|
||||
|
||||
fun localFun(): Int {}
|
||||
|
||||
val property: Int
|
||||
get() {
|
||||
<caret>
|
||||
}
|
||||
|
||||
// EXIST: localFun
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// FIR_COMPARISON
|
||||
|
||||
fun localFun(): Int {}
|
||||
|
||||
val property: Int
|
||||
get() = <caret>
|
||||
|
||||
// EXIST: localFun
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// FIR_COMPARISON
|
||||
|
||||
class LocalType
|
||||
|
||||
val property
|
||||
get(): <caret>
|
||||
|
||||
// EXIST: LocalType
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
// FIR_COMPARISON
|
||||
|
||||
fun localFun(): Int {}
|
||||
|
||||
val property = <caret>
|
||||
|
||||
// EXIST: localFun
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// FIR_COMPARISON
|
||||
|
||||
fun localFun() {}
|
||||
|
||||
var property: Int
|
||||
get() = 1
|
||||
set(value) {
|
||||
<caret>
|
||||
}
|
||||
|
||||
// EXIST: localFun
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// FIR_COMPARISON
|
||||
|
||||
fun localFun() {}
|
||||
|
||||
var property: Int
|
||||
get() = 1
|
||||
set(value) = <caret>
|
||||
|
||||
// EXIST: localFun
|
||||
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
// FIR_COMPARISON
|
||||
|
||||
class LocalType
|
||||
|
||||
val property: <caret>
|
||||
|
||||
// EXIST: LocalType
|
||||
+35
@@ -2362,6 +2362,41 @@ public class JSBasicCompletionTestGenerated extends AbstractJSBasicCompletionTes
|
||||
runTest("idea/idea-completion/testData/basic/common/primitiveCompletion/topLevelClasses.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("topLevelPropertyGetterBodyCompletion.kt")
|
||||
public void testTopLevelPropertyGetterBodyCompletion() throws Exception {
|
||||
runTest("idea/idea-completion/testData/basic/common/primitiveCompletion/topLevelPropertyGetterBodyCompletion.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("topLevelPropertyGetterExpressionCompletion.kt")
|
||||
public void testTopLevelPropertyGetterExpressionCompletion() throws Exception {
|
||||
runTest("idea/idea-completion/testData/basic/common/primitiveCompletion/topLevelPropertyGetterExpressionCompletion.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("topLevelPropertyGetterTypeCompletion.kt")
|
||||
public void testTopLevelPropertyGetterTypeCompletion() throws Exception {
|
||||
runTest("idea/idea-completion/testData/basic/common/primitiveCompletion/topLevelPropertyGetterTypeCompletion.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("topLevelPropertyInitializerCompletion.kt")
|
||||
public void testTopLevelPropertyInitializerCompletion() throws Exception {
|
||||
runTest("idea/idea-completion/testData/basic/common/primitiveCompletion/topLevelPropertyInitializerCompletion.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("topLevelPropertySetterBodyCompletion.kt")
|
||||
public void testTopLevelPropertySetterBodyCompletion() throws Exception {
|
||||
runTest("idea/idea-completion/testData/basic/common/primitiveCompletion/topLevelPropertySetterBodyCompletion.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("topLevelPropertySetterExpressionCompletion.kt")
|
||||
public void testTopLevelPropertySetterExpressionCompletion() throws Exception {
|
||||
runTest("idea/idea-completion/testData/basic/common/primitiveCompletion/topLevelPropertySetterExpressionCompletion.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("topLevelPropertyTypeCompletion.kt")
|
||||
public void testTopLevelPropertyTypeCompletion() throws Exception {
|
||||
runTest("idea/idea-completion/testData/basic/common/primitiveCompletion/topLevelPropertyTypeCompletion.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("topLevelVariablesAndFunctions.kt")
|
||||
public void testTopLevelVariablesAndFunctions() throws Exception {
|
||||
runTest("idea/idea-completion/testData/basic/common/primitiveCompletion/topLevelVariablesAndFunctions.kt");
|
||||
|
||||
+35
@@ -2362,6 +2362,41 @@ public class JvmBasicCompletionTestGenerated extends AbstractJvmBasicCompletionT
|
||||
runTest("idea/idea-completion/testData/basic/common/primitiveCompletion/topLevelClasses.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("topLevelPropertyGetterBodyCompletion.kt")
|
||||
public void testTopLevelPropertyGetterBodyCompletion() throws Exception {
|
||||
runTest("idea/idea-completion/testData/basic/common/primitiveCompletion/topLevelPropertyGetterBodyCompletion.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("topLevelPropertyGetterExpressionCompletion.kt")
|
||||
public void testTopLevelPropertyGetterExpressionCompletion() throws Exception {
|
||||
runTest("idea/idea-completion/testData/basic/common/primitiveCompletion/topLevelPropertyGetterExpressionCompletion.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("topLevelPropertyGetterTypeCompletion.kt")
|
||||
public void testTopLevelPropertyGetterTypeCompletion() throws Exception {
|
||||
runTest("idea/idea-completion/testData/basic/common/primitiveCompletion/topLevelPropertyGetterTypeCompletion.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("topLevelPropertyInitializerCompletion.kt")
|
||||
public void testTopLevelPropertyInitializerCompletion() throws Exception {
|
||||
runTest("idea/idea-completion/testData/basic/common/primitiveCompletion/topLevelPropertyInitializerCompletion.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("topLevelPropertySetterBodyCompletion.kt")
|
||||
public void testTopLevelPropertySetterBodyCompletion() throws Exception {
|
||||
runTest("idea/idea-completion/testData/basic/common/primitiveCompletion/topLevelPropertySetterBodyCompletion.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("topLevelPropertySetterExpressionCompletion.kt")
|
||||
public void testTopLevelPropertySetterExpressionCompletion() throws Exception {
|
||||
runTest("idea/idea-completion/testData/basic/common/primitiveCompletion/topLevelPropertySetterExpressionCompletion.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("topLevelPropertyTypeCompletion.kt")
|
||||
public void testTopLevelPropertyTypeCompletion() throws Exception {
|
||||
runTest("idea/idea-completion/testData/basic/common/primitiveCompletion/topLevelPropertyTypeCompletion.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("topLevelVariablesAndFunctions.kt")
|
||||
public void testTopLevelVariablesAndFunctions() throws Exception {
|
||||
runTest("idea/idea-completion/testData/basic/common/primitiveCompletion/topLevelVariablesAndFunctions.kt");
|
||||
|
||||
+35
@@ -2362,6 +2362,41 @@ public class HighLevelJvmBasicCompletionTestGenerated extends AbstractHighLevelJ
|
||||
runTest("idea/idea-completion/testData/basic/common/primitiveCompletion/topLevelClasses.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("topLevelPropertyGetterBodyCompletion.kt")
|
||||
public void testTopLevelPropertyGetterBodyCompletion() throws Exception {
|
||||
runTest("idea/idea-completion/testData/basic/common/primitiveCompletion/topLevelPropertyGetterBodyCompletion.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("topLevelPropertyGetterExpressionCompletion.kt")
|
||||
public void testTopLevelPropertyGetterExpressionCompletion() throws Exception {
|
||||
runTest("idea/idea-completion/testData/basic/common/primitiveCompletion/topLevelPropertyGetterExpressionCompletion.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("topLevelPropertyGetterTypeCompletion.kt")
|
||||
public void testTopLevelPropertyGetterTypeCompletion() throws Exception {
|
||||
runTest("idea/idea-completion/testData/basic/common/primitiveCompletion/topLevelPropertyGetterTypeCompletion.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("topLevelPropertyInitializerCompletion.kt")
|
||||
public void testTopLevelPropertyInitializerCompletion() throws Exception {
|
||||
runTest("idea/idea-completion/testData/basic/common/primitiveCompletion/topLevelPropertyInitializerCompletion.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("topLevelPropertySetterBodyCompletion.kt")
|
||||
public void testTopLevelPropertySetterBodyCompletion() throws Exception {
|
||||
runTest("idea/idea-completion/testData/basic/common/primitiveCompletion/topLevelPropertySetterBodyCompletion.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("topLevelPropertySetterExpressionCompletion.kt")
|
||||
public void testTopLevelPropertySetterExpressionCompletion() throws Exception {
|
||||
runTest("idea/idea-completion/testData/basic/common/primitiveCompletion/topLevelPropertySetterExpressionCompletion.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("topLevelPropertyTypeCompletion.kt")
|
||||
public void testTopLevelPropertyTypeCompletion() throws Exception {
|
||||
runTest("idea/idea-completion/testData/basic/common/primitiveCompletion/topLevelPropertyTypeCompletion.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("topLevelVariablesAndFunctions.kt")
|
||||
public void testTopLevelVariablesAndFunctions() throws Exception {
|
||||
runTest("idea/idea-completion/testData/basic/common/primitiveCompletion/topLevelVariablesAndFunctions.kt");
|
||||
|
||||
+16
-1
@@ -13,6 +13,7 @@ import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.declarations.FirProperty
|
||||
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
|
||||
import org.jetbrains.kotlin.fir.declarations.FirSimpleFunction
|
||||
import org.jetbrains.kotlin.fir.declarations.builder.buildPropertyAccessorCopy
|
||||
import org.jetbrains.kotlin.fir.declarations.builder.buildSimpleFunctionCopy
|
||||
import org.jetbrains.kotlin.fir.declarations.builder.buildPropertyCopy
|
||||
import org.jetbrains.kotlin.fir.expressions.FirStatement
|
||||
@@ -110,8 +111,22 @@ object LowLevelFirApiFacade {
|
||||
|
||||
val frankensteinProperty = buildPropertyCopy(originalProperty) {
|
||||
symbol = builtProperty.symbol
|
||||
|
||||
// getter does not have parameters to resolve
|
||||
getter = builtProperty.getter
|
||||
setter = builtProperty.setter
|
||||
|
||||
val originalSetter = setter
|
||||
val builtSetter = builtProperty.setter
|
||||
if (originalSetter != null && builtSetter != null) {
|
||||
setter = buildPropertyAccessorCopy(originalSetter) {
|
||||
body = builtSetter.body
|
||||
symbol = builtSetter.symbol
|
||||
resolvePhase = minOf(builtSetter.resolvePhase, FirResolvePhase.DECLARATIONS)
|
||||
source = builtSetter.source
|
||||
session = state.firIdeSourcesSession
|
||||
}
|
||||
}
|
||||
|
||||
resolvePhase = minOf(originalProperty.resolvePhase, FirResolvePhase.DECLARATIONS)
|
||||
source = builtProperty.source
|
||||
session = state.firIdeSourcesSession
|
||||
|
||||
Reference in New Issue
Block a user