Class LanguageCatalog

java.lang.Object
io.github.sergeloie.languagecheck.model.LanguageCatalog

public final class LanguageCatalog extends Object
Lazy registry of Language definitions plus the global formatting code points.

Built-in languages live in /languages/<code>.json; the global formatting list in /languages/formatting.json. A language's file is parsed only when it is first requested via language(String) - the plugin reads just the single file it needs.

User-supplied languages are registered per code as a map of code → file via load(Map). Files are validated lazily: the code key must match the code declared inside the file (fail-fast on first access), and the file's code/name/chars must be well-formed.

  • Method Details

    • loadDefaults

      public static LanguageCatalog loadDefaults()
      Catalog with only the built-in languages and formatting.
      Throws:
      IllegalStateException - if a resource is missing or malformed
    • load

      public static LanguageCatalog load(Map<String,File> customLanguages)
      Catalog with the built-in languages plus user-supplied per-code files.

      Files are not read here - only their codes are registered; parsing happens lazily on language(String) so a bad file fails only when its language is actually requested.

      Parameters:
      customLanguages - code → file; null and empty map mean "defaults only"
      Throws:
      IllegalArgumentException - if any code key is blank, its file is null, or the file is not an existing regular file
    • language

      public Language language(String code)
      Look up a language by its code; returns null if not present.

      Lazy: the first call for a code parses its file (built-in resource or user-supplied file) and caches the result; later calls are map lookups.

      Throws:
      IllegalArgumentException - if a user-supplied file is missing, has a code mismatch, or is malformed
      IllegalStateException - if a built-in resource is missing or malformed
    • codes

      public Set<String> codes()
      All registered language codes (built-ins plus custom), insertion order.
    • languages

      public Map<String,Language> languages()
      All languages, keyed by code.

      Eager: calling this parses every registered language. Use codes() when only the codes are needed (error messages, report header), so no files are read unnecessarily.

    • formatting

      public int[] formatting()
      Global formatting code points (sorted, unique, int[]).
    • isFormattingCodePoint

      public boolean isFormattingCodePoint(int codePoint)
      True if codePoint is in the global formatting set.