@Flow annotation - when and how to use?


I was looking at the Jetbrains analysis annotations and fitted my code with @Nullable/NotNull, as well as @Contract annotations (I even caught a latent bug or two), but now I am looking at @Flow and I don't quite get it...

Looking at the Javadoc: http://javadox.com/org.jetbrains/annotations/13.0/org/intellij/lang/annotations/Flow.html


It mentions things like "flow", "source", or "target" without really defining them... What are these, what kind of analysis does this annotation enable?


I can see that there is no production code annotated with it in the IntelliJ repo - only one not very informative test: https://github.com/JetBrains/intellij-community/blob/6bcad287da6100389364570fc6e421ff50d44973/java/java-tests/testData/codeInsight/slice/backward/CollectionTrack.java

And a few external annotations for JDK collections and array-copying methods: https://github.com/JetBrains/intellij-community/search?utf8=%E2%9C%93&q=%22annotations.Flow%22+extension%3Axml+&type=Code


Am I supposed to use @Flow in my own code, under what circumstances?

Alexey Kudravtsev
Comment actions Permalink
Official comment

This annotation is to support "Analyze|Analyze Data From/To Here" feature. Using this annotation we can tell IDEA about data-flow in method which happens between its parameters.  E.g. we can annotate System.arraycopy() to announce it copies information from its "Object src" parameter to its "Object dest" parameter. The annotation is useful primarily to annotate library methods via IDEA external annotations XML files. I don't think you're going to need this annotation unless you have some method in esoteric library attached to your project and you desperately need the "Analyze Data To This" to work with this library method.

Comment actions Permalink

I've asked the responsible developer to handle your questions, but he's on the vacation at the moment. Please wait a couple of weeks. We are sorry for this delay.


Please sign in to leave a comment.