HL API: Use array element type as type of vararg KtValueParameterSymbol.
This commit is contained in:
committed by
Ilya Kirillov
parent
8dd40cb398
commit
f4c5f02bfe
+16
-2
@@ -8,9 +8,13 @@ package org.jetbrains.kotlin.idea.frontend.api.fir.symbols
|
|||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
|
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirValueParameter
|
import org.jetbrains.kotlin.fir.declarations.FirValueParameter
|
||||||
|
import org.jetbrains.kotlin.fir.renderWithType
|
||||||
|
import org.jetbrains.kotlin.fir.types.arrayElementType
|
||||||
|
import org.jetbrains.kotlin.fir.types.coneType
|
||||||
import org.jetbrains.kotlin.idea.fir.findPsi
|
import org.jetbrains.kotlin.idea.fir.findPsi
|
||||||
import org.jetbrains.kotlin.idea.fir.low.level.api.api.FirModuleResolveState
|
import org.jetbrains.kotlin.idea.fir.low.level.api.api.FirModuleResolveState
|
||||||
import org.jetbrains.kotlin.idea.frontend.api.fir.KtSymbolByFirBuilder
|
import org.jetbrains.kotlin.idea.frontend.api.fir.KtSymbolByFirBuilder
|
||||||
|
import org.jetbrains.kotlin.idea.frontend.api.fir.symbols.annotations.KtFirAnnotationCall
|
||||||
import org.jetbrains.kotlin.idea.frontend.api.fir.symbols.annotations.containsAnnotation
|
import org.jetbrains.kotlin.idea.frontend.api.fir.symbols.annotations.containsAnnotation
|
||||||
import org.jetbrains.kotlin.idea.frontend.api.fir.symbols.annotations.getAnnotationClassIds
|
import org.jetbrains.kotlin.idea.frontend.api.fir.symbols.annotations.getAnnotationClassIds
|
||||||
import org.jetbrains.kotlin.idea.frontend.api.fir.symbols.annotations.toAnnotationsList
|
import org.jetbrains.kotlin.idea.frontend.api.fir.symbols.annotations.toAnnotationsList
|
||||||
@@ -38,8 +42,18 @@ internal class KtFirValueParameterSymbol(
|
|||||||
|
|
||||||
override val name: Name get() = firRef.withFir { it.name }
|
override val name: Name get() = firRef.withFir { it.name }
|
||||||
override val isVararg: Boolean get() = firRef.withFir { it.isVararg }
|
override val isVararg: Boolean get() = firRef.withFir { it.isVararg }
|
||||||
override val annotatedType: KtTypeAndAnnotations by cached {
|
override val annotatedType: KtTypeAndAnnotations by firRef.withFirAndCache(FirResolvePhase.TYPES) { fir ->
|
||||||
firRef.returnTypeAndAnnotations(FirResolvePhase.TYPES, builder)
|
if (fir.isVararg) {
|
||||||
|
val annotations = fir.returnTypeRef.annotations.map { annotation ->
|
||||||
|
KtFirAnnotationCall(firRef, annotation)
|
||||||
|
}
|
||||||
|
// There SHOULD always be an array element type (even if it is an error type, e.g., unresolved).
|
||||||
|
val arrayElementType = fir.returnTypeRef.coneType.arrayElementType()
|
||||||
|
?: error("No array element type for vararg value parameter: ${fir.renderWithType()}")
|
||||||
|
KtSimpleFirTypeAndAnnotations(arrayElementType, annotations, builder, firRef.token)
|
||||||
|
} else {
|
||||||
|
firRef.returnTypeAndAnnotations(FirResolvePhase.TYPES, builder)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override val hasDefaultValue: Boolean get() = firRef.withFir { it.defaultValue != null }
|
override val hasDefaultValue: Boolean get() = firRef.withFir { it.defaultValue != null }
|
||||||
|
|||||||
Vendored
+2
-2
@@ -1,3 +1,3 @@
|
|||||||
KtFunctionCall:
|
KtFunctionCall:
|
||||||
argumentMapping = { args -> (vararg a: kotlin.IntArray) }
|
argumentMapping = { args -> (vararg a: kotlin.Int) }
|
||||||
targetFunction = /function(vararg a: kotlin.IntArray): kotlin.Unit
|
targetFunction = /function(vararg a: kotlin.Int): kotlin.Unit
|
||||||
Vendored
+2
-2
@@ -1,3 +1,3 @@
|
|||||||
KtFunctionCall:
|
KtFunctionCall:
|
||||||
argumentMapping = { 1 -> (vararg a: kotlin.IntArray), 2 -> (vararg a: kotlin.IntArray), 3 -> (vararg a: kotlin.IntArray) }
|
argumentMapping = { 1 -> (vararg a: kotlin.Int), 2 -> (vararg a: kotlin.Int), 3 -> (vararg a: kotlin.Int) }
|
||||||
targetFunction = /function(vararg a: kotlin.IntArray): kotlin.Unit
|
targetFunction = /function(vararg a: kotlin.Int): kotlin.Unit
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
fun primitive(vararg a: Int)
|
||||||
|
fun nullablePrimitive(vararg b: Float?)
|
||||||
|
fun nonPrimitive(vararg c: Any)
|
||||||
|
fun error(vararg d: Unresolved)
|
||||||
@@ -0,0 +1,163 @@
|
|||||||
|
KtFirValueParameterSymbol:
|
||||||
|
annotatedType: [] kotlin/Int
|
||||||
|
annotationClassIds: []
|
||||||
|
annotations: []
|
||||||
|
callableIdIfNonLocal: null
|
||||||
|
hasDefaultValue: false
|
||||||
|
isExtension: false
|
||||||
|
isVararg: true
|
||||||
|
name: a
|
||||||
|
origin: SOURCE
|
||||||
|
receiverType: null
|
||||||
|
symbolKind: LOCAL
|
||||||
|
deprecationStatus: null
|
||||||
|
|
||||||
|
KtFirFunctionSymbol:
|
||||||
|
annotatedType: [] kotlin/Unit
|
||||||
|
annotationClassIds: []
|
||||||
|
annotations: []
|
||||||
|
callableIdIfNonLocal: /primitive
|
||||||
|
dispatchType: null
|
||||||
|
hasStableParameterNames: true
|
||||||
|
isExtension: false
|
||||||
|
isExternal: false
|
||||||
|
isInfix: false
|
||||||
|
isInline: false
|
||||||
|
isOperator: false
|
||||||
|
isOverride: false
|
||||||
|
isStatic: false
|
||||||
|
isSuspend: false
|
||||||
|
modality: FINAL
|
||||||
|
name: primitive
|
||||||
|
origin: SOURCE
|
||||||
|
receiverType: null
|
||||||
|
symbolKind: TOP_LEVEL
|
||||||
|
typeParameters: []
|
||||||
|
valueParameters: [
|
||||||
|
KtFirValueParameterSymbol(a)
|
||||||
|
]
|
||||||
|
visibility: Public
|
||||||
|
deprecationStatus: null
|
||||||
|
|
||||||
|
KtFirValueParameterSymbol:
|
||||||
|
annotatedType: [] kotlin/Float?
|
||||||
|
annotationClassIds: []
|
||||||
|
annotations: []
|
||||||
|
callableIdIfNonLocal: null
|
||||||
|
hasDefaultValue: false
|
||||||
|
isExtension: false
|
||||||
|
isVararg: true
|
||||||
|
name: b
|
||||||
|
origin: SOURCE
|
||||||
|
receiverType: null
|
||||||
|
symbolKind: LOCAL
|
||||||
|
deprecationStatus: null
|
||||||
|
|
||||||
|
KtFirFunctionSymbol:
|
||||||
|
annotatedType: [] kotlin/Unit
|
||||||
|
annotationClassIds: []
|
||||||
|
annotations: []
|
||||||
|
callableIdIfNonLocal: /nullablePrimitive
|
||||||
|
dispatchType: null
|
||||||
|
hasStableParameterNames: true
|
||||||
|
isExtension: false
|
||||||
|
isExternal: false
|
||||||
|
isInfix: false
|
||||||
|
isInline: false
|
||||||
|
isOperator: false
|
||||||
|
isOverride: false
|
||||||
|
isStatic: false
|
||||||
|
isSuspend: false
|
||||||
|
modality: FINAL
|
||||||
|
name: nullablePrimitive
|
||||||
|
origin: SOURCE
|
||||||
|
receiverType: null
|
||||||
|
symbolKind: TOP_LEVEL
|
||||||
|
typeParameters: []
|
||||||
|
valueParameters: [
|
||||||
|
KtFirValueParameterSymbol(b)
|
||||||
|
]
|
||||||
|
visibility: Public
|
||||||
|
deprecationStatus: null
|
||||||
|
|
||||||
|
KtFirValueParameterSymbol:
|
||||||
|
annotatedType: [] kotlin/Any
|
||||||
|
annotationClassIds: []
|
||||||
|
annotations: []
|
||||||
|
callableIdIfNonLocal: null
|
||||||
|
hasDefaultValue: false
|
||||||
|
isExtension: false
|
||||||
|
isVararg: true
|
||||||
|
name: c
|
||||||
|
origin: SOURCE
|
||||||
|
receiverType: null
|
||||||
|
symbolKind: LOCAL
|
||||||
|
deprecationStatus: null
|
||||||
|
|
||||||
|
KtFirFunctionSymbol:
|
||||||
|
annotatedType: [] kotlin/Unit
|
||||||
|
annotationClassIds: []
|
||||||
|
annotations: []
|
||||||
|
callableIdIfNonLocal: /nonPrimitive
|
||||||
|
dispatchType: null
|
||||||
|
hasStableParameterNames: true
|
||||||
|
isExtension: false
|
||||||
|
isExternal: false
|
||||||
|
isInfix: false
|
||||||
|
isInline: false
|
||||||
|
isOperator: false
|
||||||
|
isOverride: false
|
||||||
|
isStatic: false
|
||||||
|
isSuspend: false
|
||||||
|
modality: FINAL
|
||||||
|
name: nonPrimitive
|
||||||
|
origin: SOURCE
|
||||||
|
receiverType: null
|
||||||
|
symbolKind: TOP_LEVEL
|
||||||
|
typeParameters: []
|
||||||
|
valueParameters: [
|
||||||
|
KtFirValueParameterSymbol(c)
|
||||||
|
]
|
||||||
|
visibility: Public
|
||||||
|
deprecationStatus: null
|
||||||
|
|
||||||
|
KtFirValueParameterSymbol:
|
||||||
|
annotatedType: [] ERROR CLASS: Symbol not found for Unresolved
|
||||||
|
annotationClassIds: []
|
||||||
|
annotations: []
|
||||||
|
callableIdIfNonLocal: null
|
||||||
|
hasDefaultValue: false
|
||||||
|
isExtension: false
|
||||||
|
isVararg: true
|
||||||
|
name: d
|
||||||
|
origin: SOURCE
|
||||||
|
receiverType: null
|
||||||
|
symbolKind: LOCAL
|
||||||
|
deprecationStatus: null
|
||||||
|
|
||||||
|
KtFirFunctionSymbol:
|
||||||
|
annotatedType: [] kotlin/Unit
|
||||||
|
annotationClassIds: []
|
||||||
|
annotations: []
|
||||||
|
callableIdIfNonLocal: /error
|
||||||
|
dispatchType: null
|
||||||
|
hasStableParameterNames: true
|
||||||
|
isExtension: false
|
||||||
|
isExternal: false
|
||||||
|
isInfix: false
|
||||||
|
isInline: false
|
||||||
|
isOperator: false
|
||||||
|
isOverride: false
|
||||||
|
isStatic: false
|
||||||
|
isSuspend: false
|
||||||
|
modality: FINAL
|
||||||
|
name: error
|
||||||
|
origin: SOURCE
|
||||||
|
receiverType: null
|
||||||
|
symbolKind: TOP_LEVEL
|
||||||
|
typeParameters: []
|
||||||
|
valueParameters: [
|
||||||
|
KtFirValueParameterSymbol(d)
|
||||||
|
]
|
||||||
|
visibility: Public
|
||||||
|
deprecationStatus: null
|
||||||
+6
@@ -173,4 +173,10 @@ public class SymbolByPsiTestGenerated extends AbstractSymbolByPsiTest {
|
|||||||
public void testTypeAnnotations() throws Exception {
|
public void testTypeAnnotations() throws Exception {
|
||||||
runTest("idea/idea-frontend-fir/testData/symbols/symbolByPsi/typeAnnotations.kt");
|
runTest("idea/idea-frontend-fir/testData/symbols/symbolByPsi/typeAnnotations.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("varargFunctions.kt")
|
||||||
|
public void testVarargFunctions() throws Exception {
|
||||||
|
runTest("idea/idea-frontend-fir/testData/symbols/symbolByPsi/varargFunctions.kt");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user