yigit
04/19/2021, 3:28 PMyigit
04/19/2021, 3:28 PMyigit
04/19/2021, 3:28 PMelihart
04/19/2021, 3:30 PMgabrielfv
04/19/2021, 3:33 PMtargetLanguage
configuration. The way KSP works with its new api is by returning us elements like KSClassDeclaration
, but they all have enclosing elements, the top-level one being KSFile
yigit
04/19/2021, 3:36 PMenclosingTypeElement
in XExecutableElement
.
we need to make it nullable (due to target lang Kotlin) but also need to impelemnt a synthetic class when it is java. this is already something i would need to do regardless of this change (though room does not have that case, which is why it is not implemented 🤷 )gabrielfv
04/19/2021, 3:49 PMenclosingTypeElement
more generic to enclosingElement
or would that break many things? Perhaps a KSFile
abstraction could be useful for targetLanguage=kotlin
, however this kind of falls under the same problem of how we would deal with it on kaptyigit
04/19/2021, 3:52 PMenclosingElement
but that does not change the fact that we need to synthesize a class from KSFile when processed for java.
Otherwise, an annotation processor with javac in mind will have mine-fields when moving from kapt to ksp.
Also, maybe I need to make that change first because this will require some refactoring ont he room codebase.gabrielfv
04/19/2021, 3:53 PMgabrielfv
04/19/2021, 3:55 PMyigit
04/19/2021, 3:55 PMgabrielfv
04/19/2021, 3:58 PMyigit
04/19/2021, 4:10 PMyigit
04/19/2021, 4:27 PMXFile
(similar to KSFile
) or detect the package from the file and sysntesize an XPackageElement
for them.
I'm asking because making enclosingElement
nullable for XExecutableElement
feels a bit weird. can it really be null ?yigit
04/19/2021, 4:27 PMelihart
04/19/2021, 5:12 PMyigit
04/19/2021, 5:53 PMyigit
04/19/2021, 6:39 PMgabrielfv
04/19/2021, 8:29 PMKSFile
and PackageElement
. The interesting part I see here is navigating through an element´s siblings, but this is still different for either entities. Personally I don´t think we should try to emulate packages as elements, but what you guys think?gabrielfv
04/19/2021, 9:05 PMyigit
04/20/2021, 2:52 AMyigit
04/20/2021, 2:53 AMgabrielfv
04/20/2021, 3:10 PMXFile
.gabrielfv
04/20/2021, 3:10 PMyigit
04/20/2021, 3:11 PMgabrielfv
04/20/2021, 3:11 PMyigit
04/20/2021, 3:12 PMyigit
04/20/2021, 3:12 PMgabrielfv
04/20/2021, 3:12 PMyigit
04/20/2021, 3:13 PMyigit
04/20/2021, 3:13 PMyigit
04/20/2021, 3:13 PMgabrielfv
04/20/2021, 3:14 PMyigit
04/20/2021, 3:14 PMyigit
04/20/2021, 3:14 PMgabrielfv
04/20/2021, 3:15 PMgabrielfv
04/20/2021, 3:16 PMyigit
04/20/2021, 6:19 PMyigit
04/20/2021, 9:10 PMjava
.yigit
04/20/2021, 9:12 PMyigit
04/20/2021, 9:20 PMyigit
04/20/2021, 9:20 PMrequireTypeElement
yigit
04/20/2021, 9:21 PMyigit
04/20/2021, 9:31 PMyigit
04/20/2021, 9:57 PMyigit
04/21/2021, 2:55 PMyigit
04/21/2021, 2:57 PMmight
be OK to only support this for files in source though because for anything else, you really have no way of accessing them as far as I can see but I'll try to play with is. Especially, if a lib dependency has java + kotlin code where Java class has a reference to the generated class file from kotlin file, there should be a way to get that type & declarationyigit
04/21/2021, 3:07 PMgetClassDeclarationByName
. but if you never accessed it, it cannot. i'll file a bug to track, not sure how the right solution is. technically that class does not exist in KSP's realm but in practice it does exist and might be returned in different places.yigit
04/21/2021, 3:19 PMyigit
04/21/2021, 3:25 PMgabrielfv
04/21/2021, 5:06 PMgabrielfv
04/21/2021, 5:08 PMgabrielfv
04/21/2021, 5:10 PMyigit
04/21/2021, 5:43 PMTing-Yuan Huang
04/21/2021, 6:12 PMgetClassDeclarationByName
may need some tweaks, too. I need to check how it is generated in compiler and see how it can be delivered in KSP.Ting-Yuan Huang
04/21/2021, 6:17 PMfun getDeclarationsFromPackage(packageName: String): Sequence<KSDeclaration>
serve as an alternative for the need to access FileKt directly?
We are also working on getFunctionDeclarationByName
, getPropertyDeclarationByName
All of those enables accesses to top level declarations.
Sorry I'm still trying to catch up this thread and may ask stupid questions.yigit
04/21/2021, 7:56 PMTing-Yuan Huang
04/22/2021, 10:35 PM@JvmName
, etc. I guess it's fairly feasible to synthesize file classes in KSP. The other consideration is schedule; We may need to reprioritize existing tasks a little bit. Would this be a blocker for you guys?yigit
04/22/2021, 10:56 PMelihart
04/22/2021, 11:04 PMyigit
04/22/2021, 11:05 PMyigit
04/22/2021, 11:06 PMelihart
04/23/2021, 3:46 AMgabrielfv
04/23/2021, 4:14 PMyigit
04/24/2021, 12:59 AMclassName
to generate java code.
So,
I have a new prototype where I created a new type: XMemberContainer (name tbd). This interface provides two properties:
className : ClassName
type: XType?
type is nullable to indicate that this is not a real type in kotlin but className is mandatory to aide with java codegen.
@elihart / @gabrielfv If you can review this to see if it will address your use cases, that would be a huge help:
https://android-review.googlesource.com/c/platform/frameworks/support/+/1684749
It is still a prototype but i think it will pass all tests (i didn't add many tests yet but updated @elihart’s tests to not throw for top level elements)gabrielfv
04/24/2021, 7:14 PMgabrielfv
04/24/2021, 7:17 PMelihart
04/25/2021, 4:55 PMelihart
04/25/2021, 4:55 PMcheckNotNull(enclosingContainer) {
"XProcessing does not currently support annotations on top level " +
"functions with KSP. Cannot process $declaration."
}
elihart
04/25/2021, 4:56 PMyigit
04/26/2021, 3:23 PMyigit
04/26/2021, 3:28 PMyigit
04/26/2021, 3:29 PMyigit
04/26/2021, 3:44 PMyigit
04/26/2021, 3:44 PMyigit
04/26/2021, 3:44 PMyigit
04/26/2021, 3:46 PMyigit
04/26/2021, 3:49 PMclassName
😕yigit
04/26/2021, 4:24 PMTing-Yuan Huang
04/26/2021, 4:53 PMgetClassDeclarationByName
? I mean, I'm thinking about synthesizing it (like what you suggested a few days ago) and not sure if there are other approaches?Ting-Yuan Huang
04/26/2021, 4:56 PMTing-Yuan Huang
04/26/2021, 5:10 PMKSFunctionDeclaration
?yigit
04/26/2021, 5:12 PMyigit
04/26/2021, 5:12 PMMemberContainer
interface that has className
(that is class name in JavaPoet) which is enough to generate the java codeyigit
04/26/2021, 5:12 PMKSFile
BUT i don't have KSFile when the top level function is in a dependencyyigit
04/26/2021, 5:13 PMyigit
04/26/2021, 5:14 PMResolver.getSyntheticJvmClass(member : (KSFunctionDeclaration/KSPropertyDeclaration): String (qualified name)
yigit
04/26/2021, 5:19 PMKSFunctionDeclaration.qualifiedName
which is enough to generate kotlin code to call it but not enough to generate Java codeTing-Yuan Huang
04/26/2021, 5:19 PMyigit
04/26/2021, 6:00 PMyigit
04/26/2021, 9:41 PM/
and $
for nested).
I've not tried Arrays yet but from what i read in the source code, it will also add []
for themyigit
04/26/2021, 9:57 PMTing-Yuan Huang
04/26/2021, 10:05 PMTing-Yuan Huang
04/26/2021, 10:07 PMTing-Yuan Huang
04/26/2021, 10:21 PMyigit
04/26/2021, 10:33 PMyigit
04/26/2021, 10:33 PMyigit
04/26/2021, 10:39 PMelihart
04/26/2021, 10:40 PMgabrielfv
04/27/2021, 5:37 PM