gabrielittner / auto-value-with

AutoValue extension to implement "with-er" methods for AutoValue objects
Apache License 2.0
138 stars 5 forks source link

Get methods are not handled properly #15

Closed bnorm closed 8 years ago

bnorm commented 8 years ago

When messing around with AutoValue and your extension, if a property has a getX() method, this is not handled properly. The generated with method will have the short form method calls - which don't exist - instead of the getX() method calls.

Let me know if you need an example and I can provide one.

gabrielittner commented 8 years ago

Added a failing test for this https://github.com/gabrielittner/auto-value-with/tree/prefixes I'll try to get a fix out later this week.

toadzky commented 8 years ago

Any word on this? This is causing a problem with Android's databinding because it requires bean-style getters.

gabrielittner commented 8 years ago

The snapshot is out now, a proper release will be out later today.

toadzky commented 8 years ago

i see the test. is there a fix in that PR? i didn't see one when i looked at it. it's still broken for me in 1.2

gabrielittner commented 8 years ago

The fix was part of #17. Can you give me a sample that doesn't work?

toadzky commented 8 years ago

want a whole project or just a file?

gabrielittner commented 8 years ago

Just pasting the file in here is enough.

toadzky commented 8 years ago

truncated stacktrace:

Error:(14, 17) error: @AutoValue processor threw an exception: java.lang.IllegalArgumentException: com.itworks.mobile.terminator.models.MailingAddress doesn't have property with name street which is required for withStreet()
at com.gabrielittner.auto.value.with.AutoValueWithExtension.getWithMethods(AutoValueWithExtension.java:65)
at com.gabrielittner.auto.value.with.AutoValueWithExtension.applicable(AutoValueWithExtension.java:108)
at com.google.auto.value.processor.AutoValueProcessor.processType(AutoValueProcessor.java:372)
at com.google.auto.value.processor.AutoValueProcessor.process(AutoValueProcessor.java:143)
...

class definition:

package datamodels;

import com.google.auto.value.AutoValue;

import android.databinding.BaseObservable;
import android.databinding.Bindable;
import android.os.Parcelable;
import android.support.annotation.Nullable;

/**
 * Created by toadzky on 4/28/16.
 */
@AutoValue
public abstract class MailingAddress extends BaseObservable implements Parcelable {

  public static final MailingAddress EMPTY = MailingAddress.builder().build();

  @Bindable
  public abstract String getStreet();

  @Bindable
  @Nullable
  public abstract String getAdditional();

  @Bindable
  public abstract String getCity();

  @Bindable
  public abstract String getDistrict();

  @Bindable
  public abstract String getCountry();

  @Bindable
  public abstract String getPostal();

  public abstract MailingAddress withStreet(String update);

  public abstract MailingAddress withAdditional(String update);

  public abstract MailingAddress withCity(String update);

  public abstract MailingAddress withDistrict(String update);

  public abstract MailingAddress withCountry(String update);

  public abstract MailingAddress withPostal(String update);

  private Builder toBuilder() {
    return new AutoValue_MailingAddress.Builder(this);
  }

  public static Builder builder() {
    return new AutoValue_MailingAddress.Builder();
  }

  @AutoValue.Builder
  public abstract static class Builder {
    public abstract Builder street(String street);

    public abstract Builder additional(String additional);

    public abstract Builder city(String city);

    public abstract Builder district(String district);

    public abstract Builder country(String country);

    public abstract Builder postal(String postal);

    public abstract MailingAddress build();

  }

}
gabrielittner commented 8 years ago

Does it work when you remove implements Parcelable?

toadzky commented 8 years ago

Yes. I'm using the auto-value-parcel extension as well. I guess it's an interaction between extensions.

gabrielittner commented 8 years ago

Someone else ran into that issue with auto-value-parcel + auto+value-gson. I've posted a workaround in that issue https://github.com/rharter/auto-value-parcel/issues/47