AGENTS.md
analysis/AGENTS.mdAGENTS.md
Quality
86/100
Scores the file, not the repository.Length
668 words
14 headings · 3 code blocksRepository
53k
— · pushed 0 days agoLast changed
3 days ago
First indexed 3 days ago.1# Analysis API Guidelines23A library for analyzing Kotlin code at the semantic level, providing structured access to symbols, types, and semantic relationships.45**Entry point:** Use [`analyze()`](analysis-api/src/org/jetbrains/kotlin/analysis/api/analyze.kt) to start an analysis session. See [Analysis API documentation](https://kotl.in/analysis-api) for a usage guide.67## Architecture89- **Platform** — Provides declarations, project structure, and modification events (IntelliJ, Standalone)10- **Engine** — Performs code analysis using platform-provided information (K1, K2)11- **User** — Code that calls `analyze()` to work with symbols and types1213→ READ [`analysis-api-platform-interface/README.md`](analysis-api-platform-interface/README.md) for detailed architecture overview1415## Relationship with PSI1617Analysis API builds on top of Kotlin PSI (`compiler/psi/`):18- **PSI** provides syntax (structure of code): `KtElement`, `KtExpression`, `KtDeclaration`19- **Analysis API** provides semantics (meaning of code): `KaSymbol`, `KaType`2021```22PSI (syntax) → Analysis API (semantics) → Symbols, Types, Resolution23```2425**Both PSI and Analysis API follow shared development principles** documented in [`docs/contribution-guide/api-development.md`](docs/contribution-guide/api-development.md).2627WHEN working with PSI elements:28→ READ [`compiler/psi/AGENTS.md`](../compiler/psi/AGENTS.md) for PSI-specific rules and conventions2930## Key Conventions3132- `Ka` prefix for Analysis API types, `Kt` for PSI types33- Prefer interfaces to classes for better binary compatibility34- Properties for attributes, functions for actions with parameters35- Return nullable types for operations that can fail (avoid exceptions for non-exceptional cases)36- All implementations must validate lifetime ownership with `withValidityAssertion`37- Mark experimental APIs with `@KaExperimentalApi`, implementation details with `@KaImplementationDetail`3839## Working with Test Data4041When modifying test data files or running generated tests (`*Generated`) that compare output against `.txt` files, use `updateTestData` (to rewrite files) or `checkTestData` (to verify only) instead of standard test commands. Both take their options as `-P` properties, so changing filters between runs stays fast.4243### `updateTestData` — the only recommended way to update test data4445```bash46# Update test data by directory (preferred for iteration)47./gradlew updateTestData -Porg.jetbrains.kotlin.testDataManager.options.testDataPath=analysis/analysis-api/testData/components/resolver/4849# Update test data by test class pattern50./gradlew updateTestData -Porg.jetbrains.kotlin.testDataManager.options.testClassPattern=.*ResolveTest.*5152# Run only golden tests (useful for quick baseline updates)53./gradlew updateTestData -Porg.jetbrains.kotlin.testDataManager.options.goldenOnly=true5455# Incremental update — only re-run variant tests for changed paths56./gradlew updateTestData -Porg.jetbrains.kotlin.testDataManager.options.incremental=true5758# Limit to a subset of modules using task paths (Gradle task-name matching)59./gradlew :analysis:analysis-api-fir:updateTestData :analysis:stubs:updateTestData60```6162`updateTestData` is fixed to update mode. There is no `updateTestDataGlobally` — Gradle's task-name matching runs the task in every applicable subproject when invoked from the repo root.6364### `checkTestData` — verification only6566If you specifically need to verify that existing test data is consistent without modifying anything (e.g., sanity-checking generated files after an `updateTestData` run), use `checkTestData`. It is the exact `-P`-driven counterpart of `updateTestData` but fixed to check mode: it fails on any mismatch and writes nothing.6768```bash69./gradlew checkTestData -Porg.jetbrains.kotlin.testDataManager.options.testDataPath=analysis/analysis-api/testData/components/resolver/singleByPsi/70```7172Use this only for verification. For any workflow that writes test data, use `updateTestData`.7374**Why use these tasks instead of plain `:test`?**75- Run only relevant tests (filtered by path or class pattern)76- Handle variant chains correctly (golden `.txt` files run before variant-specific `.js.txt`, `.wasm.txt`, etc.)77- Automatically discover all modules that use managed test data78- Detect and remove redundant variant files7980For full options, see [test-data-manager-convention](../repo/gradle-build-conventions/test-data-manager-convention/README.md).8182## Key Components8384- [`analysis-api/`](analysis-api) - User-facing API surface (`KaSession`, `KaSymbol`, `KaType`)85- [`analysis-api-platform-interface/`](analysis-api-platform-interface) - Platform abstraction (declaration providers, project structure, lifetime)86- [`analysis-api-standalone/`](analysis-api-standalone) - CLI-based implementation of the Analysis API87- [`analysis-api-fir/`](analysis-api-fir) - K2 implementation based on FIR88- [`analysis-api-impl-base/`](analysis-api-impl-base) - Shared implementation utilities89- [`low-level-api-fir/`](low-level-api-fir) - K2-specific infrastructure for lazy/incremental analysis90- [`symbol-light-classes/`](symbol-light-classes) - Java PSI view of Kotlin declarations for interop91- [`decompiled/light-classes-for-decompiled`](decompiled/light-classes-for-decompiled) - Light classes for decompiled/library code92- [`test-data-manager/`](test-data-manager) - Infrastructure for managing test data files with variant chains9394## Detailed Documentation9596WHEN adding or modifying API endpoints:97→ READ [`docs/contribution-guide/api-development.md`](docs/contribution-guide/api-development.md)9899WHEN deprecating API or understanding stability categories:100→ READ [`docs/contribution-guide/api-evolution.md`](docs/contribution-guide/api-evolution.md)101102WHEN implementing platform components:103→ READ [`analysis-api-platform-interface/README.md`](analysis-api-platform-interface/README.md)104105WHEN working with light classes:106→ READ [`symbol-light-classes/README.md`](symbol-light-classes/README.md)107108WHEN working with lazy resolution (LL API):109→ READ [`low-level-api-fir/README.md`](low-level-api-fir/README.md)110111WHEN writing or managing test data files:112→ READ [`test-data-manager/AGENTS.md`](test-data-manager/AGENTS.md)113114WHEN seeking historical context on design decisions:115→ READ [`docs/design-documents/README.md`](docs/design-documents/README.md) (these are historical snapshots, not necessarily up to date)116117WHEN working with stubs:118→ READ [`stubs/README.md`](stubs/README.md)119
Also in JetBrains/kotlin
Diff this repo’s formatsOne repository carrying more than one format is the comparison this product exists for: does anyone actually write different content in each file, or is one a copy of the other?
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| JetBrains/kotlincompiler/AGENTS.md · 53k | AGENTS.md | buildtestgit | 52/100 | 3 days ago | |
| JetBrains/kotlincompiler/build-tools/AGENTS.md · 53k | AGENTS.md | buildteststylearch+2 | 89/100 | 3 days ago | |
| JetBrains/kotlinCLAUDE.md · 53k | CLAUDE.md | agent-behaviour | 25/100 | 3 days ago | |
| JetBrains/kotlinanalysis/test-data-manager/AGENTS.md · 53k | AGENTS.md | teststylearchagent-behaviour | 66/100 | 3 days ago | |
| JetBrains/kotlincompiler/fir/analysis-tests/AGENTS.md · 53k | AGENTS.md | testlint-formatarchdeployment | 74/100 | 3 days ago | |
| JetBrains/kotlincompiler/psi/AGENTS.md · 53k | AGENTS.md | teststylearchtesting-strategy+3 | 81/100 | 3 days ago |
Similar configs
Same format, overlapping stack, ranked by quality.
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| elastic/elasticsearchx-pack/plugin/inference/AGENTS.md · 78k | AGENTS.md | buildtestlint-formatstyle+3 | 100/100 | 3 days ago | |
| elastic/elasticsearchx-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/AGENTS.md · 78k | AGENTS.md | buildtestlint-formatstyle+2 | 100/100 | 3 days ago | |
| react/react-nativepackages/react-native-compatibility-check/AGENTS.md · 126k | AGENTS.md | testlint-formatstylearch+4 | 99/100 | 3 days ago | |
| kurikomi-labs/komi-storeAGENTS.md · 17k | AGENTS.md | buildlint-formatstylearch+1 | 97/100 | 3 days ago | |
| tiann/KernelSUAGENTS.md · 18k | AGENTS.md | setupbuildlint-formatstyle+4 | 97/100 | 3 days ago | |
| elastic/elasticsearchAGENTS.md · 78k | AGENTS.md | buildtestlint-formatstyle+6 | 96/100 | 3 days ago | |
| alibaba/nacosAGENTS.md · 33k | AGENTS.md | buildtestlint-formatstyle+6 | 96/100 | 3 days ago | |
| ktorio/ktorAGENTS.md · 14k | AGENTS.md | buildlint-formatstylearch+7 | 96/100 | 3 days ago |
