Enum Class SourceLanguage

java.lang.Object
java.lang.Enum<SourceLanguage>
com.vaadin.copilot.rewriter.SourceLanguage
All Implemented Interfaces:
Serializable, Comparable<SourceLanguage>, Constable

public enum SourceLanguage extends Enum<SourceLanguage>
A source language Copilot can read and, depending on the operation, rewrite.

Copilot previously expressed this as a set of Kotlin-specific predicates (KotlinUtil.isKotlin, isKotlinSourcePath) which could only answer "is this Kotlin?". Naming the languages instead lets callers pick a rewriter, choose an extension when generating a file, and report the language to the frontend.

  • Enum Constant Details

  • Method Details

    • values

      public static SourceLanguage[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static SourceLanguage valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null
    • wireName

      public String wireName()
      Stable identifier used in messages sent to the frontend. Also the conventional Maven/Gradle source folder name, as in src/main/<wireName>.
      Returns:
      the wire name, java or kotlin
    • displayName

      public String displayName()
      Returns:
      the language name as shown to the user
    • primaryExtension

      public String primaryExtension()
      The extension to use when Copilot generates a new file for this language. Kotlin recognises both kt and kts but only ever generates kt.
      Returns:
      the extension, without the leading dot
    • extensions

      public List<String> extensions()
      Returns:
      every file extension belonging to this language, without leading dots
    • matches

      public boolean matches(File file)
      Checks whether the given file belongs to this language, by extension.
      Parameters:
      file - the file to check, may be null
      Returns:
      true if the file has one of this language's extensions
    • matches

      public boolean matches(String fileName)
      Checks whether the given file name belongs to this language, by extension.
      Parameters:
      fileName - the file name to check, may be null
      Returns:
      true if the name has one of this language's extensions
    • forFile

      public static Optional<SourceLanguage> forFile(File file)
      Determines the language of a source file from its extension.
      Parameters:
      file - the file, may be null
      Returns:
      the language, or empty for null and for extensions belonging to no known language (a TypeScript view, for instance)
    • forFileName

      public static Optional<SourceLanguage> forFileName(String fileName)
      Determines the language of a source file from its name.
      Parameters:
      fileName - the file name, may be null
      Returns:
      the language, or empty if the extension belongs to no known language
    • forSourceFolder

      public static Optional<SourceLanguage> forSourceFolder(Path folder)
      Determines the language of a source folder from its path, by looking for a path segment named after a language. This follows the Maven and Gradle convention of src/main/java and src/main/kotlin.

      The segment must match exactly, so src/main/kotlinx is not Kotlin.

      Parameters:
      folder - the source folder, may be null
      Returns:
      the language, or empty if no segment names a language