Class ModuleImportDeclarationsExamples
java.lang.Object
net.jrodolfo.java_evolution.java25.ModuleImportDeclarationsExamples
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classCaptures JDK tool output. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionCompiles a generated source file.createAmbiguousDateSource(Path directory) Creates a source file where broad module imports produce a simple-name ambiguity.createHttpModuleImportSource(Path directory) Creates a source file that combines module imports fromjava.baseandjava.net.http.createJavaBaseModuleImportSource(Path directory) Creates a source file that importsjava.baseand uses types from several exported packages without ordinary imports.createSourceWithoutImports(Path directory) Creates the same source shape without imports, which should fail to compile.Launches a generated source file directly with the JDKjavalauncher.
-
Constructor Details
-
ModuleImportDeclarationsExamples
public ModuleImportDeclarationsExamples()
-
-
Method Details
-
createJavaBaseModuleImportSource
Creates a source file that importsjava.baseand 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
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
Creates a source file that combines module imports fromjava.baseandjava.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
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 compileoutputDirectory- destination for compiled classes- Returns:
- command result
- Throws:
IOException- when the compiler cannot be startedInterruptedException- when interrupted while waiting for the compiler
-
launch
public ModuleImportDeclarationsExamples.CommandResult launch(Path sourceFile) throws IOException, InterruptedException Launches a generated source file directly with the JDKjavalauncher.- Parameters:
sourceFile- source file to launch- Returns:
- command result
- Throws:
IOException- when the launcher cannot be startedInterruptedException- when interrupted while waiting for the launcher
-