Class SourceLanguageCapabilities

java.lang.Object
com.vaadin.copilot.rewriter.SourceLanguageCapabilities

public final class SourceLanguageCapabilities extends Object
Which source-rewriting commands Copilot can perform, per language.

Published to the frontend so an action that cannot succeed is disabled before the user tries it. Copilot previously accepted every action and refused once the user had already dragged a component or typed a value, which reads as a bug rather than a limitation.

The command set here is the contract, not a description: JavaRewriteHandler is verified against it by SourceLanguageCapabilitiesTest, so a command cannot be registered without being declared, nor declared without being handled.

  • Field Details

    • ALL_COMMANDS

      public static final Set<String> ALL_COMMANDS
      Every source-rewriting command, matching the handlers registered by JavaRewriteHandler.
    • ROUTE_COMMANDS

      public static final Set<String> ROUTE_COMMANDS
      Route-editing commands, registered by RouteHandler.

      Declared separately from ALL_COMMANDS because the drift guard for that set checks JavaRewriteHandler's registry, which these are not part of: they rewrite a view's annotations rather than its component tree. Without them the Routes panel offered Save on a Kotlin view and threw when it was clicked.

    • EVERY_COMMAND

      public static final Set<String> EVERY_COMMAND
      Every command any language could support.
  • Method Details

    • isSupported

      public static boolean isSupported(SourceLanguage language, String command)
      Parameters:
      language - the language of the source to be rewritten
      command - the wire command name
      Returns:
      true if Copilot can perform this command on this language
    • supportedCommands

      public static Set<String> supportedCommands(SourceLanguage language)
      Parameters:
      language - the language of the source to be rewritten
      Returns:
      the commands supported for it, possibly empty
    • projectLanguages

      public static Set<SourceLanguage> projectLanguages()
      The languages this project has sources in, derived from its source folders.

      A project can have both, and often does: a Kotlin project created from a Java archetype keeps an empty src/main/java. So this is a set rather than a single "project language", and per-component language is what actually decides whether an operation can run.

      Returns:
      the languages, never empty — Java is assumed when nothing is detected
    • hasKotlinSources

      public static boolean hasKotlinSources()
      Returns:
      true if the project has Kotlin sources