https://kotlinlang.org logo
Join the conversationJoin Slack
Channels
100daysofcode
100daysofkotlin
100daysofkotlin-2021
advent-of-code
aem
ai
alexa
algeria
algolialibraries
amsterdam
android
android-architecture
android-databinding
android-studio
androidgithubprojects
androidthings
androidx
androidx-xprocessing
anime
anko
announcements
apollo-kotlin
appintro
arabic
argentina
arkenv
arksemdevteam
armenia
arrow
arrow-contributors
arrow-meta
ass
atlanta
atm17
atrium
austin
australia
austria
awesome-kotlin
ballast
bangladesh
barcelona
bayarea
bazel
beepiz-libraries
belgium
berlin
big-data
books
boston
brazil
brikk
budapest
build
build-tools
bulgaria
bydgoszcz
cambodia
canada
carrat
carrat-dev
carrat-feed
chicago
chile
china
chucker
cincinnati-user-group
cli
clikt
cloudfoundry
cn
cobalt
code-coverage
codeforces
codemash-precompiler
codereview
codingame
codingconventions
coimbatore
collaborations
colombia
colorado
communities
competitive-programming
competitivecoding
compiler
compose
compose-android
compose-desktop
compose-hiring
compose-ios
compose-mp
compose-ui-showcase
compose-wear
compose-web
connect-audit-events
corda
cork
coroutines
couchbase
coursera
croatia
cryptography
cscenter-course-2016
cucumber-bdd
cyprus
czech
dagger
data2viz
databinding
datascience
dckotlin
debugging
decompose
decouple
denmark
deprecated
detekt
detekt-hint
dev-core
dfw
docs-revamped
dokka
domain-driven-design
doodle
dsl
dublin
dutch
eap
eclipse
ecuador
edinburgh
education
effective-kotlin
effectivekotlin
emacs
embedded-kotlin
estatik
event21-community-content
events
exposed
failgood
fb-internal-demo
feed
firebase
flow
fluid-libraries
forkhandles
forum
fosdem
fp-in-kotlin
framework-elide
freenode
french
fritz2
fuchsia
functional
funktionale
gamedev
ge-kotlin
general-advice
georgia
geospatial
german-lang
getting-started
github-workflows-kt
glance
godot-kotlin
google-io
gradle
graphic
graphkool
graphql
graphql-kotlin
graviton-browser
greece
grpc
gsoc
gui
hackathons
hacktoberfest
hamburg
hamkrest
helios
helsinki
hexagon
hibernate
hikari-cp
hire-me
hiring
hongkong
hoplite
http4k
hungary
hyderabad
image-processing
india
indonesia
inkremental
intellij
intellij-plugins
intellij-tricks
internships
introduce-yourself
io
ios
iran
israel
istanbulcoders
italian
jackson-kotlin
jadx
japanese
jasync-sql
java-to-kotlin-refactoring
javadevelopers
javafx
javalin
javascript
jdbi
jhipster-kotlin
jobsworldwide
jpa
jshdq
juul-libraries
jvm-ir-backend-feedback
jxadapter
k2-early-adopters
kaal
kafka
kakao
kalasim
kapt
karachi
karg
karlsruhe
kash_shell
kaskade
kbuild
kdbc
kgen-doc-tools
kgraphql
kinta
klaxon
klock
kloudformation
kmdc
kmm-español
kmongo
knbt
knote
koalaql
koans
kobalt
kobweb
kodein
kodex
kohesive
koin
koin-dev
komapper
kondor-json
kong
kontent
kontributors
korau
korean
korge
korim
korio
korlibs
korte
kotest
kotest-contributors
kotless
kotlick
kotlin-asia
kotlin-beam
kotlin-by-example
kotlin-csv
kotlin-data-storage
kotlin-foundation
kotlin-fuel
kotlin-in-action
kotlin-inject
kotlin-latam
kotlin-logging
kotlin-multiplatform-contest
kotlin-mumbai
kotlin-native
kotlin-pakistan
kotlin-plugin
kotlin-pune
kotlin-roadmap
kotlin-samples
kotlin-sap
kotlin-serbia
kotlin-spark
kotlin-szeged
kotlin-website
kotlinacademy
kotlinbot
kotlinconf
kotlindl
kotlinforbeginners
kotlingforbeginners
kotlinlondon
kotlinmad
kotlinprogrammers
kotlinsu
kotlintest
kotlintest-devs
kotlintlv
kotlinultimatechallenge
kotlinx-datetime
kotlinx-files
kotlinx-html
kotrix
kotson
kovenant
kprompt
kraph
krawler
kroto-plus
ksp
ktcc
ktfmt
ktlint
ktor
ktp
kubed
kug-leads
kug-torino
kvision
kweb
lambdaworld_cadiz
lanark
language-evolution
language-proposals
latvia
leakcanary
leedskotlinusergroup
lets-have-fun
libgdx
libkgd
library-development
linkeddata
lithuania
london
losangeles
lottie
love
lychee
macedonia
machinelearningbawas
madrid
malaysia
mathematics
meetkotlin
memes
meta
metro-detroit
mexico
miami
micronaut
minnesota
minutest
mirror
mockk
moko
moldova
monsterpuzzle
montreal
moonbean
morocco
motionlayout
mpapt
mu
multiplatform
mumbai
munich
mvikotlin
mvrx
myndocs-oauth2-server
naming
navigation-architecture-component
nepal
new-mexico
new-zealand
newname
nigeria
nodejs
norway
npm-publish
nyc
oceania
ohio-kotlin-users
oldenburg
oolong
opensource
orbit-mvi
osgi
otpisani
package-search
pakistan
panamá
pattern-matching
pbandk
pdx
peru
philippines
phoenix
pinoy
pocketgitclient
polish
popkorn
portugal
practical-functional-programming
proguard
prozis-android-backup
pyhsikal
python
python-contributors
quasar
random
re
react
reaktive
realm
realworldkotlin
reductor
reduks
redux
redux-kotlin
refactoring-to-kotlin
reflect
refreshversions
reports
result
rethink
revolver
rhein-main
rocksdb
romania
room
rpi-pico
rsocket
russian
russian_feed
russian-kotlinasfirst
rx
rxjava
san-diego
science
scotland
scrcast
scrimage
script
scripting
seattle
serialization
server
sg-user-group
singapore
skia-wasm-interop-temp
skrape-it
slovak
snake
sofl-user-group
southafrica
spacemacs
spain
spanish
speaking
spek
spin
splitties
spotify-mobius
spring
spring-security
squarelibraries
stackoverflow
stacks
stayhungrystayfoolish
stdlib
stlouis
strife-discord-lib
strikt
students
stuttgart
sudan
swagger-gradle-codegen
swarm
sweden
swing
swiss-user-group
switzerland
talking-kotlin
tallinn
tampa
teamcity
tegal
tempe
tensorflow
terminal
test
testing
testtestest
texas
tgbotapi
thailand
tornadofx
touchlab-tools
training
tricity-kotlin-user-group
trójmiasto
truth
tunisia
turkey
turkiye
twitter-feed
uae
udacityindia
uk
ukrainian
uniflow
unkonf
uruguay
utah
uuid
vancouver
vankotlin
vertx
videos
vienna
vietnam
vim
vkug
vuejs
web-mpp
webassembly
webrtc
wimix_sentry
wwdc
zircon
Powered by Linen
ksp
  • y

    yigit

    03/19/2021, 6:51 PM
    Looking for some feedback on how to handle repeated annotations in XProcessing (but relevant to any user of KSP). (in thread)
    a
    • 2
    • 8
  • g

    gmazzo

    03/22/2021, 1:56 PM
    Hi there, can someone help me confirm this this is an issue or we are using it wrong? https://github.com/google/ksp/issues/351
    getSymbolsWithAnnotation
    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 🤔
    👀 1
    y
    • 2
    • 1
  • l

    leandro

    03/22/2021, 7:12 PM
    Apologies if this question isn’t appropriate to KSP, as my understanding of it is quite small. Let’s say I have several classes that inherit from an interface throughout my project, and would like to create some kind of output (CSV or so, not to be used in the project) that looks at all implementations of that interface together with its properties (e.g. a Map with simple types/enums). Would it be possible with KSP to do such a thing? Or should I look for a fully fledged compiler plugin?
    t
    j
    +2
    • 5
    • 10
  • p

    parth

    03/23/2021, 12:04 PM
    lemme know if you want me to file a GH issue, or if this is a KI already
    y
    t
    • 3
    • 6
  • t

    Ting-Yuan Huang

    03/24/2021, 9:44 PM
    Hi, here is the latest KSP bi-weekly release: Highlights • Multiplatform is back working again for JVM platform. • Corresponding Kotlin version is bumped to 1.4.31. This release still works with 1.4.30. To mute the version mismatch warning when using with Kotlin-1.4.30, use 
    -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!
    🎉 3
    b
    r
    • 3
    • 7
  • a

    Ademir Queiroga

    03/26/2021, 6:30 PM
    Hello everyone! Iam receiving an error when calling
    KSName.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”
    y
    • 2
    • 13
  • a

    Ademir Queiroga

    03/28/2021, 3:02 PM
    Guys, I am struggling on making my processor incremental. I am receiving some exceptions when modifying a dependency, sometimes it’s a NPE, sometimes it’s an ArrayOutOfBounds, but if I re-run everything executes just fine. I already tried to create the
    Dependencies
    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.
    z
    t
    • 3
    • 11
  • a

    Arkadii Ivanov

    04/01/2021, 4:32 PM
    Hello! I am exploring KSP to write a compiler plugin, something like Parcelize, so it would implement a predefined interface for annotated classes. Like you have a data class that implements the interface but you don't write the actual implementation code. And then you annotate the class with a marker annotation and the plugin should add the implementation. Is it a doable task for KSP?
    j
    t
    • 3
    • 5
  • e

    evant

    04/04/2021, 3:10 PM
    Can someone explain the change
    KSP 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 with
    @get:
    and
    @set:
    targets will not appear in property's annotation list.
    I had this code to find a getter annotation on a constructor val and it's no longer finding it
    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)
    }
    y
    • 2
    • 4
  • a

    Ademir Queiroga

    04/05/2021, 10:12 PM
    Hello everyone! I’m am trying to improve my processor and I am struggling to get the
    typeParameters
    from this
    object
    I tried a few things already but without success.
    object SchemeProperty : ValueModifier<String, String>{ ... }
    j
    • 2
    • 4
  • j

    Jiaxiang

    04/07/2021, 10:52 PM
    Hi, here is the latest KSP release: Highlights • Updated Kotlin version to 1.4.32 • Added 
    Resolver.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!
    🎉 13
    e
    g
    • 3
    • 2
  • m

    Maik

    04/13/2021, 8:46 AM
    Hi everyone! I have a multi-module/libraries Android Kotlin project and would like to check the uniqueness of ID's across module/libraries boundaries. The ID's have the following code structure:
    @ErrorID val errorID = 0xA03L
    Is it possible to implement such a requirement with ksp or would it require building a Kotlin compiler plugin?
    j
    f
    +2
    • 5
    • 7
  • e

    evant

    04/15/2021, 3:49 PM
    getting this error on an incremental build, I assume this is a bug? What info would be helpful here?
    Untitled
    y
    t
    a
    • 4
    • 14
  • t

    Timo Drick

    04/16/2021, 9:17 PM
    Hi just wrote my first KSP processor and all works as expected. I create two files based of one source file. I took more or less the code from the ksp_sample playground. But when i compile it without clean before i get often this error:
    e: 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.kt
    t
    • 2
    • 3
  • e

    elihart

    04/17/2021, 6:48 PM
    Heads up @yigit I started working on support in room compiler processing for an abstraction for KSP’s new
    Resolver.getDeclarationsFromPackage()
    and javac’s
    Elements.getPackageElement
    Doesn’t seem like it should be too hard. I created a ticket https://issuetracker.google.com/issues/185609823
    🙏 2
    🙏🏼 1
    • 1
    • 2
  • y

    yigit

    04/19/2021, 3:28 PM
    XProcessing top level constructs thread. cc: @gabrielfv @elihart
    e
    g
    t
    • 4
    • 100
  • r

    russhwolf

    04/20/2021, 8:25 PM
    Checking in on KSP and multiplatform. I'm aware that the compiler plugin itself is JVM-only at least until 1.5.20 due to lack of AnalysisHandlerExtension support on other platforms. I've also seen some stuff around making sure the KSP plugin works for JVM targets of multiplatform projects, but I don't know how well-supported that's expected to be. I can't get any multiplatform project to build that applies the KSP plugin and includes an Android target. I also am having trouble with projects including native targets if I actually wire up a ksp dependency on the JVM target. Are these issues known/expected since multiplatform support isn't ready yet?
    t
    • 2
    • 1
  • t

    Ting-Yuan Huang

    04/22/2021, 2:07 AM
    Hi there, we have made another bi-weekly release that 1. Introduced
    SymbolProcessorProvider
    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!
    ❤️ 3
    🎉 9
    z
    e
    t
    • 4
    • 6
  • z

    Zac Sweers

    04/28/2021, 12:07 AM
    In trying to update to alpha08, I'm seeing a crash in KSP and not sure if it's an issue in my tests or something I should file. Let me know if this seems familiar - https://github.com/ZacSweers/MoshiX/pull/107
    👀 1
    t
    j
    • 3
    • 37
  • z

    Zac Sweers

    04/30/2021, 4:02 AM
    Is
    1.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 out
    t
    • 2
    • 9
  • n

    natario1

    05/03/2021, 3:20 PM
    KSP quickstart says that we should implement SymbolProcessorProvider to provide our processor, but all examples I found until now don't do this. Why is it so? For example: https://github.com/google/ksp/tree/8a8d16855c23f3cc24d05218b16f6c6e46fdbbd8/integr[…]/src/test/resources/on-error/on-error-processor/src/main/kotlin This project has two processors, but not processor provider.
    w
    • 2
    • 2
  • n

    natario1

    05/03/2021, 4:06 PM
    Is it possible to use KSP on non-JVM source sets in a multiplatform project, even if compilation will fail? Say you have a non-JVM target and you are interested in analyzing the source code, without code generation. For example, count how many functions have the
    @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...)
    r
    • 2
    • 7
  • t

    Ting-Yuan Huang

    05/05/2021, 11:55 PM
    Hi there, hope you are enjoying Kotlin 1.5.0 already 🙂 Here is the corresponding KSP 1.5.0-1.0.0-alpha09. Nothing major has changed besides keeping up to Kotlin 1.5; More features / fixes will be in the release next week.
    👍🏼 1
    👍 4
    y
    • 2
    • 1
  • y

    yigit

    05/06/2021, 2:03 AM
    I was trying to add typealias support to Room XProcessing and hit an interesting case. Should there be a similar
    getClassDeclarationByName
    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 alias
    f
    t
    • 3
    • 3
  • j

    Jiaxiang

    05/08/2021, 12:26 AM
    Hi, we are working on changing most of our API return type from
    Collection
    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
    )
    👍 5
    e
    e
    • 3
    • 8
  • n

    natario1

    05/10/2021, 1:24 PM
    Once 421 is merged, my understanding is that KSP could do a step forward towards KMP projects by starting to support multiple jvm targets in the same project, as in:
    kotlin {
        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.
    t
    • 2
    • 1
  • e

    evant

    05/10/2021, 6:48 PM
    brought this up a while ago but didn't seen any movement on it so decided to create a pr, let me know your thoughts! https://github.com/google/ksp/pull/422
    👍 2
    t
    e
    • 3
    • 2
  • j

    Jiaxiang

    05/12/2021, 11:59 PM
    Hi, here is the latest KSP release. Please note that we are pretty close to beta stage. In beta stage we want to avoid making API changes, if you have any changes you want to see in terms APIs, now is still a good time. This release is a pretty long one, please refer to the release note on Github for full list of changes in this release. Major breaking changes: • switch to 
    Sequence
     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
    .
    🎉 2
    👍 5
    👍🏼 1
    y
    t
    • 3
    • 22
  • t

    Ting-Yuan Huang

    05/14/2021, 5:39 PM
    Hi, we've moved the default branch of KSP from
    master
    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
    .
    👍🏼 1
    🤦 1
    👍 8
    🤦🏼 1
    • 1
    • 1
  • e

    efemoney

    05/18/2021, 1:07 PM
    Just how bad is resolution (
    KSTypeReference.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
      }
    }
    j
    • 2
    • 2
Powered by Linen
Title
e

efemoney

05/18/2021, 1:07 PM
Just how bad is resolution (
KSTypeReference.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
  }
}
j

Jiaxiang

05/18/2021, 6:43 PM
When you want to get the type you have to resolve, the comment on the performance is to give you an insight to not rely on resolution excessively, but not to advice against resolution.
👍🏼 1
e

efemoney

05/18/2021, 8:10 PM
Thanks @Jiaxiang. Thats insightful
View count: 6