SaveState icon indicating copy to clipboard operation
SaveState copied to clipboard

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

Open AndroidDeveloperLB opened this issue 4 years ago • 14 comments

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

AndroidDeveloperLB avatar Feb 15 '21 08:02 AndroidDeveloperLB

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

PrototypeZ avatar Mar 07 '21 13:03 PrototypeZ

@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...

AndroidDeveloperLB avatar Mar 07 '21 14:03 AndroidDeveloperLB

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

PrototypeZ avatar Mar 07 '21 15:03 PrototypeZ

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

AndroidDeveloperLB avatar Mar 07 '21 15:03 AndroidDeveloperLB

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

PrototypeZ avatar Mar 07 '21 15:03 PrototypeZ

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

AndroidDeveloperLB avatar Mar 07 '21 16:03 AndroidDeveloperLB

@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. :)

PrototypeZ avatar Mar 08 '21 00:03 PrototypeZ

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

AndroidDeveloperLB avatar Mar 08 '21 07:03 AndroidDeveloperLB

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. :)

PrototypeZ avatar Mar 09 '21 00:03 PrototypeZ

@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.

AndroidDeveloperLB avatar Mar 09 '21 09:03 AndroidDeveloperLB

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

PrototypeZ avatar Mar 11 '21 07:03 PrototypeZ

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

AndroidDeveloperLB avatar Mar 11 '21 08:03 AndroidDeveloperLB

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 [email protected] and I can explain anything which you are confused with.

PrototypeZ avatar Mar 12 '21 07:03 PrototypeZ

@PrototypeZ Doesn't matter. Forget it.

AndroidDeveloperLB avatar Mar 12 '21 07:03 AndroidDeveloperLB