Class ConduitGenerator
java.lang.Object
org.geysermc.conduit.generate.ConduitGenerator
Generates
Conduit interfaces from real classes.
The generator reads the classes a conduit mirrors, and works out from their constructors,
factories and methods where each field's value comes from at a call site. That becomes the
Conduit.Bind entries on each method. Only the generator needs the
real classes. Commit its output, and scanning afterwards needs nothing but the jar being scanned.
ConduitContext context = ConduitContext.load(Path.of("library.jar"));
new ConduitGenerator(context).generateAll(
Path.of("src/main/java/com/example/conduit"), "com.example.conduit",
List.of("com.example.Color", "com.example.Palette"));
Each file is stamped with a checksum. Regenerating replaces files that are unchanged since they were generated, and leaves edited ones alone, so a binding the analysis can't derive can be added by hand and survives the next run.
Also runnable from the command line, or through the dev.opencollab.conduit Gradle plugin.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionGenerates the source of a single conduit.Generates the source of a single conduit, collecting the classes its methods refer to.generateAll(@NotNull Path directory, @NotNull String targetPackage, @NotNull List<String> classNames) Generates a set of conduits that refer to each other.static booleanisUnmodified(@NotNull String source) Checks a generated file's checksum against its contents, to tell whether it was edited since it was generated.static voidGenerates conduits from the command line, the same way asgenerateAll(Path, String, List).
-
Constructor Details
-
ConduitGenerator
Main constructor.- Parameters:
context- the jars holding the classes to generate from, and anything they reference
-
-
Method Details
-
generate
Generates the source of a single conduit.- Parameters:
className- the binary name of the class to mirrortargetPackage- the package to generate into- Returns:
- the source, or null if the class is not in the context
-
generate
public String generate(@NotNull @NotNull String className, @NotNull @NotNull String targetPackage, @NotNull @NotNull Set<String> referenced) Generates the source of a single conduit, collecting the classes its methods refer to.- Parameters:
className- the binary name of the class to mirrortargetPackage- the package to generate intoreferenced- receives the binary names of non-JDK classes the conduit refers to- Returns:
- the source, or null if the class is not in the context
-
isUnmodified
Checks a generated file's checksum against its contents, to tell whether it was edited since it was generated.- Parameters:
source- the contents of a generated file- Returns:
- whether it is unchanged, false if it has no checksum
-
generateAll
public List<Path> generateAll(@NotNull @NotNull Path directory, @NotNull @NotNull String targetPackage, @NotNull @NotNull List<String> classNames) throws IOException Generates a set of conduits that refer to each other. A method whose type is outside the set is left out and reported, rather than generated against a type that won't exist.- Parameters:
directory- the directory to write intotargetPackage- the package to generate intoclassNames- the binary names of the classes to mirror- Returns:
- the files written
- Throws:
IOException- if a file can't be read or written
-
main
Generates conduits from the command line, the same way asgenerateAll(Path, String, List).- Parameters:
args- the output directory, the package, a comma-separated list of jars, then each class- Throws:
IOException- if a file can't be read or written
-