https://kotlinlang.org logo
Title
j

Joeywp

05/04/2018, 7:22 PM
Does anyone know how to configure IntelliJ Idea with Kotlin external annotations? If I use an external @Deprecated annotation the IDE picks it up correctly, but when I annotate it with @Nullable (from org.jetbrains.annotations.Nullable) the IDE just ignores it's nullability? Edit: It's for an external library, that's why I have to use the external annotations
s

Shawn

05/04/2018, 7:25 PM
is this external library written in Kotlin or written in Java?
j

Joeywp

05/04/2018, 7:26 PM
It's written in Java (it's actually the Minecraft Spigot server) Example annotations:
<root>
    <item name='org.bukkit.inventory.PlayerInventory org.bukkit.inventory.ItemStack getItemInMainHand()'>
        <annotation name='org.jetbrains.annotations.Nullable'/>
        <annotation name='java.lang.Deprecated'/>
    </item>
</root>

https://i.gyazo.com/a4c7b37b69acc8b238ac1c3f420fbcc2.png

As this image shows, the Deprecated one is picked up by the IDE, but the Nullable isn't for some reason In the editor however, both do actually show up:

https://i.gyazo.com/393e04abc624a58ad6a0479d7b40d590.png

s

Shawn

05/04/2018, 7:31 PM
the call route looks a little different here - it may be that using
.
directly on the result of
itemInMainHand
might be accidentally casting the object from
ItemStack!
to
ItemStack
rather than
ItemStack?
the result of
.clone()
on a non-null, cloneable object should result in a non-null reference being returned
j

Joeywp

05/04/2018, 7:34 PM
Oh I picked a bit of a wrong example, it also does this on none
.clone()
methods, for example:

https://i.gyazo.com/fb8bc996f8c05da25b256ed210249ba6.png

Also, the
.inventory
refers to an interface that only has methods, CTRL+Clicking the method confirms it refers to the externally annotated method
If it where to refer to the wrong element, I assume the
@Deprecated
also shouldn't work, right?
s

Shawn

05/04/2018, 7:35 PM
hmm that’s a good question
I’m not sure if appending
@Nullable
via external annotations overrides Kotlin’s concept of platform types here
may or may not be worth filing a :youtrack: ?
j

Joeywp

05/04/2018, 7:37 PM
Yeah I indeed assumed the same, guess I'll indeed just try a :youtrack: issue
s

Shawn

05/04/2018, 7:40 PM
is there any chance that method is actually marked as deprecated by the library authors?
I don’t have the source or reference in front of me to check 😅
j

Joeywp

05/04/2018, 7:40 PM
Nope, if I remove the
@Deprecated
from the external annotations it dissapears again
Just used the
@Deprecated
to test if I configured it wrongly or if it did ignore my
@Nullable
s

Shawn

05/04/2018, 7:42 PM
I see
j

Joeywp

05/04/2018, 7:54 PM