Package hydra

Interface Serialization


  • public interface Serialization
    Utilities for constructing generic program code ASTs, used for the serialization phase of source code generation.
    • Method Summary

      Static Methods 
      Modifier and Type Method Description
      static Brackets angleBraces()
      Angle bracket pair `<` `>` for use with `brackets`
      static Expr angleBracesList​(BlockStyle style, java.util.List<Expr> els)
      Comma-separate the elements inside angle brackets in the given block style; renders as `<>` when empty
      static Expr bracesListAdaptive​(java.util.List<Expr> els)
      Produce a bracketed list which separates elements by spaces or newlines depending on the estimated width of the expression.
      static Expr bracketList​(BlockStyle style, java.util.List<Expr> els)
      Comma-separate the elements inside square brackets in the given block style; renders as `[]` when empty
      static Expr bracketListAdaptive​(java.util.List<Expr> els)
      Produce a bracketed list which separates elements by spaces or newlines depending on the estimated width of the expression.
      static Expr brackets​(Brackets br, BlockStyle style, Expr e)
      Wrap an expression in the given bracket pair using the given block style
      static Expr chooseLayout​(java.lang.Integer threshold, Expr inlineExpr, Expr blockExpr)
      Pick between an inline and a multi-line layout for the same logical expression.
      static Expr commaSep​(BlockStyle v1, java.util.List<Expr> v2)
      Separate elements with a comma, using the given block style
      static Expr commaSepAdaptive​(java.util.List<Expr> els)
      Comma-separate elements inline if the joined width fits, otherwise break onto separate lines.
      static Expr cst​(java.lang.String s)
      Construct a constant expression from a literal string
      static Expr curlyBlock​(BlockStyle style, Expr e)
      Wrap a single expression in curly braces using the given block style
      static Brackets curlyBraces()
      Curly brace pair `{` `}` for use with `brackets`
      static Expr curlyBracesList​(Optional<java.lang.String> msymb, BlockStyle style, java.util.List<Expr> els)
      Separate the elements inside curly braces using the given symbol (default `,`) in the given block style; renders as `{}` when empty
      static java.lang.String customIndent​(java.lang.String idt, java.lang.String s)
      Indent every non-empty line of `s` by `idt`.
      static Expr customIndentBlock​(java.lang.String idt, java.util.List<Expr> els)
      Render a list of expressions as a block whose first element starts where the surrounding context placed it and subsequent elements break onto fresh lines indented by the given prefix
      static Expr dotSep​(java.util.List<Expr> v1)
      Separate elements with a dot and no surrounding whitespace
      static Expr doubleNewlineSep​(java.util.List<Expr> v1)
      Separate elements with a blank line between them
      static java.lang.String doubleSpace()
      The two-space string used as the canonical indent unit
      static java.lang.Integer expressionLength​(Expr e)
      Find the approximate length (number of characters, including spaces and newlines) of an expression without actually printing it.
      static BlockStyle fullBlockStyle()
      Block style with double-space indent and newlines both before and after the bracketed content
      static BlockStyle halfBlockStyle()
      Block style with double-space indent, a newline before the content but not after
      static Expr ifx​(Op op, Expr lhs, Expr rhs)
      Build an infix expression with the given operator and two operands
      static java.lang.String indent​(java.lang.String v1)
      Indent every non-empty line of a string by `doubleSpace`
      static Expr indentBlock​(java.util.List<Expr> v1)
      Like `customIndentBlock`, but using `doubleSpace` as the indent prefix
      static Expr indentSubsequentLines​(java.lang.String idt, Expr e)
      Indent every line of an expression except the first by the given prefix
      static Expr infixWs​(java.lang.String op, Expr l, Expr r)
      Space-separate three elements: left operand, operator string, right operand
      static Expr infixWsList​(java.lang.String op, java.util.List<Expr> opers)
      Space-separate operands interleaved with the given operator string
      static BlockStyle inlineStyle()
      Block style with no indent and no surrounding newlines: contents stay on a single line
      static java.lang.Integer maxLineWidth()
      The canonical maximum line width used by Hydra writers.
      static Expr newlineSep​(java.util.List<Expr> v1)
      Separate elements by a newline (no leading whitespace)
      static Padding noPadding()
      Operator padding with no whitespace on either side
      static Expr noSep​(java.util.List<Expr> v1)
      Concatenate elements with no separator and no whitespace
      static Expr num​(java.lang.Integer i)
      Construct a constant expression from an int32
      static Op op​(java.lang.String s, java.lang.Integer p, Associativity assoc)
      Build an op with single-space padding from a symbol, precedence, and associativity
      static Op orOp​(java.lang.Boolean newlines)
      Build the `|` alternative-separator operator.
      static Expr orSep​(BlockStyle style, java.util.List<Expr> l)
      Separate alternatives with `|`, breaking onto separate lines when the block style requests a newline before content
      static Expr parenList​(java.lang.Boolean newlines, java.util.List<Expr> els)
      Comma-separate the elements inside parentheses; switches to a half-block style when newlines are requested and there is more than one element.
      static Expr parenListAdaptive​(java.util.List<Expr> els)
      Produce a parenthesized list which separates elements by spaces or newlines depending on the estimated width of the expression.
      static Expr parens​(Expr v1)
      Wrap an expression in inline parentheses
      static Brackets parentheses()
      Round parenthesis pair `(` `)` for use with `brackets`
      static Expr parenthesize​(Expr exp)
      Recursively insert parentheses around subexpressions where required by operator precedence and associativity.
      static Expr prefix​(java.lang.String p, Expr expr)
      Prepend a prefix string to an expression with no surrounding whitespace
      static java.lang.String printExpr​(Expr e)
      Render an expression to a string, expanding bracket pairs, block styles, indents, and operator chains
      static Expr semicolonSep​(java.util.List<Expr> v1)
      Separate elements with `;` inline
      static Expr sep​(Op op, java.util.List<Expr> els)
      Combine a list of expressions into a single OpExpr chain using the given operator.
      static Expr spaceSep​(java.util.List<Expr> v1)
      Space-separate elements (no break between them)
      static Expr spaceSepAdaptive​(java.util.List<Expr> els)
      Space-separate elements inline if the joined width fits, otherwise newline-separate them.
      static Brackets squareBrackets()
      Square bracket pair `[` `]` for use with `brackets`
      static Expr structuralSep​(Op op, java.util.List<Expr> els)
      Like sep, but produces a SeqExpr instead of an OpExpr chain.
      static Expr structuralSpaceSep​(java.util.List<Expr> v1)
      Like spaceSep, but produces a SeqExpr.
      static Expr suffix​(java.lang.String s, Expr expr)
      Append a suffix string to an expression
      static Symbol sym​(java.lang.String s)
      Construct a Symbol from a string
      static Expr symbolSep​(java.lang.String symb, BlockStyle style, java.util.List<Expr> l)
      Separate elements with the given symbol; trailing whitespace per element is determined by the block style's newline-before/after flags (space, single break, or double break)
      static Expr tabIndent​(Expr e)
      Indent every line of an expression by four spaces
      static Expr tabIndentDoubleSpace​(java.util.List<Expr> exprs)
      Tab-indent a list of expressions, separated by blank lines
      static Expr tabIndentSingleSpace​(java.util.List<Expr> exprs)
      Tab-indent a list of expressions, separated by single newlines
      static Expr unsupportedType​(java.lang.String label)
      Render a placeholder for a type the writer does not yet handle, e.g.
      static Expr unsupportedVariant​(java.lang.String label, java.lang.String obj)
      Render a placeholder for an unsupported variant, including a string representation of the offending value
      static Expr withComma​(Expr e)
      Append a trailing comma to an expression
      static Expr withSemi​(Expr e)
      Append a trailing semicolon to an expression
    • Method Detail

      • angleBraces

        static Brackets angleBraces()
        Angle bracket pair `<` `>` for use with `brackets`
      • angleBracesList

        static Expr angleBracesList​(BlockStyle style,
                                    java.util.List<Expr> els)
        Comma-separate the elements inside angle brackets in the given block style; renders as `<>` when empty
      • bracesListAdaptive

        static Expr bracesListAdaptive​(java.util.List<Expr> els)
        Produce a bracketed list which separates elements by spaces or newlines depending on the estimated width of the expression.
      • bracketList

        static Expr bracketList​(BlockStyle style,
                                java.util.List<Expr> els)
        Comma-separate the elements inside square brackets in the given block style; renders as `[]` when empty
      • bracketListAdaptive

        static Expr bracketListAdaptive​(java.util.List<Expr> els)
        Produce a bracketed list which separates elements by spaces or newlines depending on the estimated width of the expression.
      • brackets

        static Expr brackets​(Brackets br,
                             BlockStyle style,
                             Expr e)
        Wrap an expression in the given bracket pair using the given block style
      • chooseLayout

        static Expr chooseLayout​(java.lang.Integer threshold,
                                 Expr inlineExpr,
                                 Expr blockExpr)
        Pick between an inline and a multi-line layout for the same logical expression. Returns the inline form if its estimated width does not exceed the threshold, otherwise the block form. Note: the threshold is measured against the inline expression in isolation; surrounding indentation may push content beyond the threshold at print time. Callers that know they are nested can pass a smaller threshold to compensate.
      • commaSep

        static Expr commaSep​(BlockStyle v1,
                             java.util.List<Expr> v2)
        Separate elements with a comma, using the given block style
      • commaSepAdaptive

        static Expr commaSepAdaptive​(java.util.List<Expr> els)
        Comma-separate elements inline if the joined width fits, otherwise break onto separate lines.
      • cst

        static Expr cst​(java.lang.String s)
        Construct a constant expression from a literal string
      • curlyBlock

        static Expr curlyBlock​(BlockStyle style,
                               Expr e)
        Wrap a single expression in curly braces using the given block style
      • curlyBraces

        static Brackets curlyBraces()
        Curly brace pair `{` `}` for use with `brackets`
      • curlyBracesList

        static Expr curlyBracesList​(Optional<java.lang.String> msymb,
                                    BlockStyle style,
                                    java.util.List<Expr> els)
        Separate the elements inside curly braces using the given symbol (default `,`) in the given block style; renders as `{}` when empty
      • customIndent

        static java.lang.String customIndent​(java.lang.String idt,
                                             java.lang.String s)
        Indent every non-empty line of `s` by `idt`. Empty lines stay empty (no trailing whitespace) so downstream byte-identity checks don't care about indent depth.
      • customIndentBlock

        static Expr customIndentBlock​(java.lang.String idt,
                                      java.util.List<Expr> els)
        Render a list of expressions as a block whose first element starts where the surrounding context placed it and subsequent elements break onto fresh lines indented by the given prefix
      • dotSep

        static Expr dotSep​(java.util.List<Expr> v1)
        Separate elements with a dot and no surrounding whitespace
      • doubleNewlineSep

        static Expr doubleNewlineSep​(java.util.List<Expr> v1)
        Separate elements with a blank line between them
      • doubleSpace

        static java.lang.String doubleSpace()
        The two-space string used as the canonical indent unit
      • expressionLength

        static java.lang.Integer expressionLength​(Expr e)
        Find the approximate length (number of characters, including spaces and newlines) of an expression without actually printing it.
      • fullBlockStyle

        static BlockStyle fullBlockStyle()
        Block style with double-space indent and newlines both before and after the bracketed content
      • halfBlockStyle

        static BlockStyle halfBlockStyle()
        Block style with double-space indent, a newline before the content but not after
      • ifx

        static Expr ifx​(Op op,
                        Expr lhs,
                        Expr rhs)
        Build an infix expression with the given operator and two operands
      • indent

        static java.lang.String indent​(java.lang.String v1)
        Indent every non-empty line of a string by `doubleSpace`
      • indentBlock

        static Expr indentBlock​(java.util.List<Expr> v1)
        Like `customIndentBlock`, but using `doubleSpace` as the indent prefix
      • indentSubsequentLines

        static Expr indentSubsequentLines​(java.lang.String idt,
                                          Expr e)
        Indent every line of an expression except the first by the given prefix
      • infixWs

        static Expr infixWs​(java.lang.String op,
                            Expr l,
                            Expr r)
        Space-separate three elements: left operand, operator string, right operand
      • infixWsList

        static Expr infixWsList​(java.lang.String op,
                                java.util.List<Expr> opers)
        Space-separate operands interleaved with the given operator string
      • inlineStyle

        static BlockStyle inlineStyle()
        Block style with no indent and no surrounding newlines: contents stay on a single line
      • maxLineWidth

        static java.lang.Integer maxLineWidth()
        The canonical maximum line width used by Hydra writers. Adaptive helpers compare estimated expression widths against this threshold to decide whether to render inline or break across lines. Set to 120 to match the project-wide line-length convention.
      • newlineSep

        static Expr newlineSep​(java.util.List<Expr> v1)
        Separate elements by a newline (no leading whitespace)
      • noPadding

        static Padding noPadding()
        Operator padding with no whitespace on either side
      • noSep

        static Expr noSep​(java.util.List<Expr> v1)
        Concatenate elements with no separator and no whitespace
      • num

        static Expr num​(java.lang.Integer i)
        Construct a constant expression from an int32
      • op

        static Op op​(java.lang.String s,
                     java.lang.Integer p,
                     Associativity assoc)
        Build an op with single-space padding from a symbol, precedence, and associativity
      • orOp

        static Op orOp​(java.lang.Boolean newlines)
        Build the `|` alternative-separator operator. The flag selects whether the right side breaks onto a new line.
      • orSep

        static Expr orSep​(BlockStyle style,
                          java.util.List<Expr> l)
        Separate alternatives with `|`, breaking onto separate lines when the block style requests a newline before content
      • parenList

        static Expr parenList​(java.lang.Boolean newlines,
                              java.util.List<Expr> els)
        Comma-separate the elements inside parentheses; switches to a half-block style when newlines are requested and there is more than one element. Renders as `()` when empty.
      • parenListAdaptive

        static Expr parenListAdaptive​(java.util.List<Expr> els)
        Produce a parenthesized list which separates elements by spaces or newlines depending on the estimated width of the expression.
      • parens

        static Expr parens​(Expr v1)
        Wrap an expression in inline parentheses
      • parentheses

        static Brackets parentheses()
        Round parenthesis pair `(` `)` for use with `brackets`
      • parenthesize

        static Expr parenthesize​(Expr exp)
        Recursively insert parentheses around subexpressions where required by operator precedence and associativity. The traversal descends into bracket, indent, sequence, and operator expressions and parenthesizes left or right operands whose binding is weaker than the surrounding operator.
      • prefix

        static Expr prefix​(java.lang.String p,
                           Expr expr)
        Prepend a prefix string to an expression with no surrounding whitespace
      • printExpr

        static java.lang.String printExpr​(Expr e)
        Render an expression to a string, expanding bracket pairs, block styles, indents, and operator chains
      • semicolonSep

        static Expr semicolonSep​(java.util.List<Expr> v1)
        Separate elements with `;` inline
      • sep

        static Expr sep​(Op op,
                        java.util.List<Expr> els)
        Combine a list of expressions into a single OpExpr chain using the given operator. Returns the empty constant for an empty list.
      • spaceSep

        static Expr spaceSep​(java.util.List<Expr> v1)
        Space-separate elements (no break between them)
      • spaceSepAdaptive

        static Expr spaceSepAdaptive​(java.util.List<Expr> els)
        Space-separate elements inline if the joined width fits, otherwise newline-separate them. Useful for long signatures, type chains, and other space-joined sequences.
      • squareBrackets

        static Brackets squareBrackets()
        Square bracket pair `[` `]` for use with `brackets`
      • structuralSep

        static Expr structuralSep​(Op op,
                                  java.util.List<Expr> els)
        Like sep, but produces a SeqExpr instead of an OpExpr chain. SeqExpr is treated as structural layout and is not subject to parenthesization.
      • structuralSpaceSep

        static Expr structuralSpaceSep​(java.util.List<Expr> v1)
        Like spaceSep, but produces a SeqExpr. Use for structural layout that should not trigger parenthesization of children.
      • suffix

        static Expr suffix​(java.lang.String s,
                           Expr expr)
        Append a suffix string to an expression
      • sym

        static Symbol sym​(java.lang.String s)
        Construct a Symbol from a string
      • symbolSep

        static Expr symbolSep​(java.lang.String symb,
                              BlockStyle style,
                              java.util.List<Expr> l)
        Separate elements with the given symbol; trailing whitespace per element is determined by the block style's newline-before/after flags (space, single break, or double break)
      • tabIndent

        static Expr tabIndent​(Expr e)
        Indent every line of an expression by four spaces
      • tabIndentDoubleSpace

        static Expr tabIndentDoubleSpace​(java.util.List<Expr> exprs)
        Tab-indent a list of expressions, separated by blank lines
      • tabIndentSingleSpace

        static Expr tabIndentSingleSpace​(java.util.List<Expr> exprs)
        Tab-indent a list of expressions, separated by single newlines
      • unsupportedType

        static Expr unsupportedType​(java.lang.String label)
        Render a placeholder for a type the writer does not yet handle, e.g. `[bigint]`
      • unsupportedVariant

        static Expr unsupportedVariant​(java.lang.String label,
                                       java.lang.String obj)
        Render a placeholder for an unsupported variant, including a string representation of the offending value
      • withComma

        static Expr withComma​(Expr e)
        Append a trailing comma to an expression
      • withSemi

        static Expr withSemi​(Expr e)
        Append a trailing semicolon to an expression