yatatsu / AutoBundle

AutoBundle generates boilerplate code for field binding with android.os.Bundle
Apache License 2.0
135 stars 13 forks source link

Code generator works wrong #2

Closed mykola-dev closed 8 years ago

mykola-dev commented 8 years ago

Here is generated class:

public final class TariffAcceptingWithOffersActivityAutoBundle {
  public static com.matrixx.android.activity.IntentBuilder createIntentBuilder(boolean fromSurvey) {
    return new com.matrixx.android.activity.IntentBuilder(fromSurvey);
  }

  public static void bind(TariffAcceptingWithOffersActivity target, Intent intent) {
    if (intent.getExtras() != null) {
      bind(target, intent.getExtras());
    }
  }

  public static void bind(TariffAcceptingWithOffersActivity target, Bundle source) {
    if (source.containsKey("fromSurvey")) {
      target.fromSurvey = (boolean) source.getBoolean("fromSurvey");
    } else {
      throw new IllegalStateException("fromSurvey is required, but not found in the bundle.");
    }
  }

  public static void pack(TariffAcceptingWithOffersActivity source, Bundle args) {
    args.putBoolean("fromSurvey", source.fromSurvey);
  }

  public static final class IntentBuilder {
    final Bundle args;

    public IntentBuilder(boolean fromSurvey) {
      this.args = new Bundle();
      this.args.putBoolean("fromSurvey", fromSurvey);
    }

    public Intent build(Context context) {
      Intent intent = new Intent(context, TariffAcceptingWithOffersActivity.class);
      intent.putExtras(args);
      return intent;
    }

    public Intent build(Intent intent) {
      intent.putExtras(args);
      return intent;
    }
  }
}

It fails on resolving IntentBuilder http://i.imgur.com/WJ7c5uq.png

yatatsu commented 8 years ago

Thanks for your feedback. It seems to be wrong certainly. Could you show more detail? I'd like to see original and generated one.

mykola-dev commented 8 years ago

My activity is in com.matrixx.android.activity package activity has 1 @AutoBundle field i make binding in onCreate. Looks like generator only works ok when activity placed in the project root package

yatatsu commented 8 years ago

I see. It may be occurred in specific package placement. I'll try to reproduce it. Thanks.

yatatsu commented 8 years ago

Caller method for builder pointed to wrong package actually. I Fixed it, so try in 1.0.2.

compile 'com.github.yatatsu:autobundle:1.0.2'
apt 'com.github.yatatsu:autobundle-processor:1.0.2'
mykola-dev commented 8 years ago

thanks! it works now