Interface Container

All Superinterfaces:
AutoCloseable, Closeable

@API(since="0.0.1", status=STABLE) public interface Container extends Closeable
Container that wraps a file path source of some description.

Closing this resource will close any internally held resources that were opened internally. Already-opened resources passed to the implementation will not be closed.

Since:
0.0.1
Author:
Ashley Scopes
  • Method Details

    • contains

      boolean contains(PathFileObject fileObject)
      Determine if this container contains the path file object.
      Parameters:
      fileObject - the file object to look up.
      Returns:
      true if the object exists in this container, or false otherwise.
    • getFile

      Path getFile(String fragment, String... fragments)
      Find the physical path to a given string file path.

      Examples:

      
         // Using platform-specific separators ('/' for in-memory file systems).
         container.getFile("foo/bar/baz.txt");
      
         // Letting JCT infer the correct path separators to use.
         container.getFile("foo", "bar", "baz.txt");
       
      Parameters:
      fragment - the first part of the file name.
      fragments - any additional parts of the file name to find.
      Returns:
      the path if the file exists, or null if it does not exist.
    • getFileForInput

      PathFileObject getFileForInput(String packageName, String relativeName)
      Get a FileObject for reading, if it exists.

      If the file does not exist, null is returned.

      Parameters:
      packageName - the package name of the file.
      relativeName - the relative name of the file in the package.
      Returns:
      the file object, or null if it does not exist.
    • getFileForOutput

      PathFileObject getFileForOutput(String packageName, String relativeName)
      Get a FileObject for writing.

      If the container is read-only, null is returned.

      Parameters:
      packageName - the package name of the file.
      relativeName - the relative name of the file in the package.
      Returns:
      the file object, or null if this container is read-only.
    • getJavaFileForInput

      Get a JavaFileObject for reading, if it exists.

      If the file does not exist, null is returned.

      Parameters:
      className - the binary name of the class to open.
      kind - the kind of file to open.
      Returns:
      the file object, or null if it does not exist.
    • getJavaFileForOutput

      Get a JavaFileObject for writing.

      If the container is read-only, null is returned.

      Parameters:
      className - the binary name of the class to open.
      kind - the kind of file to open.
      Returns:
      the file object, or null if this container is read-only.
    • getLocation

      Get the location of this container.
      Returns:
      the location.
    • getModuleFinder

      Get a module finder for this container.

      Note that this will not detect modules that are not yet compiled.

      Returns:
      the module finder for this container, or null if not relevant to the implementation.
    • getName

      Get the name of this container for human consumption.
      Returns:
      the container name.
    • getPathRoot

      Get the path root of the container.
      Returns:
      the path root.
    • inferBinaryName

      Infer the binary name of a given Java file object.
      Parameters:
      javaFileObject - the Java file object to infer the binary name of.
      Returns:
      the name, or null if the file does not exist in this container.
    • listAllFiles

      List all files within this container.
      Returns:
      all files within the container, relative to the container base path.
      Throws:
      IOException - if the file system failed to be read.
    • listFileObjects

      void listFileObjects(String packageName, Set<? extends JavaFileObject.Kind> kinds, boolean recurse, Collection<JavaFileObject> collection) throws IOException
      List all the file objects that match the given criteria in this group.

      The results are filled into a given collection, since this call may be made many times per compliation, and this reduces the memory overhead needed in such cases.

      Parameters:
      packageName - the package name to look in.
      kinds - the kinds of file to look for. Set to Set.of(Kind.OTHER) to find all types of file.
      recurse - true to recurse subpackages, false to only consider the given package.
      collection - the collection to fill.
      Throws:
      IOException - if the file system failed to be read.