@Test public void generatesJavaCode() { MatcherAssert.assertThat( new PrimaryConstructor( "color", new StickyList<>( new Attribute("Byte", "alpha"), new Attribute("Int", "rgb") ) ).code(), Matchers.stringContainsInOrder( new StickyList<>( "public", "color(", "final Byte alpha", "final Int rgb", ")", "{", "this.alpha = alpha;", "this.rgb = rgb;", "}" ) ) ); }
public String code() { return new UncheckedText( new FormattedText( "public %s(%s) {\n %s \n}", this.name, new UncheckedText( new JoinedText( ", ", new Mapped<>( attr -> attr.java( PrimaryConstructor.CTOR_PARAM_FORMAT ), this.attributes ) ) ).asString(), new UncheckedText( new JoinedText( "\n", new Mapped<>( attr -> attr.java( PrimaryConstructor.CTOR_INIT_FORMAT ), this.attributes ) ) ).asString() ) ).asString(); }
PrimaryConstructor { public String code() { return new UncheckedText( new FormattedText( "public %s(%s) {\n %s \n}", this.name, new UncheckedText( new JoinedText( ", ", new Mapped<>( attr -> attr.java( PrimaryConstructor.CTOR_PARAM_FORMAT ), this.attributes ) ) ).asString(), new UncheckedText( new JoinedText( "\n", new Mapped<>( attr -> attr.java( PrimaryConstructor.CTOR_INIT_FORMAT ), this.attributes ) ) ).asString() ) ).asString(); } }
PrimaryConstructor { public String code() { return new UncheckedText( new FormattedText( "public %s(%s) {\n %s \n}", this.name, new UncheckedText( new JoinedText( ", ", new Mapped<>( attr -> attr.java( PrimaryConstructor.CTOR_PARAM_FORMAT ), this.attributes ) ) ).asString(), new UncheckedText( new JoinedText( "\n", new Mapped<>( attr -> attr.java( PrimaryConstructor.CTOR_INIT_FORMAT ), this.attributes ) ) ).asString() ) ).asString(); } PrimaryConstructor(final String ctor,
        final Iterable<Attribute> attrs); }
PrimaryConstructor { public String code() { return new UncheckedText( new FormattedText( "public %s(%s) {\n %s \n}", this.name, new UncheckedText( new JoinedText( ", ", new Mapped<>( attr -> attr.java( PrimaryConstructor.CTOR_PARAM_FORMAT ), this.attributes ) ) ).asString(), new UncheckedText( new JoinedText( "\n", new Mapped<>( attr -> attr.java( PrimaryConstructor.CTOR_INIT_FORMAT ), this.attributes ) ) ).asString() ) ).asString(); } PrimaryConstructor(final String ctor,
        final Iterable<Attribute> attrs); String code(); }
PrimaryConstructor { public String code() { return new UncheckedText( new FormattedText( "public %s(%s) {\n %s \n}", this.name, new UncheckedText( new JoinedText( ", ", new Mapped<>( attr -> attr.java( PrimaryConstructor.CTOR_PARAM_FORMAT ), this.attributes ) ) ).asString(), new UncheckedText( new JoinedText( "\n", new Mapped<>( attr -> attr.java( PrimaryConstructor.CTOR_INIT_FORMAT ), this.attributes ) ) ).asString() ) ).asString(); } PrimaryConstructor(final String ctor,
        final Iterable<Attribute> attrs); String code();  }