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

Report INNER modifier for class descriptors #232

Merged
merged 1 commit into from
Jan 6, 2021

Conversation

yigit
Copy link
Collaborator

@yigit yigit commented Jan 6, 2021

This PR fixes a bug where the inner modifier would be lost if the
kotlin sources is in dependencies (when wrapped in a descriptor).

Unfortunately, for descriptors, there is no easy way to distinguish
between JAVA_STATIC and INNER. That is, if a java nested class that is
annotated with STATIC is compiled, descriptor API will no longer report
any modifiers for it. Similarly, if a Java inner class (that has no
static annotation) is compiled, we'll start reporting INNER for it.
Even though this is slightly confusing, it is at least consistent from a
kotlin perspective.

Also fixed a bug in multi-module testing setup where we were NOT
compiling java sources in test modules.

Fixes: #231
Test: javaModifiers

more test cases

report inner for descriptors

This PR fixes a bug where the inner modifier would be lost if the
kotlin sources is in dependencies (when wrapped in a descriptor).

Unfortunately, for descriptors, there is no easy way to distinguish
between JAVA_STATIC and INNER. That is, if a java nested class that is
annotated with STATIC is compiled, descriptor API will no longer report
any modifiers for it. Similarly, if a Java inner class (that has no
static annotation) is compiled, we'll start reporting INNER for it.
Even though this is slightly confusing, it is at least consistent from a
kotlin perspective.

Also fixed a bug in multi-module testing setup where we were NOT
compiling java sources in test modules.

Fixes: google#231
Test: javaModifiers

more test cases

report inner for descriptors
@yigit yigit requested a review from ting-yuan January 6, 2021 04:03
@ting-yuan ting-yuan merged commit 97c47e4 into google:master Jan 6, 2021
copybara-service bot pushed a commit to androidx/androidx that referenced this pull request Jan 6, 2021
Nested classes in kotlin are static by default.
This CL updates KspHasModifiers to add the static
modifier when it is a nested kotlin class without the
inner modifier.

A possible alternative solution is to add `isInner` to XTypeElement
because Room is using isStatic as a proxy to discover inner classes.
I've not implemented that because removing isStatic is not very feasible
from XHasModifiers but we can do a followup CL to divide XHasModifiers
and remove isStatic from there.

Right now, KSP does not report INNER modifier for .class files which is
why I couldn't add a test with compiled code.
google/ksp#232

I've also renamed KspTypeElementTest to XTypeElementTest since
it runs all but 1 test w/ both processors.

Bug: 160322705
Test: XTypeElementTest
Change-Id: Ie07382a8744b26eda3b4454d45ea74bfae71fd70
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

Successfully merging this pull request may close these issues.

JAVA_STATIC / INNER modifiers are lost in descriptors
2 participants