[Java] Emit @Nullable
for context methods
#4235
Marcono1234
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello,
is it possible to have ANTLR emit
@Nullable
annotations for context methods (methods ofRuleContext
implementations generated for the parser) which can returnnull
because the corresponding parts of the rule are optional?For example, for the following grammar:
ANTLR generates this Java code:
Here
RootContext.second()
can returnnull
. It would therefore be useful if that method had a@Nullable
annotation.However, such generation of
@Nullable
should probably be opt-in, because depending on what error listener you have configured, you might also encounternull
for any other methods if the input does not match the grammar, see also #4040, so@Nullable
would give a false sense of security implying that other methods cannot returnnull
.Such a
@Nullable
annotation might not have to come from a specific framework; many tools recognize such annotations just from its nameNullable
, ignoring the package name.Related:
Beta Was this translation helpful? Give feedback.
All reactions