Class DslCodeGenerator

  • All Implemented Interfaces:
    MethodCallBuilderRegistry

    public class DslCodeGenerator
    extends Object
    implements MethodCallBuilderRegistry
    Generates DSL code from JMX files.

    Take into account that code generation is a continuous improving process, so please report any unexpected or missing conversions as issues in repository, so we keep improving it.

    Check MethodCallBuilder for instructions on how to implement DSL code generation for new DSL test elements.

    Since:
    0.45
    See Also:
    MethodCallBuilder
    • Constructor Detail

      • DslCodeGenerator

        public DslCodeGenerator()
    • Method Detail

      • addBuildersFrom

        public DslCodeGenerator addBuildersFrom​(Class<?>... dslClasses)
        Allows registering DSL classes containing builder methods, which can be used to generate DSL code for.

        This method allows you to register DSL classes from none core modules or your own custom DSL classes. This is the way DslGenerators can discover new DSL test elements, and their associated MethodCallBuilder instances, to generate code for.

        Parameters:
        dslClasses - are the classes containing builder methods.
        Returns:
        the DslCodeGenerator instance for further configuration or usage.
      • addBuilders

        public DslCodeGenerator addBuilders​(MethodCallBuilder... builders)
        Allows registering MethodCallBuilders that are not associated to a DSL builder method.

        This is helpful when some element has no DSL builder method counterpart, but still there is a way to convert the element (eg: ignoring it all together, only converting children, etc).

        Parameters:
        builders - list of MethodCallBuilders to register into the generator.
        Returns:
        the DslCodeGenerator instance for further configuration or usage.
        Since:
        0.50
      • addDependency

        public DslCodeGenerator addDependency​(Class<?> dependencyClass,
                                              String dependencyLocator)
        Allows registering libraries required to use a specific class.
        Parameters:
        dependencyClass - is the class to register a library for.
        dependencyLocator - the jbang library locator for the library containing the class.
        Returns:
        the DslCodeGenerator instance for further configuration or usage.
        Since:
        0.62
      • generateCodeFromJmx

        public String generateCodeFromJmx​(File file)
                                   throws IOException
        Generates DSL code from JMX file.
        Parameters:
        file - is the JMX file from which DSL code will be generated.
        Returns:
        the generated DSL MethodCall used to generate code from.
        Throws:
        IOException - when there is some problem reading the file.