Class ClassGeneratorOptionsBuilder
java.lang.Object
org.jfuncmachine.compiler.classgen.ClassGeneratorOptionsBuilder
A builder used to create a ClassGeneratorOptions class.
This builder allows you to easily override just one or two defaults in the ClassGeneratorOptions
without having to provide all the constructor parameters.
Example:
ClassGeneratorOptions options =
new ClassGeneratorOptionsBuilder().withAutobox(false).javaVersion(20).build();
-
Field Summary
FieldsModifier and TypeFieldDescriptionbooleanIndicates whether the code generator should automatically convert between native types and boxed types (Object-versions of each type, e.g.booleanThe TypeSwitch and EnumSwitch expressions use a feature that was a preview in Java 17, and became fully supported in Java 21.booleanGenerate non-Java-callable methods with tail-call optimization.booleanIndicate whether to generate Java-compatible generic object interfaces for each lambda.intThe Java version to generate class files forThe name used for the single method in a lambda interface.booleanConvert local recursive calls (method calling itself) to loopsbooleanIndicates that any lambdas generated for one class can be shared by all classes in the same package.booleanCurrently JFuncMachine uses two features that were previews between Java 17 and Java 21. -
Constructor Summary
ConstructorsConstructorDescriptionCreate a ClassGeneratorOptionsBuilder instance with the default settings -
Method Summary
Modifier and TypeMethodDescriptionbuild()Generate a new ClassGeneratorOptions object with the desired changes.withAutobox(boolean option) Change the option to generate autoboxing to automatically convert between native and box types.withConvertSwitchesToIf(boolean option) Change the option to convert TypeSwitch and EnumSwitch expressions to If expressions if the JVM doesn't support them (Java 21 is required if usePreviewFeatures is false, or Java 17 if usePreviewFeatures is true).withFullTailCalls(boolean option) Change the option to generate full tail calls for all methods (except ones marked as Java-callable)withGenericLambdas(boolean option) Change the option to generate generic lambda interfaces that use boxed typeswithJavaVersion(int version) Change the Java version in the optionswithLambdaMethodName(String lambdaMethodName) Change the name of the single method in a generated lambda interfacewithLocalTailCallsToLoops(boolean option) Change the option to replace local recursive method calls with loopswithSharedLambdas(boolean option) Change the option indicating whether all classes in the package should share generated lambda interfaces.withUsePreviewFeatures(boolean option) Change the option to use preview features
-
Field Details
-
javaVersion
public int javaVersionThe Java version to generate class files for -
localTailCallsToLoops
public boolean localTailCallsToLoopsConvert local recursive calls (method calling itself) to loops -
fullTailCalls
public boolean fullTailCallsGenerate non-Java-callable methods with tail-call optimization. This requires changing the return type of each method to return an object that contains a reference to the next function to call, or a value representing the return value of the function. This option should not be used unless it is really needed as it adds overhead to each function call. -
autobox
public boolean autoboxIndicates whether the code generator should automatically convert between native types and boxed types (Object-versions of each type, e.g. java.lang.Byte for byte, java.lang.Integer for int). -
lambdaMethodName
The name used for the single method in a lambda interface. -
genericLambdas
public boolean genericLambdasIndicate whether to generate Java-compatible generic object interfaces for each lambda. This facilitates lambdas that are compatible with the java.util.function package. -
usePreviewFeatures
public boolean usePreviewFeaturesCurrently JFuncMachine uses two features that were previews between Java 17 and Java 21. If this option is true, JFuncMachine will use these features if generating for Java versions 17, 18, 19, and 20. -
convertSwitchesToIf
public boolean convertSwitchesToIfThe TypeSwitch and EnumSwitch expressions use a feature that was a preview in Java 17, and became fully supported in Java 21. If this flag is true, JFuncMachine will convert these expressions to If expressions if generating for a JVM where the feature is not supported. If usePreviewFeatures is true, then this conversion will only happen for Java 16 or lower. If usePreviewFeatures is false, then this conversion will happen for Java 20 or lower.
-
-
Constructor Details
-
ClassGeneratorOptionsBuilder
public ClassGeneratorOptionsBuilder()Create a ClassGeneratorOptionsBuilder instance with the default settings
-
-
Method Details
-
withJavaVersion
Change the Java version in the options- Parameters:
version- The version of Java to generate class files for- Returns:
- The current ClassGeneratorOptionsBuilder (for chaining calls)
-
withLocalTailCallsToLoops
Change the option to replace local recursive method calls with loops- Parameters:
option- True if local recursive calls should be turned into loops- Returns:
- The current ClassGeneratorOptionsBuilder (for chaining calls)
-
withFullTailCalls
Change the option to generate full tail calls for all methods (except ones marked as Java-callable)- Parameters:
option- True if each non-Java-callable method should be generated to do tail-call optimization- Returns:
- The current ClassGeneratorOptionsBuilder (for chaining calls)
-
withAutobox
Change the option to generate autoboxing to automatically convert between native and box types.- Parameters:
option- True if autoboxing should be on- Returns:
- The current ClassGeneratorOptionsBuilder (for chaining calls)
-
withLambdaMethodName
Change the name of the single method in a generated lambda interface- Parameters:
lambdaMethodName- The name to use for lambda interface methods- Returns:
- The current ClassGeneratorOptionsBuilder (for chaining calls)
-
withGenericLambdas
Change the option to generate generic lambda interfaces that use boxed types- Parameters:
option- True if lambda interfaces should always box native types- Returns:
- The current ClassGeneratorOptionsBuilder (for chaining calls)
-
withUsePreviewFeatures
Change the option to use preview features- Parameters:
option- True if JFuncMachine should use JVM features that are currently in preview- Returns:
- The current ClassGeneratorOptionsBuilder (for chaining calls)
-
withConvertSwitchesToIf
Change the option to convert TypeSwitch and EnumSwitch expressions to If expressions if the JVM doesn't support them (Java 21 is required if usePreviewFeatures is false, or Java 17 if usePreviewFeatures is true).- Parameters:
option- True if JFuncMachine should use preview features- Returns:
- The current ClassGeneratorOptionsBuilder (for chaining calls)
-
build
Generate a new ClassGeneratorOptions object with the desired changes.- Returns:
- a new ClassGeneratorOptions containing all the options set by this builder
-