https://kotlinlang.org logo
#ksp
Title
# ksp
c

Charlie Tapping

03/06/2023, 5:27 PM
If I have an annotated class Foo<T>, and I use the symbol information for the generic type T to create a file, should I tag the file spec with the originatingFile as T or Foo? What if multiple Ts make up a file, should all of them be tagged as the originating file? Any help is much appreciated
j

Jiaxiang

03/06/2023, 6:30 PM
what do you mean by
tag the file spec with the originatingFile as T or Foo
?
c

Charlie Tapping

03/06/2023, 6:32 PM
I’m using this kotlin poet ksp function TypeSpec.Builder.addOriginatingKSFile(ksFile: KSFile) in an attempt to help incremental compilation determine if the file really needs to be recompiled
j

Jiaxiang

03/06/2023, 6:45 PM
The part I don’t understand is
originatingFile as T or Foo
, originating file, as the name suggests, should be a file, not a type parameter or class. If you mean the file that contains the target type parameter
T
or target class
Foo
, aren’t they just the file that contains the annotated class? Or am I misunderstanding anything?
c

Charlie Tapping

03/07/2023, 10:21 AM
Well Foo and T (which could be anything the user chooses) are declared in different files, I only use symbol data from T in the creation of my code generated file, but Foo happens to be the class which is annotated . I’m trying to establish if T alone is sufficient or if changes to Foo (Like removing the annotation) would warrant it also being tagged as an originating file.
j

Jiaxiang

03/07/2023, 6:26 PM
It’s actually up to your processor’s logic, it might be enough to not take
Foo
into incremental if you do not care about the annotated class but only cares about the type parameter ( to the extent that even
Foo
is unresolved reference it still won’t affect your code generation logic).
c

Charlie Tapping

03/08/2023, 12:23 PM
Thank you!
17 Views