Files
codeql/java
Anders Fugmann ae68d36147 Kotlin: read KDoc sections via Kotlin PSI, not com.intellij.psi navigation
The previous two commits removed the `ProcessCanceledException` and
`PsiTreeUtil` references from KDoc-section parsing, but the internal extractor
build then failed on `unresolved reference 'PsiElement'`: the hand-written tree
walk named `com.intellij.psi.PsiElement` (and its `firstChild`/`nextSibling`).

The root cause is that the LighterAST/K2 comment extractor is compiled against a
curated classpath that deliberately excludes `com.intellij.psi.*`. It exposes
only the `com.intellij.lang` LighterAST API (`LighterASTNode`,
`FlyweightCapableTreeStructure`) plus the Kotlin PSI classes
(`org.jetbrains.kotlin.psi.*`, `...kdoc.psi.*`). That is why `KtPsiFactory`,
`KtFile`, `KDoc` and `getAllSections` all resolve while any `com.intellij.psi`
reference does not. The full standalone builds bundle the whole classpath, so
they never caught this.

Locate the parsed KDoc through the Kotlin PSI API instead: the KDoc attaches to
the throwaway `val __codeql_kdoc__` as its `docComment`, so
`ktFile.declarations.firstOrNull()?.docComment` retrieves it using only
`org.jetbrains.kotlin.psi` types (`KtCommonFile.getDeclarations`,
`KtDeclaration.getDocComment`). No `com.intellij.psi` symbol remains in the
file's code. Behaviour is unchanged: the parsed input is a single KDoc comment
followed by one declaration, so its `docComment` is exactly the KDoc the old
descendant search returned.

No expected-output changes. Verified the standalone extractor builds for
1.9.0-Beta and 2.4.0.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-07-14 11:49:33 +02:00
..