Skip to content

Commit

Permalink
Change the default name of the outer interfaces to be `<BuilderClass>…
Browse files Browse the repository at this point in the history
…s`, instead of `<TargetClass>Builders`.
  • Loading branch information
skinny85 committed Jan 27, 2024
1 parent 585a595 commit 82bbfb4
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 7 deletions.
3 changes: 2 additions & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,8 @@ It has the following attributes (all of them are optional):

* `outerName` allows you to change the name of the outer interface that the per-property interfaces
will be generated inside of (this is in order not to pollute the global namespace).
The default name is `<BuiltClass>Builders`.
The default name is `<BuilderClass>s` (the name of the Builder class with an "s" at the end) -
so, if we're building a `Person` class, the default name will be `PersonBuilders`.
* `packageName` allows you to change the package the generated interfaces will reside in.
The default is for the interfaces to reside in the same package as the one the Builder will be generated in.
* `innerNames` allows you to set the pattern that will be used for naming the per-property generated interfaces.
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/jilt/Builder.java
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,8 @@
* Must be a valid Java (top-level) class name.
* <p>
* This is an optional attribute - the default is <code>&lt;TargetClass&gt;Builder</code>
* (for example, <code>PersonBuilder</code>).
* (so, for example, if we're building an instance of a <code>Person</code> class,
* the default name will be <code>PersonBuilder</code>).
*/
String className() default "";

Expand Down
7 changes: 5 additions & 2 deletions src/main/java/org/jilt/BuilderInterfaces.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,11 @@
* will be generated as inner interfaces of this outer interface,
* in order not to pollute the global namespace.
* <p>
* This is an optional attribute, the default name is <code>&lt;TargetClass&gt;Builders</code>
* (so, if we're building a <code>Person</code> class, the name will be <code>PersonBuilders</code>).
* This is an optional attribute, the default name is <code>&lt;BuilderClass&gt;</code>
* with an "s" appended to the end of the name
* (the Builder class's name is <code>&lt;TargetClass&gt;Builder</code> by default,
* but can be changed with the {@link Builder#className} attribute) -
* so, if we're building a <code>Person</code> class, the name will be <code>PersonBuilders</code>.
*/
String outerName() default "";

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/jilt/internal/AbstractBuilderGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ private String initBuilderClassPackage() {
}
}

private String builderClassStringName() {
protected final String builderClassStringName() {
String annotationBuilderClassName = builderAnnotation.className();
return annotationBuilderClassName.isEmpty()
? this.targetClassSimpleName() + "Builder"
Expand All @@ -282,7 +282,7 @@ protected final Filer filer() {
return filer;
}

protected final Name targetClassSimpleName() {
private Name targetClassSimpleName() {
return this.targetClassType.getSimpleName();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ protected final String outerInterfacesName() {
? ""
: builderInterfaces.outerName();
return nameFromAnnotation.isEmpty()
? this.targetClassSimpleName() + "Builders"
? this.builderClassStringName() + "s"
: nameFromAnnotation;
}

Expand Down
11 changes: 11 additions & 0 deletions src/test/java/org/jilt/test/OptionalsValueTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.jilt.test;

import org.jilt.test.data.optionals.NullableOptionalsWithOrderValueBuilder;
import org.jilt.test.data.optionals.OptionalsRawValue;
import org.jilt.test.data.optionals.OptionalsRawValueBuilder;
import org.jilt.test.data.optionals.OptionalsValue;
Expand Down Expand Up @@ -58,4 +59,14 @@ public void null_can_be_passed_to_optional_setter() {

assertThat(value.optional).isNull();
}

@Test
public void null_can_be_passed_to_unwrapped_optional_and_sets_empty() {
OptionalsWithOrderValue<String> value = NullableOptionalsWithOrderValueBuilder.<String>optionalsWithOrderValue()
.optional(null)
.build();

assertThat(value.optional).isEmpty();
assertThat(value.v).isNull();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import org.jilt.Builder;
import org.jilt.BuilderStyle;
import org.jilt.Opt;

import java.util.List;
import java.util.Optional;
import javax.annotation.Nullable;

@Builder(style = BuilderStyle.STAGED_PRESERVING_ORDER)
public final class OptionalsWithOrderValue<T> {
Expand All @@ -15,4 +17,10 @@ public OptionalsWithOrderValue(Optional<? extends List<? super T>> optional, Voi
this.optional = optional;
this.v = v;
}

@Builder(style = BuilderStyle.STAGED_PRESERVING_ORDER,
className = "NullableOptionalsWithOrderValueBuilder")
static <T> OptionalsWithOrderValue<T> unwrapped(@Nullable List<? super T> optional, @Opt Void v) {
return new OptionalsWithOrderValue<>(Optional.ofNullable(optional), v);
}
}

0 comments on commit 82bbfb4

Please sign in to comment.