Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TableBuilder API for Scala (and others) compatibility #33

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from

Commits on Oct 25, 2021

  1. Add TableBuilder API for Scala (and others) compatibility

    Add TableBuilder API, which is a Java-shim over Picnic's Table.Builder
    API. Unfortunately Table.Builder is not accessible from Scala (and
    probably other JVM-based languages). The Scala incompatibility of
    Table.Builder comes from the fact that Scala does not seem to
    understand Kotlins @set:JvmSynthetic annotation. And since this
    annotation is used in Picnic to hide Kotlin setter methods from
    Java (and, in turn from Scala), the Scala compiler failes to resolve a
    method reference:
    
    [error] Example.scala:37:14: ambiguous reference to overloaded definition,
    [error] both method setColumnSpan in class TableBuilder of type (x$1: Int): jakewharton.picnic.Cell.Builder
    [error] and  method setColumnSpan in class TableBuilder of type (x$1: Int): Unit
    [error] match argument types (Int)
    [error]             .setColumnSpan(4)
    
    As additional benefit, the new TableBuilder API creates much less noisy
    code compared to the existing Table.Builder, since it avoids the 'new'
    keyword and nexted builders.
    
    Compare Table.Builder
    
    .setHeader(new TableSection.Builder()
        .setCellStyle(new CellStyle.Builder()
            .setBorder(true)
            .setAlignment(BottomLeft)
            .build())
        .addRow(new Row.Builder()
            .addCell(new Cell.Builder("APK")
                .setRowSpan(2)
                .build())
            .addCell(new Cell.Builder("compressed")
                .setColumnSpan(3)
                .setStyle(new CellStyle.Builder()
                    .setAlignment(BottomCenter)
                    .build())
                .build())
            .addCell(new Cell.Builder("uncompressed")
                .setColumnSpan(3)
                .setStyle(new CellStyle.Builder()
                    .setAlignment(BottomCenter)
                    .build())
                .build())
            .build())
    
    with TableBuilder
    
    .withHeader()
        .withCellStyle()
            .setBorder(true)
            .setAlignment(BottomLeft)
            .endCellStyle()
        .addRow()
            .addCell("APK")
                .setRowSpan(2)
                .endCell()
            .addCell("compressed")
                .setColumnSpan(3)
                .withCellStyle()
                    .setAlignment(BottomCenter)
                    .endCellStyle()
                .endCell()
            .addCell("uncompressed")
                .setColumnSpan(3)
                .withCellStyle()
                    .setAlignment(BottomCenter)
                    .endCellStyle()
                .endCell()
            .endRow()
        .addRow("old", "new", "diff", "old", "new", "diff")
        .endHeader()
    Flowdalic committed Oct 25, 2021
    Configuration menu
    Copy the full SHA
    88cda93 View commit details
    Browse the repository at this point in the history