KAnnotator 0.1 is out
We announced KAnnotator back in December: it helps you against NPEs in Java and makes your Kotlin code nicer. Today we are pleased to announce a KAnnotator Plugin for IntelliJ, version 0.1. It is available from the plugin repository.
Why Infer Annotations
An excerpt from an earlier blog post, explaining what KAnnotator is:
Since Kotlin M3, you can use external annotations to tell the system that your methods return/take non-null values. This mechanism is useful even if you don’t use Kotlin: you can turn on nullability inspections for Java too (and I totally recommend you to do so).
One problem about this used to be that, while you can annotate your own code while you write it (and we do it all the time at JetBrains), your favorite library is not annotated, and it is so big, you can’t annotate it manually.
The key thing here is that ‘manually’. A programmer is a lazy creature, and by virtue of our laziness, we want to automate as much as we can. KAnnotator is a tool that annotates your libraries automatically (the tool is written in Kotlin, of course).
How it works, in a nutshell: you have your library as a jar (or a number of jars), you tell KAnnotator to infer annotations for these jars, and get a bunch of .xml files back. They contain annotations for methods and fields, for example:
Now, you can attach these annotations to your project, and both Java IDE and Kotlin compiler will see them.
We used KAnnotator to infer annotations for JDK that ship with Kotlin. Now you can use it as well: to annotate your own libraries.
KAnnotator ships as a separate plugin for IntelliJ IDEA 12 or higher (both 12.0.4 and 12.1 will work). Note that the Kotlin plugin is not required. To install the plugin, follow the instructions from here.
No you can call Analyze -> Annotate Jar Files… (from either Main menu or context menu)
You get a dialog like this:
There you specify what JAR files you want analyzed and where to put the results, i.e. XML files containing annotations. By default, KAnnotator will attach the annotation to the libraries you call it on.
So, when you see Kotlin complaining about nullable types coming from Java, all you need to do is run KAnnotator once on that Java library, and it will turn your red code green.
If it does not, maybe KAnnotator is not smart enough, but maybe that method actually returns null?
Subscribe to Blog updates
Thanks, we've got you!
Gradle Kotlin DSL 1.0
This is a guest blog post from Paul Merlin software engineer for Gradle The recently released Gradle 5.0 includes the Gradle Kotlin DSL v1.0 which is now ready for widespread use. We want you to enjoy a build authoring experience with the benefits provided by Kotlin’s static type system in Inte…
Kotlin 1.3 Released with Coroutines, Kotlin/Native Beta, and more
You can read this blog post in other languages: Today we are releasing Kotlin 1.3 together with a set of accompanying libraries, build tools, and learning materials! We develop Kotlin to be a good tool for all application developers, at all scales and on all platforms. In Kotlin…
KotlinConf 2018 Announcements
In today's keynote at KotlinConf 2018 we made a series of announcements around releases, resources, and other things we've made available. For your convenience below is a brief summary of the announcements with the corresponding links for more information. Kotlin 1.3 hits RC Version 1.3 hits RC…