Skip to content

Commit 5fa891f

Browse files
committed
Fix tests, did not see how getters worked initially
1 parent 2856e27 commit 5fa891f

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

value/src/main/java/com/google/auto/value/processor/autovalue.vm

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,10 +290,13 @@ ${gwtCompatibleAnnotation}
290290

291291
@Override
292292
${p.nullableAnnotation}public $builderGetters[$p.name].type ${p.getter}() {
293-
#set ($getterOptional = $builderGetters[$p.name].optional)
294-
#if ($getterOptional)
293+
#if ($builderGetters[$p.name].optional)
295294

296-
return ${getterOptional.rawType}.${getterOptional.nullable}($p);
295+
if ($p == null) {
296+
return $builderGetters[$p.name].optional.empty;
297+
} else {
298+
return ${builderGetters[$p.name].optional.rawType}.of($p);
299+
}
297300

298301
#else
299302
#if ($builderRequiredProperties.contains($p))

value/src/test/java/com/google/auto/value/processor/CompilationTest.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -793,7 +793,11 @@ public void correctBuilder() throws Exception {
793793
"",
794794
" @Override",
795795
" public Optional<Integer> anInt() {",
796-
" return Optional.fromNullable(anInt)",
796+
" if (anInt == null) {",
797+
" return Optional.absent();",
798+
" } else {",
799+
" return Optional.of(anInt);",
800+
" }",
797801
" }",
798802
"",
799803
" @Override",

0 commit comments

Comments
 (0)