Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moe sync 12/05/2016 #407

Merged
merged 3 commits into from
Dec 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1253,10 +1253,6 @@ public static <T extends Number & Comparable<T>, U extends T> Builder<T, U> buil
return new AutoValue_AutoValueTest_GenericsWithBuilder.Builder<T, U>();
}

public Builder<T, U> toBuilderManual() {
return new AutoValue_AutoValueTest_GenericsWithBuilder.Builder<T, U>(this);
}

public abstract Builder<T, U> toBuilderGenerated();

@AutoValue.Builder
Expand All @@ -1274,21 +1270,13 @@ public void testBuilderGenerics() {
assertEquals(integers, instance.list());
assertEquals((Integer) 23, instance.u());

GenericsWithBuilder<Integer, Integer> instance2 = instance.toBuilderManual().build();
GenericsWithBuilder<Integer, Integer> instance2 = instance.toBuilderGenerated().build();
assertEquals(instance, instance2);
assertNotSame(instance, instance2);

GenericsWithBuilder<Integer, Integer> instance3 = instance.toBuilderManual().u(17).build();
GenericsWithBuilder<Integer, Integer> instance3 = instance.toBuilderGenerated().u(17).build();
assertEquals(integers, instance3.list());
assertEquals((Integer) 17, instance3.u());

GenericsWithBuilder<Integer, Integer> instance4 = instance.toBuilderGenerated().build();
assertEquals(instance, instance4);
assertNotSame(instance, instance4);

GenericsWithBuilder<Integer, Integer> instance5 = instance.toBuilderManual().u(17).build();
assertEquals(integers, instance5.list());
assertEquals((Integer) 17, instance5.u());
}

@AutoValue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
Expand Down Expand Up @@ -1404,10 +1406,6 @@ public static <T extends Number & Comparable<T>, U extends T> Builder<T, U> buil
return new AutoValue_AutoValueTest_GenericsWithBuilder.Builder<T, U>();
}

public Builder<T, U> toBuilderManual() {
return new AutoValue_AutoValueTest_GenericsWithBuilder.Builder<T, U>(this);
}

public abstract Builder<T, U> toBuilderGenerated();

@AutoValue.Builder
Expand All @@ -1425,21 +1423,13 @@ public void testBuilderGenerics() {
assertEquals(integers, instance.list());
assertEquals((Integer) 23, instance.u());

GenericsWithBuilder<Integer, Integer> instance2 = instance.toBuilderManual().build();
GenericsWithBuilder<Integer, Integer> instance2 = instance.toBuilderGenerated().build();
assertEquals(instance, instance2);
assertNotSame(instance, instance2);

GenericsWithBuilder<Integer, Integer> instance3 = instance.toBuilderManual().u(17).build();
GenericsWithBuilder<Integer, Integer> instance3 = instance.toBuilderGenerated().u(17).build();
assertEquals(integers, instance3.list());
assertEquals((Integer) 17, instance3.u());

GenericsWithBuilder<Integer, Integer> instance4 = instance.toBuilderGenerated().build();
assertEquals(instance, instance4);
assertNotSame(instance, instance4);

GenericsWithBuilder<Integer, Integer> instance5 = instance.toBuilderManual().u(17).build();
assertEquals(integers, instance5.list());
assertEquals((Integer) 17, instance5.u());
}

@AutoValue
Expand Down Expand Up @@ -2107,6 +2097,152 @@ public void testOneTwoThreeFour() {
.isEqualTo("OneTwoThreeFourImpl{one=one, two=two, three=false, four=4}");
}

@AutoValue
abstract static class OuterWithBuilder {
abstract String foo();
abstract InnerWithBuilder inner();
abstract Builder toBuilder();

static Builder builder() {
return new AutoValue_AutoValueTest_OuterWithBuilder.Builder();
}

@AutoValue.Builder
abstract static class Builder {
abstract Builder foo(String x);
abstract Builder inner(InnerWithBuilder x);
abstract InnerWithBuilder.Builder innerBuilder();

abstract OuterWithBuilder build();
}
}

@AutoValue
abstract static class InnerWithBuilder {
abstract int bar();
abstract Builder toBuilder();

static Builder builder() {
return new AutoValue_AutoValueTest_InnerWithBuilder.Builder();
}

@AutoValue.Builder
abstract static class Builder {
abstract Builder setBar(int x);

abstract InnerWithBuilder build();
}
}

public void testBuilderWithinBuilder() {
OuterWithBuilder x = OuterWithBuilder.builder()
.inner(InnerWithBuilder.builder()
.setBar(23)
.build())
.foo("yes")
.build();
assertThat(x.toString()).isEqualTo("OuterWithBuilder{foo=yes, inner=InnerWithBuilder{bar=23}}");

OuterWithBuilder.Builder xBuilder = x.toBuilder();
xBuilder.innerBuilder().setBar(17);
OuterWithBuilder y = xBuilder.build();
assertThat(y.toString()).isEqualTo("OuterWithBuilder{foo=yes, inner=InnerWithBuilder{bar=17}}");
}

public static class MyMap<K, V> extends HashMap<K, V> {
public MyMap() {}

public MyMap(Map<K, V> map) {
super(map);
}

public MyMapBuilder<K, V> toBuilder() {
return new MyMapBuilder<K, V>(this);
}
}

public static class MyMapBuilder<K, V> extends LinkedHashMap<K, V> {
public MyMapBuilder() {}

public MyMapBuilder(Map<K, V> map) {
super(map);
}

public MyMap<K, V> build() {
return new MyMap<K, V>(this);
}
}

@AutoValue
abstract static class BuildMyMap<K, V> {
abstract MyMap<K, V> map();

static <K, V> Builder<K, V> builder() {
return new AutoValue_AutoValueTest_BuildMyMap.Builder<K, V>();
}

@AutoValue.Builder
abstract static class Builder<K, V> {
abstract MyMapBuilder<K, V> mapBuilder();
abstract BuildMyMap<K, V> build();
}
}

public void testMyMapBuilder() {
BuildMyMap.Builder<String, Integer> builder = BuildMyMap.builder();
MyMapBuilder<String, Integer> mapBuilder = builder.mapBuilder();
mapBuilder.put("23", 23);
BuildMyMap<String, Integer> built = builder.build();
assertThat(built.map()).containsExactly("23", 23);
}

public static class MyStringMap<V> extends MyMap<String, V> {
public MyStringMap() {}

public MyStringMap(Map<String, V> map) {
super(map);
}

@Override public MyStringMapBuilder<V> toBuilder() {
return new MyStringMapBuilder<V>(this);
}
}

public static class MyStringMapBuilder<V> extends MyMapBuilder<String, V> {
public MyStringMapBuilder() {}

public MyStringMapBuilder(Map<String, V> map) {
super(map);
}

@Override public MyStringMap<V> build() {
return new MyStringMap<V>(this);
}
}

@AutoValue
abstract static class BuildMyStringMap<V> {
abstract MyStringMap<V> map();

static <V> Builder<V> builder() {
return new AutoValue_AutoValueTest_BuildMyStringMap.Builder<V>();
}

@AutoValue.Builder
abstract static class Builder<V> {
abstract MyStringMapBuilder<V> mapBuilder();
abstract BuildMyStringMap<V> build();
}
}

public void testMyStringMapBuilder() {
BuildMyStringMap.Builder<Integer> builder = BuildMyStringMap.builder();
MyStringMapBuilder<Integer> mapBuilder = builder.mapBuilder();
mapBuilder.put("23", 23);
BuildMyStringMap<Integer> built = builder.build();
assertThat(built.map()).containsExactly("23", 23);
}

static class VersionId {}

static class ItemVersionId extends VersionId {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import static com.google.common.collect.Sets.union;

import com.google.auto.common.MoreElements;
import com.google.auto.common.MoreTypes;
import com.google.auto.service.AutoService;
import com.google.auto.value.AutoValue;
import com.google.auto.value.extension.AutoValueExtension;
Expand Down Expand Up @@ -740,6 +741,7 @@ private TypeSimplifier defineVarsForType(
ImmutableSet<ExecutableElement> toBuilderMethods,
ImmutableSet<ExecutableElement> propertyMethods,
Optional<BuilderSpec.Builder> builder) {
DeclaredType declaredType = MoreTypes.asDeclared(type.asType());
Set<TypeMirror> types = new TypeMirrorSet();
types.addAll(returnTypesOf(propertyMethods));
if (builder.isPresent()) {
Expand All @@ -762,7 +764,7 @@ private TypeSimplifier defineVarsForType(
allMethodExcludedAnnotations(propertyMethods);
types.addAll(allMethodAnnotationTypes(propertyMethods, excludedAnnotationsMap));
String pkg = TypeSimplifier.packageNameOf(type);
TypeSimplifier typeSimplifier = new TypeSimplifier(typeUtils, pkg, types, type.asType());
TypeSimplifier typeSimplifier = new TypeSimplifier(typeUtils, pkg, types, declaredType);
vars.imports = typeSimplifier.typesToImport();
vars.generated = generatedTypeElement == null
? ""
Expand All @@ -775,7 +777,7 @@ private TypeSimplifier defineVarsForType(
List<Property> props = new ArrayList<Property>();
EclipseHack eclipseHack = eclipseHack();
ImmutableMap<ExecutableElement, TypeMirror> returnTypes =
eclipseHack.methodReturnTypes(propertyMethods, type);
eclipseHack.methodReturnTypes(propertyMethods, declaredType);
for (ExecutableElement method : propertyMethods) {
TypeMirror returnType = returnTypes.get(method);
String propertyType = typeSimplifier.simplify(returnType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.google.auto.value.processor;

import com.google.auto.value.processor.PropertyBuilderClassifier.PropertyBuilder;
import com.google.auto.value.processor.escapevelocity.Template;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
Expand Down Expand Up @@ -157,10 +158,11 @@ class AutoValueTemplateVars extends TemplateVars {
/**
* A map from property names to information about the associated property builder. A property
* called foo (defined by a method foo() or getFoo()) can have a property builder called
* fooBuilder(). The type of foo must be an immutable Guava type, like ImmutableSet, and
* fooBuilder() must return the corresponding builder, like ImmutableSet.Builder.
* fooBuilder(). The type of foo must be a type that has an associated builder following
* certain conventions. Guava immutable types such as ImmutableList follow those conventions,
* as do many {@code @AutoValue} types.
*/
ImmutableMap<String, BuilderSpec.PropertyBuilder> builderPropertyBuilders =
ImmutableMap<String, PropertyBuilder> builderPropertyBuilders =
ImmutableMap.of();

/**
Expand Down
Loading