Interface ClassDeclarationModifier

All Known Implementing Classes:
JavaModifier, KotlinModifier

public interface ClassDeclarationModifier
Edits the header of a class — the annotations on it and the types it implements — without the caller knowing which language declared it.

It exists for one caller, and for one reason. What a theme is — an @StyleSheet naming the theme's constant, another naming styles.css, and AppShellConfigurator — is a decision about Vaadin, not about Java. Written once per language it would become two decisions, and the second copy would be the one nobody updates when a theme grows a third annotation. That is the argument StylePolicy made for styles, applied to the one other place Copilot writes a class header.

Deliberately not a general Kotlin-source-editing API. It has exactly the three operations applying a theme needs; anything else belongs to whichever feature needs it, with its own tests.

  • Method Details

    • forFile

      static ClassDeclarationModifier forFile(File sourceFile, String operation)
      The modifier for the language a source file is written in.

      The interface naming its own implementations is a small inversion, taken deliberately: there are two callers — applying a theme and adding the Lumo utility stylesheet — and a duplicated if/else over SourceLanguage is the thing most likely to answer differently in one place than the other, which is exactly what this interface exists to prevent.

      Parameters:
      sourceFile - the file declaring the class
      Returns:
      the modifier for that language
      Throws:
      UnsupportedSourceLanguageException - for a language with no modifier, which is what a Hilla-only project with a TypeScript entry point gets
    • modify

      Applies the operations to the source file declaring the given class.
      Parameters:
      cls - the class to modify
      operations - what to do to it
      Returns:
      the file and the source it should be given, which the caller writes. Returning the content rather than writing it is what lets a caller collect several files and write them under one undo label
      Throws:
      IOException - if the source cannot be read