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

Auto-exclude delegated properties? #171

Open
edenman opened this issue Apr 4, 2017 · 8 comments
Open

Auto-exclude delegated properties? #171

edenman opened this issue Apr 4, 2017 · 8 comments

Comments

@edenman
Copy link
Contributor

edenman commented Apr 4, 2017

I've got a data class like this:

@PaperParcel
data class MyParcelable(val taco: String, val burrito: String) : PaperParcelable {
  companion object {
    @JvmField val CREATOR = PaperParcelMyParcelable.CREATOR
  }

  val calculatedProperty by lazy { taco + burrito }
}

which gives me:

e: /myproject/build/tmp/kapt3/stubs/release/domain/MyParcelable.java:6: error: All field type arguments must be specified.
e: 

e:     private final kotlin.Lazy calculatedProperty$delegate = null;

I know I can add my own exclude annotation and apply it to the field, but that sort of seems like overkill for a fairly normal usecase. Thoughts?

@grandstaish
Copy link
Owner

The transient keyword still works for excluding fields. In kotlin it's an annotation, e.g. @field:Transient

The error message here is not that helpful though. I guess kotlin.Lazy is a generic class but they neglect generics in the kapt Java stubs. Not sure what to do about that

@edenman
Copy link
Contributor Author

edenman commented Apr 4, 2017

ahhh, i didn't know about the @delegate:Transient syntax, that works for me.

@grandstaish
Copy link
Owner

As for auto-excluding these, I wonder if we could auto-exclude properties that end with $delegate or something (although that's an implementation detail so it might be ill advised). Hopefully all delegates inherit from some interface or base class, that'd make it easy. I'll leave this open for now and look into what the options are later.

@edenman
Copy link
Contributor Author

edenman commented Apr 4, 2017

Yeah, I'd be in favor of that. Although it might be a surprising change if there's anybody out there relying on the current behavior to save computation even over a parcel/unparcel cycle.

@Hazer
Copy link

Hazer commented May 11, 2017

@edenman @grandstaish There are 2 types of Delegates ReadOnlyProperty and ReadWriteProperty, the later one, may be a valid field to be saved. One use-case for a ReadWriteProperty is an Observable Field, no computations performed, just trigger some event.

So I believe excluding all delegates can be dangerous. At least a really nice warning should be raised.

@ansman
Copy link
Contributor

ansman commented Jun 8, 2017

I can't apply annotations to lazy properties, I get this error:
'@field: annotations could only be applied to properties with backing fields. Is there a workaround?

@grandstaish
Copy link
Owner

Does @delegate:Transient work?

@ansman
Copy link
Contributor

ansman commented Jun 9, 2017

Yup, worked perfectly 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants