PrototypeZ / SaveState

:icecream: Generate 'onSaveInstanceState' and 'onRestoreInstanceState' methods for your application automatically
1.01k stars 79 forks source link

Bug: no way to use "private" for the fields #22

Open AndroidDeveloperLB opened 3 years ago

AndroidDeveloperLB commented 3 years ago

classpath "io.github.prototypez:save-state:0.2.3"

Example:

class MainActivity : AppCompatActivity() {
    @AutoRestore
    private var someInt: Long = 0L

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        if (savedInstanceState == null)
            someInt = System.currentTimeMillis()
        Log.d("AppLog", "someInt:$someInt")
    }
}

Error that I get:

C:\Users\User\Desktop\SaveStateSample\app\build\generated\source\kapt\debug\com\lb\savestatesample\MainActivityAutoSaveState.java:7: error: someInt has private access in MainActivity
    outState.putLong("someInt", instance.someInt);
                                        ^
C:\Users\User\Desktop\SaveStateSample\app\build\generated\source\kapt\debug\com\lb\savestatesample\MainActivityAutoSaveState.java:11: error: someInt has private access in MainActivity
    instance.someInt = savedInstanceState.getLong("someInt");
            ^

Sample: SaveStateSample.zip

PrototypeZ commented 3 years ago

Currently private fields are not support because my implementation relies on apt, changing the modifier to default or protected is a workaround

AndroidDeveloperLB commented 3 years ago

@PrototypeZ Can you please consider changing it so that it would work? It's quite a harsh requirement to force us to have such fields are non-private...

PrototypeZ commented 3 years ago

I'm refactering my plugin by using asm and private fields will be supported soon.

AndroidDeveloperLB commented 3 years ago

@PrototypeZ "asm" ? Assembly language?! You went this far? :)

PrototypeZ commented 3 years ago

Sorry acturally i mean using the ASM framework to manipulate byte codes inside the Transform Api...

AndroidDeveloperLB commented 3 years ago

I don't know what this is, but sounds complex too. Can it also generate java code from byte code?

PrototypeZ commented 3 years ago

@AndroidDeveloperLB yes, it's similar to annotation processor, but it can change class byte codes we write at compile time while annotation processor can only add new classes. :)

AndroidDeveloperLB commented 3 years ago

Wow cool! Sadly I never created anything that handles annotations. To me it seems like magic.

PrototypeZ commented 3 years ago

Thank you sir, actually I've read a lot of your answers on StackOverflow which helped me a lot, thank you so much. I'm so glad that you leave a comment on my repo. I'm not a native speaker so I'm not sure if i express my feelings properly, just let you know that I'm one of your fans. :)

AndroidDeveloperLB commented 3 years ago

@PrototypeZ Really? Thank you. Do you know perhaps of a nice tutorial (video is great too) of creating new annotations? Maybe it's time to play with this a bit. On both Java and Kotlin.

PrototypeZ commented 3 years ago

@AndroidDeveloperLB Hey I just found this post, I hope it helps. :)

AndroidDeveloperLB commented 3 years ago

@PrototypeZ I don't understand what it is. Sorry.

PrototypeZ commented 3 years ago

hey, don't worry. I'm not sure whether I misunderstand your intention, maybe it's me who needs to say sorry...please send me an email at prototypez@126.com and I can explain anything which you are confused with.

AndroidDeveloperLB commented 3 years ago

@PrototypeZ Doesn't matter. Forget it.