Skip to content

Commit

Permalink
Merge pull request #346 from eamonnmcmanus/update-2016-06-15
Browse files Browse the repository at this point in the history
Update 2016-06-15
  • Loading branch information
eamonnmcmanus authored Jun 16, 2016
2 parents d4c6189 + 9697672 commit 73452e4
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,19 @@ ImmutableSet<ExecutableElement> toBuilderMethods(
return builderMethods;
}

/**
* Returns the types that are referenced by abstract methods in the builder, either as
* parameters or as return types.
*/
Set<TypeMirror> referencedTypes() {
Set<TypeMirror> types = new TypeMirrorSet();
for (ExecutableElement method :
ElementFilter.methodsIn(builderTypeElement.getEnclosedElements())) {
types.add(method.getReturnType());
for (VariableElement parameter : method.getParameters()) {
types.add(parameter.asType());
if (method.getModifiers().contains(Modifier.ABSTRACT)) {
types.add(method.getReturnType());
for (VariableElement parameter : method.getParameters()) {
types.add(parameter.asType());
}
}
}
return types;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ ${gwtCompatibleAnnotation}
${p.nullableAnnotation}$p.type $p #if ($foreach.hasNext) , #end
#end ) {
#foreach ($p in $props)
#if (!$p.kind.primitive && !$p.nullable && $builderTypeName == "")
#if (!$p.kind.primitive && !$p.nullable && ($builderTypeName == "" || !$isFinal))
## We don't need a null check if the type is primitive or @Nullable. We also don't need it
## if there is a builder, since the build() method will check for us. However, if there is a
## builder but there are also extensions (!$isFinal) then we can't omit the null check because
## the constructor is called from the extension code.

if ($p == null) {
throw new NullPointerException("Null $p.name");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,7 @@ public void correctBuilder() throws Exception {
"import com.google.common.base.Optional;",
"import com.google.common.collect.ImmutableList;",
"",
"import java.util.ArrayList;",
"import java.util.List;",
"import javax.annotation.Nullable;",
"",
Expand All @@ -607,21 +608,26 @@ public void correctBuilder() throws Exception {
" public abstract Builder<T> toBuilder();",
"",
" @AutoValue.Builder",
" public interface Builder<T extends Number> {",
" Builder<T> anInt(int x);",
" Builder<T> aByteArray(byte[] x);",
" Builder<T> aNullableIntArray(@Nullable int[] x);",
" Builder<T> aList(List<T> x);",
" Builder<T> anImmutableList(List<T> x);",
" ImmutableList.Builder<T> anImmutableListBuilder();",
" Builder<T> anOptionalString(Optional<String> s);",
" Builder<T> anOptionalString(String s);",
" public abstract static class Builder<T extends Number> {",
" public abstract Builder<T> anInt(int x);",
" public abstract Builder<T> aByteArray(byte[] x);",
" public abstract Builder<T> aNullableIntArray(@Nullable int[] x);",
" public abstract Builder<T> aList(List<T> x);",
" public abstract Builder<T> anImmutableList(List<T> x);",
" public abstract ImmutableList.Builder<T> anImmutableListBuilder();",
" public abstract Builder<T> anOptionalString(Optional<String> s);",
" public abstract Builder<T> anOptionalString(String s);",
"",
" public Builder<T> aList(ArrayList<T> x) {",
// ArrayList should not be imported in the generated class.
" return aList((List<T>) x);",
" }",
"",
" Optional<Integer> anInt();",
" List<T> aList();",
" ImmutableList<T> anImmutableList();",
" public abstract Optional<Integer> anInt();",
" public abstract List<T> aList();",
" public abstract ImmutableList<T> anImmutableList();",
"",
" Baz<T> build();",
" public abstract Baz<T> build();",
" }",
"",
" public static <T extends Number> Builder<T> builder() {",
Expand Down Expand Up @@ -742,7 +748,7 @@ public void correctBuilder() throws Exception {
" return new Builder<T>(this);",
" }",
"",
" static final class Builder<T extends Number> implements Baz.Builder<T> {",
" static final class Builder<T extends Number> extends Baz.Builder<T> {",
" private Integer anInt;",
" private byte[] aByteArray;",
" private int[] aNullableIntArray;",
Expand Down
14 changes: 0 additions & 14 deletions value/userguide/vertical_nav.md

This file was deleted.

0 comments on commit 73452e4

Please sign in to comment.