Record Class ModelFiles

java.lang.Object
java.lang.Record
org.clafer.frontend.ModelFiles
Record Components:
files - the files, in order, the model last
options - the options of all the files, combined
errors - the compiler's errors of reading the files and combining their options; the files are empty if there is one

public record ModelFiles(List<ModelFiles.ModelFile> files, ModelOptions options, List<String> errors) extends Record
The files of a model: the model and the files it imports, transitively, with --import=FILE in their //# OPTIONS lines, as the compiler reads them (Import.readModel): local files and http or https URLs (Http). An import is relative to the folder or the URL of the importing file; the imported files come before the files that import them, each once, and the model last. The model is their concatenation, and a line of it is shown in its file (position(int)). The web tools' restrictions of the imports are ModelFiles.ImportOptions.
  • Field Details

  • Constructor Details

  • Method Details

    • of

      public static ModelFiles of(String path, String text)
      A model in one file, whose imports are not read: its text and options.
      Parameters:
      path - the path that the messages show, or empty
    • text

      public String text()
      Returns:
      the text of the model, the files in order
    • read

      public static ModelFiles read(String path, List<String> commandLineImports)
      Reads a model and the files it imports, local files and URLs.
      Parameters:
      path - the model's file or URL, as the messages show it
      commandLineImports - the imports given on the command line, relative to the working folder, which come first
    • read

      public static ModelFiles read(String path, List<String> commandLineImports, Function<String, Optional<String>> open)
      Reads a model and the local files it imports, taking the text of a file from open where it has one, e.g., a document open in an editor, and from disk otherwise. An import of a URL is an error (importsUrl()).
      Parameters:
      path - the model's file, as the messages show it
      commandLineImports - the imports given on the command line
      open - the text of a file, by its path as the model names it, if it is not to be read from disk
    • read

      public static ModelFiles read(String path, List<String> commandLineImports, Function<String, Optional<String>> open, ModelFiles.ImportOptions restrictions)
      Reads a model and the files it imports, as the compiler does (Import.readModel). The model is a file, a URL, or the standard input (Stdin, whose text open gives). The imports of the command line are relative to the working folder, and those of a file to its folder or URL, or, for the model, to --import-base. A file read from a URL may only import URLs.
      Parameters:
      path - the model's file or URL, as the messages show it
      commandLineImports - the imports given on the command line
      open - the text of a file, by its path, if it is not to be read
      restrictions - the restrictions of the imports
    • localName

      public static String localName(String path)
      The name of the model's file for its outputs: its path, or, for a URL, the last segment of its path (model.cfr if it has none), in the working folder.
    • importsUrl

      public boolean importsUrl()
      Returns:
      whether the model could not be read because it imports a URL, which was not to be read (ModelFiles.ImportOptions.readUrls)
    • isUrl

      public static boolean isUrl(String name)
      Returns:
      whether an import names a URL
    • position

      public ModelFiles.Position position(int line)
      Parameters:
      line - a line of the model, from 1
      Returns:
      the path of its file and its line in it
    • format

      public String format(Diagnostic d)
      Returns:
      the diagnostic at its position in its file, e.g., model.cfr:3:5: message, or without a path if the model has no name
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • files

      Returns the value of the files record component.
      Returns:
      the value of the files record component
    • options

      Returns the value of the options record component.
      Returns:
      the value of the options record component
    • errors

      public List<String> errors()
      Returns the value of the errors record component.
      Returns:
      the value of the errors record component