[AA] Provide expected type for annotation entry argument

^KTIJ-19863
This commit is contained in:
aleksandrina-streltsova
2023-06-15 14:07:10 +03:00
committed by teamcity
parent fa6b1e24f9
commit 3477d35168
9 changed files with 78 additions and 8 deletions
@@ -52,6 +52,12 @@ public class Fe10IdeNormalAnalysisSourceModuleExpectedExpressionTypeTestGenerate
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("analysis/analysis-api/testData/components/expressionTypeProvider/expectedExpressionType"), Pattern.compile("^(.+)\\.kt$"), null, true);
}
@Test
@TestMetadata("annotationPositionalArgument.kt")
public void testAnnotationPositionalArgument() throws Exception {
runTest("analysis/analysis-api/testData/components/expressionTypeProvider/expectedExpressionType/annotationPositionalArgument.kt");
}
@Test
@TestMetadata("arrayAccessExpressionGet.kt")
public void testArrayAccessExpressionGet() throws Exception {
@@ -88,6 +94,12 @@ public class Fe10IdeNormalAnalysisSourceModuleExpectedExpressionTypeTestGenerate
runTest("analysis/analysis-api/testData/components/expressionTypeProvider/expectedExpressionType/conditionInWhenWithoutSubject.kt");
}
@Test
@TestMetadata("delegatedConstructorCall.kt")
public void testDelegatedConstructorCall() throws Exception {
runTest("analysis/analysis-api/testData/components/expressionTypeProvider/expectedExpressionType/delegatedConstructorCall.kt");
}
@Test
@TestMetadata("elvisExpressionLeftOperand.kt")
public void testElvisExpressionLeftOperand() throws Exception {
@@ -110,10 +110,13 @@ internal class KtFirExpressionTypeProvider(
private data class SubstitutedValueParameter(val parameter: FirValueParameter, val substitutedType: ConeKotlinType)
private fun FirFunctionCall.argumentsToSubstitutedValueParameters(
substituteWithErrorTypes: Boolean = true
private fun FirCall.argumentsToSubstitutedValueParameters(
substituteWithErrorTypes: Boolean = true,
): LinkedHashMap<FirExpression, SubstitutedValueParameter>? {
val substitutor = createConeSubstitutorFromTypeArguments(discardErrorTypes = !substituteWithErrorTypes) ?: ConeSubstitutor.Empty
val substitutor = (this as? FirQualifiedAccessExpression)
?.createConeSubstitutorFromTypeArguments(discardErrorTypes = !substituteWithErrorTypes)
?: ConeSubstitutor.Empty
return resolvedArgumentMapping?.mapValuesTo(LinkedHashMap()) { (_, parameter) ->
SubstitutedValueParameter(parameter, substitutor.substituteOrSelf(parameter.returnTypeRef.coneType))
}
@@ -170,8 +173,8 @@ internal class KtFirExpressionTypeProvider(
}
private fun getExpectedTypeOfFunctionParameter(expression: PsiElement): KtType? {
val (ktCallExpression, argumentExpression) = expression.getFunctionCallAsWithThisAsParameter() ?: return null
val firCall = ktCallExpression.getOrBuildFirSafe<FirFunctionCall>(firResolveSession) ?: return null
val (ktCallElement, argumentExpression) = expression.getFunctionCallAsWithThisAsParameter() ?: return null
val firCall = ktCallElement.getOrBuildFirSafe<FirCall>(firResolveSession) ?: return null
val callee = (firCall.calleeReference as? FirResolvedNamedReference)?.resolvedSymbol
if (callee?.fir?.origin == FirDeclarationOrigin.SamConstructor) {
@@ -221,8 +224,8 @@ internal class KtFirExpressionTypeProvider(
valueArg.getArgumentExpression()?.unwrap() == expr
} ?: return null
val callExpression =
(valueArgument.parent as? KtValueArgumentList)?.parent as? KtCallExpression
?: valueArgument.parent as? KtCallExpression // KtLambdaArgument
(valueArgument.parent as? KtValueArgumentList)?.parent as? KtCallElement
?: valueArgument.parent as? KtCallElement // KtLambdaArgument
?: return null
val argumentExpression = valueArgument.getArgumentExpression() ?: return null
return KtCallWithArgument(callExpression, argumentExpression)
@@ -397,7 +400,7 @@ internal class KtFirExpressionTypeProvider(
}
}
private data class KtCallWithArgument(val call: KtCallExpression, val argument: KtExpression)
private data class KtCallWithArgument(val call: KtCallElement, val argument: KtExpression)
private inline fun <reified R : Any> PsiElement.unwrapQualified(check: (R, PsiElement) -> Boolean): R? {
val parent = nonContainerParent
@@ -52,6 +52,12 @@ public class FirIdeDependentAnalysisSourceModuleExpectedExpressionTypeTestGenera
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("analysis/analysis-api/testData/components/expressionTypeProvider/expectedExpressionType"), Pattern.compile("^(.+)\\.kt$"), null, true);
}
@Test
@TestMetadata("annotationPositionalArgument.kt")
public void testAnnotationPositionalArgument() throws Exception {
runTest("analysis/analysis-api/testData/components/expressionTypeProvider/expectedExpressionType/annotationPositionalArgument.kt");
}
@Test
@TestMetadata("arrayAccessExpressionGet.kt")
public void testArrayAccessExpressionGet() throws Exception {
@@ -88,6 +94,12 @@ public class FirIdeDependentAnalysisSourceModuleExpectedExpressionTypeTestGenera
runTest("analysis/analysis-api/testData/components/expressionTypeProvider/expectedExpressionType/conditionInWhenWithoutSubject.kt");
}
@Test
@TestMetadata("delegatedConstructorCall.kt")
public void testDelegatedConstructorCall() throws Exception {
runTest("analysis/analysis-api/testData/components/expressionTypeProvider/expectedExpressionType/delegatedConstructorCall.kt");
}
@Test
@TestMetadata("elvisExpressionLeftOperand.kt")
public void testElvisExpressionLeftOperand() throws Exception {
@@ -52,6 +52,12 @@ public class FirIdeNormalAnalysisSourceModuleExpectedExpressionTypeTestGenerated
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("analysis/analysis-api/testData/components/expressionTypeProvider/expectedExpressionType"), Pattern.compile("^(.+)\\.kt$"), null, true);
}
@Test
@TestMetadata("annotationPositionalArgument.kt")
public void testAnnotationPositionalArgument() throws Exception {
runTest("analysis/analysis-api/testData/components/expressionTypeProvider/expectedExpressionType/annotationPositionalArgument.kt");
}
@Test
@TestMetadata("arrayAccessExpressionGet.kt")
public void testArrayAccessExpressionGet() throws Exception {
@@ -88,6 +94,12 @@ public class FirIdeNormalAnalysisSourceModuleExpectedExpressionTypeTestGenerated
runTest("analysis/analysis-api/testData/components/expressionTypeProvider/expectedExpressionType/conditionInWhenWithoutSubject.kt");
}
@Test
@TestMetadata("delegatedConstructorCall.kt")
public void testDelegatedConstructorCall() throws Exception {
runTest("analysis/analysis-api/testData/components/expressionTypeProvider/expectedExpressionType/delegatedConstructorCall.kt");
}
@Test
@TestMetadata("elvisExpressionLeftOperand.kt")
public void testElvisExpressionLeftOperand() throws Exception {
@@ -52,6 +52,12 @@ public class FirStandaloneNormalAnalysisSourceModuleExpectedExpressionTypeTestGe
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("analysis/analysis-api/testData/components/expressionTypeProvider/expectedExpressionType"), Pattern.compile("^(.+)\\.kt$"), null, true);
}
@Test
@TestMetadata("annotationPositionalArgument.kt")
public void testAnnotationPositionalArgument() throws Exception {
runTest("analysis/analysis-api/testData/components/expressionTypeProvider/expectedExpressionType/annotationPositionalArgument.kt");
}
@Test
@TestMetadata("arrayAccessExpressionGet.kt")
public void testArrayAccessExpressionGet() throws Exception {
@@ -88,6 +94,12 @@ public class FirStandaloneNormalAnalysisSourceModuleExpectedExpressionTypeTestGe
runTest("analysis/analysis-api/testData/components/expressionTypeProvider/expectedExpressionType/conditionInWhenWithoutSubject.kt");
}
@Test
@TestMetadata("delegatedConstructorCall.kt")
public void testDelegatedConstructorCall() throws Exception {
runTest("analysis/analysis-api/testData/components/expressionTypeProvider/expectedExpressionType/delegatedConstructorCall.kt");
}
@Test
@TestMetadata("elvisExpressionLeftOperand.kt")
public void testElvisExpressionLeftOperand() throws Exception {
@@ -0,0 +1,4 @@
annotation class A(val n: Int)
@A(a<caret>v)
class B
@@ -0,0 +1,5 @@
expression: av
expected type: KtUsualClassType:
annotationsList: []
ownTypeArguments: []
type: kotlin/Int
@@ -0,0 +1,5 @@
class Base(val p1: Int, val p2: Int)
class Derived(override val p1: Int, override val p2: Int) : Base(p1, p2) {
constructor(s: String) : this(s.length, a<caret>v)
}
@@ -0,0 +1,5 @@
expression: av
expected type: KtUsualClassType:
annotationsList: []
ownTypeArguments: []
type: kotlin/Int