inferred / FreeBuilder

Automatic generation of the Builder pattern for Java
Apache License 2.0
838 stars 101 forks source link

Parameterize first argument of PreconditionExcerpts methods #378

Closed alicederyn closed 5 years ago

alicederyn commented 5 years ago

Rather than taking in and attempting to negate an Excerpt, which is blocking SourceBuilder cleanups, instead make the first argument a parameter using the same list of arguments as the second. This has the nice side-effect of making uses cleaner. For example,


Excerpt propertyIsSet = Excerpts.add("!%s.contains(%s.%s)",
    UNSET_PROPERTIES, datatype.getPropertyEnum(), property.getAllCapsName());
code.add(PreconditionExcerpts.checkState(propertyIsSet, property.getName() + " not set"));

becomes:


code.add(PreconditionExcerpts.checkState(
    "!%s.contains(%s.%s)",
    property.getName() + " not set",
    UNSET_PROPERTIES,
    datatype.getPropertyEnum(),
    property.getAllCapsName()));

The new TemplateApplier class encapsulates the code shared between this and AbstractSourceBuilder.

alicederyn commented 5 years ago

Failing with missing apache commons class error