-
Notifications
You must be signed in to change notification settings - Fork 264
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
enum constants in java sources are reported as properties #234
Comments
it works fine for the descriptor implementation (they are reported as KSClassDeclaration instances with type ENUM_ENTRY) |
this seems not very trivial because PsiEnumConstant does not have a PsiClass that represents that entry :/. We could also possibly implement KSClassDeclaration from a PsiEnumConstant but that adds more variety. |
This PR fixes a bug in KSClassDeclarationJavaImpl where it would return properties for its enum constants instead of returning class declarations. Unfortunately, PsiEnumConstant does not have an API to resolve it as a class. So instead, this PR delegates to the descriptor implementation for these fields. Fixes: google#234 Test: classKinds
Fixed in #238 |
Enum classes are slightly different than other classes where they have inner classes/properties that are actually enum constants. Moreoever, KSP returns those constants as class declarations whereas java AP returns them as fields. To avoid possibly confusions, this CL adds a new XEnumTypeElement with a field to receive enum constant names. Subsequently, java implementation of XTypeElement was returning enum constants as if they are fields, I've removed them from that list as well. As part of this change, I've removed XType.isEnum and instead added XTypeElement.isEnum which can also do the auto cast to XEnumTypeElement. Also refactored EnumColumnTypeAdapter to use the new APIs. Note that there is an existing bug in KSP where it does not report enum constants properly from java sources so for now, I've excluded that case from tests: google/ksp#234 I've copied the EnumColumnTypeAdapterTest to also run in room kotlin test app so that we can ensure KSP is working propery (it was failing). Bug: 160322705 Bug: 173236324 Test: XTypeElementTest, EnumColumnTypeAdapterTest.kt Change-Id: Ie6d74cc5ccd93ed6be2687cdb382baf9dee16a0f
This issue (google/ksp#234) was already fixed in an earlier version but looks like i forgot to remove the TODO. Test exclusion was removed here: https://android-review.googlesource.com/c/platform/frameworks/support/+/1543326/7/room/compiler-processing/src/test/java/androidx/room/compiler/processing/XTypeElementTest.kt Bug: 160322705 Test: n/a Change-Id: Ib36361b8d6598ea18d5f332ee38f62af1b532efc
For the following two inputs:
When traversing declarations in
KotlinEnum
andJavaEnum
, enum constants ofJavaEnum
are returned as KSPropertyDeclaration instances while enum constants ofKotlinEnum
are returned as KSClassDeclarations with the proper kind (ENUM_ENTRY
)Java Annotation Processing also returns them as fields for the java source code but i think for KSP, to be consistent, it is better to report them as
KSClassDeclaration
s.I've not checked what happens with descriptors, will update the bug.
The text was updated successfully, but these errors were encountered: