INRIA / spoon

Spoon is a metaprogramming library to analyze and transform Java source code. :spoon: is made with :heart:, :beers: and :sparkles:. It parses source files to build a well-designed AST with powerful analysis and transformation API.
http://spoon.gforge.inria.fr/
Other
1.74k stars 346 forks source link

Spoon and Nullable #5320

Open MartinWitt opened 1 year ago

MartinWitt commented 1 year ago

Currently, spoon has non @Nullable annotation and we only document nullablility in the Javadoc. Why don't we adopt https://jspecify.dev/docs/start-here and migrate over the time to an annotated library? An alternative is @Contract from JB, but these are only supported in IJ and are way harder to write.

tenax66 commented 1 year ago

I am interested in this proposal. If we adopt jspecify, should we start working with version 0.3 instead of waiting for version 1.0?

MartinWitt commented 1 year ago

We start with 0.3 and can update it later. The goal is to start annotating spoon and waiting for the 1.0 release can take years. A good starting point are methods with null documented in their javadoc for return values.

MartinWitt commented 1 year ago

A noteworthy alternative is using https://www.jetbrains.com/help/idea/annotating-source-code.html. These annotations are at least stable and do the same. But there could be some future where everyone uses jspecify. And the qodana rule for this is: NullableProblems.

tenax66 commented 1 year ago

A good starting point are methods with null documented in their javadoc for return values.

I will see what I can do about this.

tenax66 commented 1 year ago

I looked for the word "null" in @return tags in Javadoc of the spoon-core code. Here are the counts for each package. We may be able to start from these.

package count
spoon 1
spoon.compiler 1
spoon.metamodel 3
spoon.pattern.internal 2
spoon.pattern.internal.matcher 3
spoon.pattern.internal.node 1
spoon.pattern.internal.parameter 2
spoon.reflect.code 3
spoon.reflect.declaration 12
spoon.reflect.factory 7
spoon.reflect.path 1
spoon.reflect.reference 8
spoon.reflect.visitor 5
spoon.support.compiler 1
spoon.support.compiler.jdt 4
spoon.support.modelobs 1
spoon.support.reflect.eval 1
spoon.support.reflect.reference 1
spoon.support.sniper.internal 3
spoon.support.util 2
spoon.support.util.internal 1
spoon.support.visitor 3
spoon.support.visitor.java 2
MartinWitt commented 1 year ago

Yes, this is a good starting point. 👍

tenax66 commented 1 year ago

Create a task list to add @Nullable annotations to the classes under each package.

tenax66 commented 11 months ago

As I mentioned in #5424 , JavaReflectionTreeBuilderTest fails when @Nullable is applied to classes under some specific packages. (like spoon.reflect.code, spoon.reflect.declaration).

Can we remove @Nullable and @NonNull from the target of the test? Since these are TYPE_USE annotations, so JavaReflectionTreeBuilder does not build them.