[AA] Provide expected type for annotation entry argument
^KTIJ-19863
This commit is contained in:
committed by
teamcity
parent
fa6b1e24f9
commit
3477d35168
+12
@@ -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 {
|
||||
|
||||
+11
-8
@@ -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
|
||||
|
||||
+12
@@ -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 {
|
||||
|
||||
+12
@@ -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 {
|
||||
|
||||
+12
@@ -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 {
|
||||
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
annotation class A(val n: Int)
|
||||
|
||||
@A(a<caret>v)
|
||||
class B
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
expression: av
|
||||
expected type: KtUsualClassType:
|
||||
annotationsList: []
|
||||
ownTypeArguments: []
|
||||
type: kotlin/Int
|
||||
+5
@@ -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)
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
expression: av
|
||||
expected type: KtUsualClassType:
|
||||
annotationsList: []
|
||||
ownTypeArguments: []
|
||||
type: kotlin/Int
|
||||
Reference in New Issue
Block a user