ConstructorView implements Transform<Constructor, String>,
           HasThrowsView<Constructor>,
           HasGenericsView<Constructor>,
           HasFieldsView<Constructor>,
           HasJavadocView<Constructor>,
           HasAnnotationUsageView<Constructor>,
           HasCodeView<Constructor>,
           HasModifiersView<Constructor> { @Override public Optional<String> transform(Generator gen, Constructor model) { requireNonNulls(gen, model); return Optional.of( renderJavadoc(gen, model) + renderAnnotations(gen, model) + renderModifiers(gen, model, PUBLIC, PRIVATE, PROTECTED) + renderGenerics(gen, model) + renderName(gen, model) .orElseThrow(() -> new UnsupportedOperationException( "Could not find a nameable parent of constructor." )) + ((splitFields(model)) ? "(" + Formatting.nl() + Formatting.tab() + Formatting.tab() : "(") + renderFields(gen, model) + ") " + renderThrows(gen, model) + renderCode(gen, model) ); }  @Override String fieldSeparator(Constructor model); @Override String throwsSuffix(Constructor model); @Override Optional<String> transform(Generator gen, Constructor model);  }
@Test void transform() { final File file = File.of("com/example/Main.java") .add(Import.of(StringBuilder.class)) .add(Class.of("Main").public_().final_() .add(Field.of("string", String.class).private_().final_()) .add(Constructor.of() .public_() .add(SUPPRESS_WARNINGS_UNCHECKED) .add(IllegalArgumentException.class) .set(Javadoc.of("The constructor for this class.")) .add(Field.of("stringOrBuilder", CharSequence.class)) .add("if (stringOrBuilder instanceof String) " + block( "this.string = (String) stringOrBuilder;" ) + " else if () " + block( "this.string = ((StringBuilder) stringOrBuilder).toString();" ) + " else " + block( "throw new IllegalArgumentException(\"Not a String or StringBuilder!\");" )) ) ); final Generator generator = new JavaGenerator(); final String code = generator.on(file).get(); assertNotNull(code); Stream.of( "package com.example;", "public final class Main", "public Main(", String.class.getSimpleName(), StringBuilder.class.getSimpleName(), "Main", "public", "final", "private" ).forEach(s -> { assertTrue(code.contains(s)); }); }