Class ModuleImportDeclarationsExamples

java.lang.Object
net.jrodolfo.java_evolution.java25.ModuleImportDeclarationsExamples

public class ModuleImportDeclarationsExamples extends Object
Demonstrates module import declarations, finalized in Java 25.

Module import declarations are source-level syntax, so this example writes temporary source files and runs the JDK tools against them instead of placing import module ...; declarations in this repository's ordinary Maven package tree.

  • Constructor Details

    • ModuleImportDeclarationsExamples

      public ModuleImportDeclarationsExamples()
  • Method Details

    • createJavaBaseModuleImportSource

      public Path createJavaBaseModuleImportSource(Path directory) throws IOException
      Creates a source file that imports java.base and uses types from several exported packages without ordinary imports.
      Parameters:
      directory - directory where the source file should be written
      Returns:
      path to the source file
      Throws:
      IOException - when the source file cannot be written
    • createSourceWithoutImports

      public Path createSourceWithoutImports(Path directory) throws IOException
      Creates the same source shape without imports, which should fail to compile.
      Parameters:
      directory - directory where the source file should be written
      Returns:
      path to the source file
      Throws:
      IOException - when the source file cannot be written
    • createHttpModuleImportSource

      public Path createHttpModuleImportSource(Path directory) throws IOException
      Creates a source file that combines module imports from java.base and java.net.http.
      Parameters:
      directory - directory where the source file should be written
      Returns:
      path to the source file
      Throws:
      IOException - when the source file cannot be written
    • createAmbiguousDateSource

      public Path createAmbiguousDateSource(Path directory) throws IOException
      Creates a source file where broad module imports produce a simple-name ambiguity.
      Parameters:
      directory - directory where the source file should be written
      Returns:
      path to the source file
      Throws:
      IOException - when the source file cannot be written
    • compile

      public ModuleImportDeclarationsExamples.CommandResult compile(Path sourceFile, Path outputDirectory) throws IOException, InterruptedException
      Compiles a generated source file.
      Parameters:
      sourceFile - source file to compile
      outputDirectory - destination for compiled classes
      Returns:
      command result
      Throws:
      IOException - when the compiler cannot be started
      InterruptedException - when interrupted while waiting for the compiler
    • launch

      Launches a generated source file directly with the JDK java launcher.
      Parameters:
      sourceFile - source file to launch
      Returns:
      command result
      Throws:
      IOException - when the launcher cannot be started
      InterruptedException - when interrupted while waiting for the launcher