Class KotlinFileSourceProvider

java.lang.Object
com.vaadin.copilot.kotlinrewriter.KotlinFileSourceProvider

public class KotlinFileSourceProvider extends Object
Serves and saves parsed Kotlin sources for one operation.

The Kotlin counterpart of JavaFileSourceProvider, and separate from it on purpose: that class is named for what it does and keeps throwing for .kt, which is what makes every handler Copilot has not ported yet — the i18n plugin, Lit templates, the theme editor — refuse cleanly for Kotlin without a line of code each. Merging the two into one SourceFileProvider is worth doing, but it renames 121 references and belongs in a change of its own rather than buried in this one.

Caching by path is what makes several edits to one file accumulate: each KotlinSource owns a single edit buffer, so two properties set in one batch splice into the same text and are written once. Handing out a fresh parse per lookup would mean the second edit silently discarded the first.

  • Constructor Details

    • KotlinFileSourceProvider

      public KotlinFileSourceProvider()
  • Method Details

    • getSource

      public KotlinSource getSource(File file) throws IOException
      The parsed source for a file, reading and parsing it on first use.
      Parameters:
      file - the Kotlin file
      Returns:
      the parsed source, the same instance for the same file
      Throws:
      IOException - if the file cannot be read
    • saveChangedSources

      public void saveChangedSources()
      Writes every source this operation changed.

      Iterates the cache rather than following a component's create and attach locations, which is how the Java path decides what to save and why a rewriter that touches a third file there silently fails to write it.

    • setWriteMode

      public void setWriteMode(boolean writeMode)
      Parameters:
      writeMode - false to collect edits without writing them, true to write on the next saveChangedSources()