Interface Generator

  • All Known Implementing Classes:
    StandardGenerator, StandardJavaGenerator

    public interface Generator
    A hook to the generator that can be passed to various stages in the pipeline. Contains multiple methods for generating model-to-model or model-to-text.
    Since:
    2.0
    Author:
    Emil Forslund
    • Method Detail

      • getRenderStack

        RenderStack getRenderStack()
        Returns the current rendering stack. The top element will be the one most recent rendered and the bottom one will be the element that was first passed to the generator. Elements are removed from the stack once they have finished rendering.

        If an element needs to access its parent, it can call this method and peek on the second element from the top.

        Returns:
        the current rendering stack
        See Also:
        RenderStack
      • metaOn

        <A,​B> Stream<Meta<A,​B>> metaOn​(A from,
                                                   Class<B> to)
        Renders the specified model into a stream of code models. This is used internally to provide the other interface methods.
        Type Parameters:
        A - the input type
        B - the expected output type
        Parameters:
        from - the model to generate
        to - the model type to transform to
        Returns:
        a stream of meta objects
        See Also:
        Meta
      • metaOn

        default <A,​B> Stream<Meta<A,​B>> metaOn​(A from,
                                                           Class<B> to,
                                                           Class<? extends Transform<A,​B>> transform)
        Renders the specified model into a stream of code models. This is used internally to provide the other interface methods.

        If the specified transform is not installed, an empty stream will be returned.

        Type Parameters:
        A - the input type
        B - the expected output type
        Parameters:
        from - the model to generate
        to - the model type to transform to
        transform - the specified transform to use
        Returns:
        a stream of meta objects
        See Also:
        Meta
      • metaOn

        default <M> Stream<Meta<M,​String>> metaOn​(M model)
        Renders the specified model into a stream of code models. This is used internally to provide the other interface methods.
        Type Parameters:
        M - the model type
        Parameters:
        model - the model to generate
        Returns:
        a stream of meta objects
        See Also:
        Meta
      • metaOn

        default <A> Stream<Meta<A,​String>> metaOn​(Collection<A> models)
        Renders all the specified models into a stream of code models. This is used internally to provide the other interface methods.
        Type Parameters:
        A - the input type
        Parameters:
        models - the models to generate
        Returns:
        a stream of meta objects
        See Also:
        Meta
      • metaOn

        default <A,​B> Stream<Meta<A,​B>> metaOn​(Collection<A> models,
                                                           Class<B> to)
        Renders all the specified models into a stream of code models. This is used internally to provide the other interface methods.
        Type Parameters:
        A - the input type
        B - the expected output type
        Parameters:
        models - the models to generate
        to - the expected result type
        Returns:
        a stream of meta objects
        See Also:
        Meta
      • metaOn

        default <A,​B> Stream<Meta<A,​B>> metaOn​(Collection<A> models,
                                                           Class<B> to,
                                                           Class<? extends Transform<A,​B>> transform)
        Renders all the specified models into a stream of code models. This is used internally to provide the other interface methods. This will only return results from the specified transform.

        If the specified transform is not installed, an empty stream will be returned.

        Type Parameters:
        A - the input type
        B - the expected output type
        Parameters:
        models - the models to generate
        to - the expected result type
        transform - the specific transform to use
        Returns:
        a stream of meta objects
        See Also:
        Meta
      • on

        default Optional<String> on​(Object model)
        Locates the Transform that corresponds to the specified model and uses it to generate a String. If no view is associated with the model type, an empty Optional will be returned.
        Parameters:
        model - the model
        Returns:
        the generated text if any
      • onEach

        default <M> Stream<String> onEach​(Collection<M> models)
        Renders all the specified models into a stream of strings.
        Type Parameters:
        M - the model type
        Parameters:
        models - the models to generate
        Returns:
        a stream of meta objects
      • transform

        <A,​B> Optional<Meta<A,​B>> transform​(Transform<A,​B> transform,
                                                        A model,
                                                        TransformFactory factory)
        Transforms the specified model using the specified Transform from the specified TransformFactory.
        Type Parameters:
        A - the input type
        B - the expected output type
        Parameters:
        transform - the transform to use
        model - the inputed model
        factory - the factory used when instantiating the transform
        Returns:
        the meta object if successful, else empty
        See Also:
        Transform, TransformFactory
      • forJava

        static Generator forJava()
        Returns an implementation of this interface that uses the default implementation used to generate Java code.
        Returns:
        the default generator for Java