简体   繁体   English

@Nullable / @NotNull与IntelliJ IDEA,Maven和JSR 305

[英]@Nullable/@NotNull with IntelliJ IDEA, Maven & JSR 305

I really like the code inspection functionalities which are now able with either JSR 305 or Jetbrains' proprietary annotations for IntelliJ. 我非常喜欢代码检查功能,现在可以使用JSR 305或Jetbrains的IntelliJ专有注释。 Unfortunately both implementations (JSR 305 and Jetbrains') do not mix well: 不幸的是,这两种实现(JSR 305和Jetbrains')混合不好:

  • IntelliJ obviously only understands its own proprietary set of annotations and integrates them quite well. IntelliJ显然只能理解它自己的一套注释并将它们很好地集成在一起。
  • Using Findbugs in my Maven Build, it only supports JSR-305 annotations. 在我的Maven Build中使用Findbugs,它只支持JSR-305注释。

The only possible workaround might be to go for JSR-305 and use the Findbugs plugin in IntelliJ. 唯一可能的解决方法可能是使用JSR-305并使用IntelliJ中的Findbugs插件。 Has anybody a better idea? 谁有更好的主意? (please don't say change your IDE ;) ). (请不要说改变你的IDE;))。

Thanks Thomas 谢谢托马斯

I'm late to the party, but for future readers this might be interesting. 我迟到了,但对于未来的读者来说,这可能很有趣。

As of IntelliJ 15.0.2, you may natively use other annotations than the JetBrains ones: 从IntelliJ 15.0.2开始,您可以使用其他注释而不是JetBrains注释:

  • go to the settings 转到设置
  • go to the Editor > Inspections tab 转到Editor > Inspections选项卡
  • go to Java > Probable Bugs > "@NotNull/@Nullable problems" 转到Java > Probable Bugs > "@NotNull/@Nullable problems"
  • at the end of the options panel (you might need to scroll), there is a Configure annotations button, leading to this dialog where you can select from a list of well-known annotations: 在选项面板的末尾(您可能需要滚动),有一个“ Configure annotations按钮,通向此对话框,您可以从中选择一个众所周知的注释列表:

在此输入图像描述

According to IntelliJ issue IDEA-64677 : 根据IntelliJ问题IDEA-64677

  • support for arbitrary @Nullable/@NotNull annotations should be available in IDEA 10.0.3 在IDEA 10.0.3中应该支持任意@ Nullable / @NotNull注释
  • there will probably some a manual configuration step(s) to enable support for the non-proprietary annotations (see Anna's comments on that page) 可能会有一些手动配置步骤来支持非专有注释(参见Anna对该页面的评论)

As this question is IntelliJ specific it is perhaps best asked on an IntelliJ forum. 由于这个问题是IntelliJ特定的,因此最好在IntelliJ论坛上询问。 You might find this thread interesting http://devnet.jetbrains.net/message/5262800 . 您可能会发现此主题很有趣http://devnet.jetbrains.net/message/5262800 The downside of using Findbugs is that it doesn't provide code injection for runtime checks and JSR-305 doesn't appear likely to be approved anytime soon. 使用Findbugs的缺点是它不为运行时检查提供代码注入,并且JSR-305似乎不会很快被批准。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM