https://kotlinlang.org logo
Title
m

Matthias Geisler

04/29/2022, 6:51 AM
Hello - Small question - when I use
getSymbolsWithAnnotation
with multiple deferring Annotation for a Class target. Is it suppose to pick up only the first?
To make it a bit clearer what I mean:
In this case only
@MockCommon
is the first I extract via
getSymbolsWithAnnotation
and surprisingly it also contains `@Mock`and
@MockShared
:
Is that intentional or shall I file a bug report?
g

Grégory Lureau

04/29/2022, 7:34 AM
getSymbolsWithAnnotation give you all symbols annotated with @MockCommon. Once you have the symbol, you can get everything that belongs to it, like all the annotations of this symbol, it's not related to the resolver method you used initially to get the symbol.
m

Matthias Geisler

04/29/2022, 7:40 AM
But why it takes then a parameter annotationName?
Also the doc state - "Get all symbols with specified annotation."
g

Grégory Lureau

04/29/2022, 7:45 AM
getSymbolsWithAnnotation give you all symbols annotated with @MockCommon
You cannot find your class
Platform
without giving the annotation name of "MockCommon". Let's say you also annotate another class like
Shared
with @MockCommon, then getSymbolsWithAnnotation will return [Platform, Shared].
And Platform will still have 3 annotations, and Shared only one.
m

Matthias Geisler

04/29/2022, 8:06 AM
I think you do not get me here. The Sequence which is returned from
getSymbolsWithAnnotation
when I call it with the name for example of MockCommon will contain in the example above also the Annotated for Mock and MockShared. That would not be that bad, but if call it again for Mock or MockShared, those Annotated are not resolved.
(There for the pictures)
Where the Annotation sits does not matter in this case
g

Grégory Lureau

04/29/2022, 8:07 AM
Ah ok, sorry for the misunderstanding.
m

Matthias Geisler

04/29/2022, 8:07 AM
No problem - but is it clear now?
:yes: 1
e

efemoney

04/29/2022, 8:36 AM
@Matthias Geisler from the screenshot you shared, get symbols with ‘MockCommon’ will return only
Platform
But then you proceed to read all annotations of Platform & print them and obviously Platform is annotated with ALL 3 annotations
Where is the problem here?
This is not “_surprising behavior”._ Infact_,_ I am more surprised you are expecting differently
m

Matthias Geisler

04/29/2022, 8:39 AM
Did you read the entire Thread?
e

efemoney

04/29/2022, 8:41 AM
I did but I wanted to address just the code that you shared firstly. Just so that I understand you better, are you saying that calling get symbols annotated with ‘Mock’ & ‘MockShared’ returns empty?
m

Matthias Geisler

04/29/2022, 8:44 AM
Yes
But common contains the Annotated for them in its sequence
e

efemoney

04/29/2022, 8:50 AM
Are you calling getSymbolsWithAnnotation multiple times in the same round?
m

Matthias Geisler

04/29/2022, 8:51 AM
yes
currently 4times
e

efemoney

04/29/2022, 8:52 AM
Cool 👍🏼 . I think you should file a bug then. with a reproducer. It should just work
m

Matthias Geisler

04/29/2022, 8:56 AM
Sure, but I hoped @Jiaxiang or @Ting-Yuan Huang pick it up - maybe they think it should work the other way...
e

efemoney

04/29/2022, 9:21 AM
I am unable to reproduce this with latest ksp 🤔. Is there something your project does differently from this?:
(note: the subsequent printed headers are from the 2nd round and like KSP mentions in the javadoc for getSymbolsWithAnnotation, only deferred symbols & new files are processed)
m

Matthias Geisler

04/29/2022, 9:39 AM
That is interesting...I am sitting still on 1.6.10 - but there was nothing mentioned in the release notes about changes that specific method.
e

efemoney

04/29/2022, 9:39 AM
Ksp api hasnt changed from then (the 1.0.5 part)
m

Matthias Geisler

04/29/2022, 9:41 AM
Yeah...but you never know...
And the annotations are with:
@Retention(AnnotationRetention.SOURCE)
@Target(AnnotationTarget.CLASS)
But it should not have any effect...since I was able to reproduces when I removed the target
:yes: 1
e

efemoney

04/29/2022, 10:31 AM
I switched to 1.6.10-1.0.4 and got same results
m

Matthias Geisler

04/29/2022, 11:54 AM
Super wired - after poking stuff around then reset it to the starting code (git checkout . is always the best) now I get the same result...
Super wired
And @efemoney thx that you invested time btw
🙌🏼 1
e

efemoney

04/29/2022, 11:56 AM
Awesome, Glad you got it working! Sometimes you just have to “turn it off and on again” 😅
If you are ever able to reproduce it I would suggest opening an issue, At a minimum you’ll understand why it happens. In the best case you’ll have discovered a potential bug in ksp that can be fixed for someone else.
m

Matthias Geisler

04/29/2022, 12:21 PM
Let's hope that never happens again...
j

Jiaxiang

04/29/2022, 8:41 PM
It is quite a long thread.. good to see that it eventually works, sometimes there could also be issues with compiler version, feel free to file a bug if you encountered it again 🙂