FE1.0 Analysis API: fix getReturnTypeForKtDeclaration for setter parameter
This commit is contained in:
committed by
Ilya Kirillov
parent
f1d0791f15
commit
6e555e1d28
+16
@@ -99,6 +99,22 @@ class KtFe10ExpressionTypeProvider(
|
|||||||
return kotlinType.toKtType(analysisContext)
|
return kotlinType.toKtType(analysisContext)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Manually handle custom setter parameter
|
||||||
|
if (declaration is KtParameter) {
|
||||||
|
val parameterList = declaration.parent as? KtParameterList
|
||||||
|
if (parameterList?.parameters?.singleOrNull() == declaration) {
|
||||||
|
val propertyAccessor = parameterList.parent as? KtPropertyAccessor
|
||||||
|
val property = propertyAccessor?.parent as? KtProperty
|
||||||
|
if (property != null && property.setter == propertyAccessor) {
|
||||||
|
val bindingContext = analysisContext.analyze(property)
|
||||||
|
val kotlinType = bindingContext[BindingContext.VARIABLE, property]?.returnType
|
||||||
|
?: ErrorUtils.createErrorType("Return type for property \"${declaration.name}\" cannot be resolved")
|
||||||
|
|
||||||
|
return kotlinType.toKtType(analysisContext)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return analysisContext.builtIns.unitType.toKtType(analysisContext)
|
return analysisContext.builtIns.unitType.toKtType(analysisContext)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+9
-9
@@ -19,20 +19,20 @@ abstract class AbstractDeclarationReturnTypeTest(
|
|||||||
override fun doTestByFileStructure(ktFile: KtFile, module: TestModule, testServices: TestServices) {
|
override fun doTestByFileStructure(ktFile: KtFile, module: TestModule, testServices: TestServices) {
|
||||||
val actual = buildString {
|
val actual = buildString {
|
||||||
ktFile.accept(object : KtTreeVisitor<Int>() {
|
ktFile.accept(object : KtTreeVisitor<Int>() {
|
||||||
override fun visitDeclaration(dcl: KtDeclaration, data: Int): Void? {
|
override fun visitDeclaration(dclaration: KtDeclaration, indent: Int): Void? {
|
||||||
if (dcl is KtTypeParameter) return null
|
if (dclaration is KtTypeParameter) return null
|
||||||
append(" ".repeat(data))
|
append(" ".repeat(indent))
|
||||||
if (dcl is KtClassLikeDeclaration) {
|
if (dclaration is KtClassLikeDeclaration) {
|
||||||
appendLine(dcl.getNameWithPositionString())
|
appendLine(dclaration.getNameWithPositionString())
|
||||||
} else {
|
} else {
|
||||||
analyseForTest(dcl) {
|
analyseForTest(dclaration) {
|
||||||
val returnType = dcl.getReturnKtType()
|
val returnType = dclaration.getReturnKtType()
|
||||||
append(dcl.getNameWithPositionString())
|
append(dclaration.getNameWithPositionString())
|
||||||
append(" : ")
|
append(" : ")
|
||||||
appendLine(returnType.render())
|
appendLine(returnType.render())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return super.visitDeclaration(dcl, data + 2)
|
return super.visitDeclaration(dclaration, indent + 2)
|
||||||
}
|
}
|
||||||
}, 0)
|
}, 0)
|
||||||
}
|
}
|
||||||
|
|||||||
-9
@@ -1,9 +0,0 @@
|
|||||||
i@(1,1) : kotlin.Int
|
|
||||||
KtPropertyAccessor@(2,5) : kotlin.Int
|
|
||||||
KtPropertyAccessor@(3,5) : kotlin.Unit
|
|
||||||
value@(3,9) : kotlin.Unit
|
|
||||||
A@(5,1)
|
|
||||||
j@(6,5) : kotlin.Int
|
|
||||||
KtPropertyAccessor@(7,9) : kotlin.Int
|
|
||||||
KtPropertyAccessor@(8,9) : kotlin.Unit
|
|
||||||
value@(8,13) : kotlin.Unit
|
|
||||||
Reference in New Issue
Block a user