yigit
03/19/2021, 6:51 PMgmazzo
03/22/2021, 1:56 PMgetSymbolsWithAnnotation
seems not to pick up annotation used in function/constructors parameters.
Basically this works:
class MyClass(@Builder val param: String)
but this doesn’t:
class MyClass(@Builder param: String)
inDepth
seems to have no effect either 🤔leandro
03/22/2021, 7:12 PMparth
03/23/2021, 12:04 PMTing-Yuan Huang
03/24/2021, 9:44 PM-Pksp.version.check=false
.
• Supported Gradle 7.0-rc-1.
API / behavior changes
• Use-site annotations are now attached to use-sites consistently. Previously, they are attached to where they were declared if the source is available, and the use-sites if the source isn't available.
As always, please give it a try and let us know what you think, especially on the API design!Ademir Queiroga
03/26/2021, 6:30 PMKSName.asString()
. What is strange is that I had a working version of my processor but after a few changes in the project structure (moved classes do different packages and so on) this error is now happening.
I am basically trying to get the qualified name or the simple name of a Kotlin annotation class.
Basically this is the code:
annotation as KSAnnotation
val declaration = annotation.annotationType.resolve().declaration
val qualifiedName = (declaration.qualifiedName ?: declaration.simpleName).asString()
val className = ClassName.bestGuess(qualifiedName)
If I print declaration
I can already see the string “Error type synthetic declaration”Ademir Queiroga
03/28/2021, 3:02 PMDependencies
instance by just adding the symbol.containingFile
and also tried by adding all the files of the inherited interfaces. For more context, I am generating classes base on an annotated interface which can then inherit from other interfaces.Arkadii Ivanov
04/01/2021, 4:32 PMevant
04/04/2021, 3:10 PMKSP now handles annotation use site targets internally for property accessors (namely,@get:Anno
).@set:Anno
property accessors will have corresponding targeted annotations from their receiver properties
annotations withI had this code to find a getter annotation on a constructor val and it's no longer finding itand@get:
targets will not appear in property's annotation list.@set:
class Foo(@get:Annotation val bar: String)
fun KSAnnotated.hasAnnotation(className: String, useSiteTarget: AnnotationUseSiteTarget? = null): Boolean {
return annotations.any {
it.annotationType.resolve().declaration.qualifiedName?.asString() == className &&
useSiteTarget == it.useSiteTarget
}
}
override fun hasAnnotation(className: String): Boolean {
return declaration.getter?.hasAnnotation(className) == true ||
declaration.hasAnnotation(className, AnnotationUseSiteTarget.GET)
}
Ademir Queiroga
04/05/2021, 10:12 PMtypeParameters
from this object
I tried a few things already but without success.
object SchemeProperty : ValueModifier<String, String>{ ... }
Jiaxiang
04/07/2021, 10:52 PMResolver.getDeclarationsFromPackage()
API, this API is to retrieve declarations with a given package name from both classpath and sources. Note that this API can be expensive.
• Bug fixes around generic type arguments and jvm_static detection.
Please take a try and let us know if you have any comments!Maik
04/13/2021, 8:46 AM@ErrorID val errorID = 0xA03L
Is it possible to implement such a requirement with ksp or would it require building a Kotlin compiler plugin?evant
04/15/2021, 3:49 PMTimo Drick
04/16/2021, 9:17 PMe: java.io.IOException: No such file or directory
at java.base/java.io.UnixFileSystem.createFileExclusively(Native Method)
at java.base/java.io.File.createNewFile(File.java:1026)
Full backstack in Thread.
When i delete the "generated/ksp" folder it compiles.
Source code of my processor: https://gitlab.com/compose1/livecomposable/-/blob/develop/hotreload_ksp_processor/[…]in/kotlin/de/appsonair/compose/processor/hotreload_processor.ktelihart
04/17/2021, 6:48 PMResolver.getDeclarationsFromPackage()
and javac’s Elements.getPackageElement
Doesn’t seem like it should be too hard. I created a ticket https://issuetracker.google.com/issues/185609823yigit
04/19/2021, 3:28 PMrusshwolf
04/20/2021, 8:25 PMTing-Yuan Huang
04/22/2021, 2:07 AMSymbolProcessorProvider
to get rid of the need of saving logger, options, CodeGenerator, etc in SymbolProcessor.init()
, which will be deprecated in the future. To use the new entry point, you'll need to register SymbolProcessorProvider
rather than SymbolProcessor
in the service file. Please find more details in the release note. Thank you @edrd for the PR!
2. Introduced getFunctionDeclarationByName
and getPropertyDeclarationByName
3. Fixed a few issues around incremental processing and multiple-round.
As always, please give it a try and let us know what you think!Zac Sweers
04/28/2021, 12:07 AMZac Sweers
04/30/2021, 4:02 AM1.5.0-alpha09
rolled out? I get mixed messages from my build about whether it exists on central and the github release doesn't look intentional/filled outnatario1
05/03/2021, 3:20 PMnatario1
05/03/2021, 4:06 PM@Function
annotation. May be a weird idea but what I'm thinking is:
• add a fake JVM target which reads the non-JVM source set
• run KSP on this target, count @Function
s or any other read-only symbol operation
• have compilation fail, we don't care because it's a fake target
Would this be possible? I'm not sure if KSP gets a chance to run if the source set is not compilable (it has non-JVM imports, non-JVM dependencies...)Ting-Yuan Huang
05/05/2021, 11:55 PMyigit
05/06/2021, 2:03 AMgetClassDeclarationByName
that supports KSTypeAlias
.
I'm honestly not sure what is the right behavior here.
I think in XProcessing, we'll just resolve them immediately as we wrap which might cause some confusion but will work fine (except for the fact that generated code would access the resolved type rather than type alias).
But i don't know if there are other cases where processors would need to find classes by type aliasJiaxiang
05/08/2021, 12:26 AMCollection
to Sequence
for a better performance. This change will need your attention as Sequence
is lazily evaluated and requires a terminal operation to make it actually compute. Here is my API change, please kindly take a look and leave comments in case of any concerns. The most important item I want to hear from you is if your use case involves some operations that is not feasible with a sequence, like indexed access operation which is only possible on a List (while you can still call .toList()
on a sequence to do that, if this becomes a common use case, it might make more sense to just make it List
)natario1
05/10/2021, 1:24 PMkotlin {
jvm()
jvm("foo")
}
Is this on the roadmap? One solution could be creating per-target ksp configurations like kspJvmFoo
, inheriting from the root ksp
. I'm happy to work on a PR if the team agrees with the plan.evant
05/10/2021, 6:48 PMJiaxiang
05/12/2021, 11:59 PMSequence
for a bunch of APIs
◦ Some of the API return type has been changed from Collection
or List
to Sequence
, which will allow performance improvement if you use case involved early termination.
◦ Note that because Sequence
is lazily evaluated, it requires a terminal operation to make actual compute happen. Please check you uses around the impacted APIs to see if they have a terminal operation. Most common use case is Collection.map{}
which will iterate through the collection by itself, but is non-terminal for Sequence
and should be companied with toList()
or replaced with forEach
◦ For the whole list of APIs impacted by this change, please refer to this commit.
• Origin for KS symbols from binaries is now split into KOTLIN_LIB
and JAVA_LIB
.Ting-Yuan Huang
05/14/2021, 5:39 PMmaster
to main
. If you don't have a local copy of KSP source code, please feel free to ignore this message. If you do, you may want to update origin
by git branch -u origin/main <your-local-branch>
and git remote set-head origin -a
.efemoney
05/18/2021, 1:07 PMKSTypeReference.resolve()
)? in terms of performance.
I’m mildly curious because the docs say to avoid it unless necessary but it might affect correctness if you don’t resolve 🤔
For example: I have these functions trying to check if a class (KSClassDeclaration
) extends a particular abstract class (with fqcn KSName
)
//
classDeclaration.superTypes.any { it.isClassWithName(superClassName) }
//
private fun KSTypeReference.isClassWithName(className: KSName): Boolean =
element?.isClassWithName(className) == true
// Wondering if its necessary to resolve type reference like below or is above name comparison sufficient
// && resolve() == resolver.getClassDeclarationByName(className)?.asType()
private fun KSReferenceElement.isClassWithName(className: KSName): Boolean {
return when (val ref = this) {
is KSParenthesizedReference -> ref.element.isClassWithName(className)
is KSClassifierReference -> {
val name = ref.referencedName(). // This is a simple text comparison and can break depending on what code the end user writes :(
className.asString().commonSuffixWith(name) == name
}
else -> false
}
}