Class KotlinPsi

java.lang.Object
com.vaadin.copilot.kotlinrewriter.psi.KotlinPsi

public final class KotlinPsi extends Object
Parses Kotlin source into a PSI tree.

The only class in Copilot permitted to import org.jetbrains.kotlin.*. Everything else works through

invalid reference
KtNodeRef
and the rewriter interfaces, so the parser stays replaceable and the shade filter has one place to be checked against.

Uses the lightweight PSI path — CoreApplicationEnvironment plus a KotlinParserDefinition — and deliberately not KotlinCoreEnvironment.createForProduction, which loads the whole compiler frontend and its extension registry for no benefit here: Copilot needs exact source offsets, not resolved types. Types come from reflection on the live component instead.

Measured on this path: ~240 ms one-off environment setup, ~1.2 ms to parse a typical view, ~2 MB retained heap. See kotlin-support/PHASE-0-FINDINGS.md.

  • Method Details

    • parse

      public static org.jetbrains.kotlin.psi.KtFile parse(String fileName, String text)
      Parses Kotlin source text.

      The returned tree must not be retained past the operation that asked for it: it holds the whole PSI graph alive, and this class keeps its environment for the lifetime of the JVM.

      Parameters:
      fileName - the file's name, used only for messages and to pick the parser
      text - the source
      Returns:
      the parsed file