kyay10 / kotlin-hides-members

Apache License 2.0
0 stars 2 forks source link

Use other methods to solve the issue of not supporting higher versions of JDK, cancel and use reflection #2

Open DreamMoonCai opened 2 weeks ago

DreamMoonCai commented 2 weeks ago

HIDES.MEMBERD_NAMELIST is actually a LinkedHashSet, and in PluginRegistrar, it is allowed to add or remove it and continue to take effect in the future. The original project idea was to modify this field to its own Set object and always display it as included, but the reflection of constant fields seems to be not allowed in higher versions. We can try adding function names one by one to support related function coverage

Of course, adding them one by one is not appropriate and cannot be generalized. Perhaps we can go further and obtain all the functions in the project that use HidesMembers annotation, and write their function names into this Set collection. This may be possible to achieve

After testing, it was found that modifying the HIDES.MEMBERS-NAME_LIST set does not work in the extension of the registered extension, including the IrElementTransformer part. However, it seems that we can only easily obtain all functions through these, which is my guess

I use IrElementTransformer to record the annotated names of all properties and functions and write them to a file. Then, I read the file from PluginRegistrar and write it to HIDES.MEMBERD_NAME_LIST. After testing, this is feasible, but it may require two compilations. The first one is to obtain the property and function names with overwritten annotations, and the second one is to write them to Set. Finally, I share my code image, which will work

image image image I don't think my method is the best, but it works and I hope there is a better way

DreamMoonCai commented 2 weeks ago

I'm sorry, I'm a Chinese developer. The submitted content may have some issues with machine translation, but the meaning should be understandable

kyay10 commented 1 week ago

Thanks for discovering this!

Your solution seems apt, but my fear is that one needs to run compilation twice for it to take effect. I might experiment with making a FIR plugin that should do the same thing, but that runs before the frontend resolution runs so that we don't need to compile twice