Add KaResolver resolveSymbol/resolveCall support for a PSI type
This skill adds resolveSymbol() and optionally resolveCall() support for a given Kt* PSI type
by following the established pattern from existing resolver support commits.
The argument is the PSI type name, e.g. KtDestructuringDeclarationEntry.
Find the PSI type source file. Search compiler/psi/ for <KtPsiType>.java or <KtPsiType>.kt.
Read the file to understand the class hierarchy and whether it already implements KtResolvable or KtResolvableCall.
Check KaResolver for existing support. Read analysis/analysis-api/src/org/jetbrains/kotlin/analysis/api/components/KaResolver.kt
and search for the PSI type. If it already has resolveSymbol()/resolveCall() methods, inform the user and stop.
Check for existing test data. Search analysis/analysis-api/testData/components/resolver/ for test files
mentioning the PSI type or related scenarios.
Read the Analysis API AGENTS.md at analysis/AGENTS.md for area-specific guidelines.
Use AskUserQuestion to ask these questions (all in one call):
Header: "Resolution"
Question: "Should <KtPsiType> support symbol-only resolution (KtResolvable) or both symbol and call resolution (KtResolvableCall)?"
KtResolvable — symbol resolution only (resolveSymbol())KtResolvableCall — both symbol and call resolution (resolveSymbol() + resolveCall())Header: "Symbol type"
Question: "What should resolveSymbol() return for <KtPsiType>?"
KaConstructorSymbolKaFunctionSymbolKaNamedFunctionSymbolKaCallableSymbol(Allow "Other" for types like KaDeclarationSymbol, etc.)
KtResolvableCall)Header: "Call type"
Question: "What should resolveCall() return for <KtPsiType>?"
KaFunctionCall<KaConstructorSymbol>KaDelegatedConstructorCallKaAnnotationCallKaFunctionCall<KaNamedFunctionSymbol>(Allow "Other" for types like KaSingleCall<*, *>, KaFunctionCall<*>, etc.)
Use the answers from Phase 2 to determine: RESOLUTION_KIND (KtResolvable or KtResolvableCall),
SYMBOL_TYPE (e.g. KaCallableSymbol), and CALL_TYPE (e.g. KaSingleCall<*, *>).
File: The PSI source file found in Phase 1 (under compiler/psi/).
KtResolvable/KtResolvableCall, add it:
KtResolvable: add implements KtResolvable (Java) or : KtResolvable (Kotlin)KtResolvableCall: add implements KtResolvableCall (Java) or : KtResolvableCall (Kotlin)KtResolvableCall extends KtResolvable, so only one is needed.org.jetbrains.kotlin.resolution.KtResolvable or org.jetbrains.kotlin.resolution.KtResolvableCall).File: analysis/analysis-api/src/org/jetbrains/kotlin/analysis/api/components/KaResolver.kt
resolveSymbol() interface methodInsert after the last existing typed resolveSymbol() method (currently KtDestructuringDeclarationEntry.resolveSymbol())
and before tryResolveCall().
Follow the exact KDoc pattern — copy from a similar existing method and adapt:
/**
* Resolves the <description> by the given [<KtPsiType>].
*
* #### Example
*
* ```kotlin
* <code example with // ^^^^ markers>
* ```
*
* Calling `resolveSymbol()` on a [<KtPsiType>] ... returns the [<SYMBOL_TYPE>] ...
* if resolution succeeds; otherwise, it returns `null` (e.g., when unresolved or ambiguous).
*
* This is a specialized counterpart of [KtResolvable.resolveSymbol] focused specifically on <description>
*
* @see tryResolveSymbols
* @see KtResolvable.resolveSymbol
*/
@KaExperimentalApi
public fun <KtPsiType>.resolveSymbol(): <SYMBOL_TYPE>?
resolveCall() interface method (only if KtResolvableCall)Insert after the last existing typed resolveCall() method (currently KtDestructuringDeclarationEntry.resolveCall())
and before collectCallCandidates().
/**
* Resolves the given [<KtPsiType>] to a <call description>.
*
* #### Example
*
* ```kotlin
* <code example with // ^^^^ markers>
* ```
*
* Returns the corresponding [<CALL_TYPE short name>] if resolution succeeds; otherwise, it returns `null`
* (e.g., when unresolved or ambiguous).
*
* This is a specialized counterpart of [KtResolvableCall.resolveCall] focused specifically on <description>
*
* @see tryResolveCall
* @see KtResolvableCall.resolveCall
*/
@KaExperimentalApi
public fun <KtPsiType>.resolveCall(): <CALL_TYPE>?
resolveSymbol() bridge functionInsert after the last existing resolveSymbol bridge (currently KtDestructuringDeclarationEntry.resolveSymbol bridge)
and before the tryResolveCall bridge.
/**
* <Same KDoc as the interface method>
*/
// Auto-generated bridge. DO NOT EDIT MANUALLY!
@KaExperimentalApi
@KaContextParameterApi
context(session: KaSession)
public fun <KtPsiType>.resolveSymbol(): <SYMBOL_TYPE>? {
return with(session) {
resolveSymbol()
}
}
resolveCall() bridge function (only if KtResolvableCall)Insert after the last existing resolveCall bridge (currently KtDestructuringDeclarationEntry.resolveCall bridge)
and before the collectCallCandidates bridge.
/**
* <Same KDoc as the interface method>
*/
// Auto-generated bridge. DO NOT EDIT MANUALLY!
@KaExperimentalApi
@KaContextParameterApi
context(session: KaSession)
public fun <KtPsiType>.resolveCall(): <CALL_TYPE>? {
return with(session) {
resolveCall()
}
}
File: analysis/analysis-api-impl-base/src/org/jetbrains/kotlin/analysis/api/impl/base/components/KaBaseResolver.kt
resolveSymbol() override (always)Insert after the last existing resolveSymbolSafe() line (currently KtDestructuringDeclarationEntry.resolveSymbol())
and before KtReference.resolveToSymbol().
final override fun <KtPsiType>.resolveSymbol(): <SYMBOL_TYPE>? = resolveSymbolSafe()
resolveCall() override (only if KtResolvableCall)Insert after the last existing resolveCallSafe()/resolveSingleCallSafe() line
(currently KtDestructuringDeclarationEntry.resolveCall()) and before KtElement.resolveToCall().
Choose the helper based on the call return type:
*) → use resolveCallSafe():
final override fun <KtPsiType>.resolveCall(): <CALL_TYPE>? = resolveCallSafe()
resolveSingleCallSafe():
final override fun <KtPsiType>.resolveCall(): <CALL_TYPE>? = resolveSingleCallSafe()
canBeResolvedAsCall (only if KtResolvableCall)In the canBeResolvedAsCall function, add a new branch before else -> false:
is <KtPsiType> -> true
This step requires investigation — do NOT skip it.
Read the FIR resolver:
analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/components/KaFirResolver.ktThe FIR resolver works by calling getOrBuildFir(psi) and dispatching on the FIR element type in a when block.
Investigate:
getOrBuildFir(<KtPsiType instance>) return?when blocks of performSymbolResolution() and performCallResolution()?when, possibly with unwrapping logic).Examples of when FIR changes were needed:
KtDestructuringDeclarationEntry → maps to FirProperty (a declaration), needed to unwrap FirProperty.initializerKtLabelReferenceExpression → FIR doesn't have a dedicated label element, needed to extract from FirThisReceiverExpression.calleeReferenceKtConstructorDelegationReferenceExpression → needed to add FirReference as a handled caseKtReturnExpression → FirReturnExpression wasn't handled, added a new branch + helperSimilarly, read the FE10 resolver:
analysis/analysis-api-fe10/src/org/jetbrains/kotlin/analysis/api/descriptors/components/KaFe10Resolver.ktCheck if the BindingContext-based resolution handles the PSI type. Examples of needed changes:
KtCallableReferenceExpression → redirects to psi.callableReferenceKtWhenConditionInRange → redirects to psi.operationReferenceKtReturnExpression → custom logic to find enclosing function via parents()If changes are needed, implement them following the existing patterns in those files.
Run:
./gradlew :compiler:psi:psi-api:updateKotlinAbi
This updates compiler/psi/psi-api/api/psi-api.api to reflect the new interface implementation.
Run get_file_problems with errorsOnly=false on each modified file. Fix any warnings related to the changes.
./gradlew manageTestDataGlobally --mode=update --incremental --test-data-path=analysis/analysis-api/testData/components/resolver/
Read the newly generated/updated golden .txt files and sanity-check:
.symbol.txt — should contain KaSymbolResolutionSuccess with the expected symbol type matching SYMBOL_TYPE.references.txt — should contain KaSymbolResolutionSuccess with the expected symbol representing SYMBOL_TYPE.call.txt — (if KtResolvableCall) should contain KaCallResolutionSuccess with the expected call typenull or unexpected resolution failures, investigate whether FIR/FE10 changes (Step 4 in Phase 3) are missingFor quick investigation of individual tests, run on a specific subdirectory or file:
# By subdirectory
./gradlew manageTestDataGlobally --mode=check --golden-only --test-data-path=analysis/analysis-api/testData/components/resolver/singleByPsi/<specific-subdir>/
# By individual file
./gradlew manageTestDataGlobally --mode=check --test-data-path=analysis/analysis-api/testData/components/resolver/singleByPsi/<subdir>/TestName.kt
Create a commit with the message:
[Analysis API] resolver: support new API for `<KtPsiType>`
^KT-66039
Before committing, read docs/code_authoring_and_core_review.md for commit guidelines.