简体   繁体   English

Intellij 在标准 Java 类上显示非标准注释?

[英]Intellij showing nonstandard annotations on standard Java classes?

Whilst using Intellij Idea quick documentation feature ( CTRL + Q ) sometimes I find standard JDK classes to be annotated by nonstandard annotations.在使用 Intellij Idea 快速文档功能( CTRL + Q )时,有时我会发现标准 JDK 类被非标准注释所注释。 Those annotations are not there when one CTRL -clicks the annotated feature to view its source code.当一个CTRL键单击带注释的功能以查看其源代码时,这些注释不存在。 For example, the following picture shows argument of java.util.Collections.unmodifiableList to be annotated with @org.jetbrains.annotations.NotNull :例如,下图显示了要使用@org.jetbrains.annotations.NotNull注释的java.util.Collections.unmodifiableList参数:

用于 java.util.Collections.unmodifiableList 的 QuickDoc

Why would a standard class be decorated with third party annotation?为什么标准类会被第三方注解修饰?

This is not consistent, as for example, checkedNavigableSet from java.util.collections is annotated differently, no package for @NotNull is given:这是不一致的,例如java.util.collections checkedNavigableSet注释不同,没有给出@NotNull包:

CheckedNavigableSet 的 QuickDoc

The phenomenon does not preclude development, I am just curious as to the cause of QuickDoc behaving that way.这种现象并不妨碍发展,我只是好奇 QuickDoc 出现这种行为的原因。 Maybe those annotations put there by Intellij team for convenience?也许 Intellij 团队为了方便起见放在那里的那些注释?

According to doc from here that annotations are used by Idea's inspection mechanism, so statement Collections.unmodifiableList(null) is marked with warning of non-null contract violation.根据此处的文档,Idea 的检查机制使用了注释,因此语句Collections.unmodifiableList(null)标有非空合同违规警告。 As you noticed this annotations are not being present in original code, so I guess they were added somewhere in a middle between JDK and Editor.正如您所注意到的,原始代码中不存在此注释,因此我猜它们是添加到 JDK 和编辑器之间的某个位置的。 It's still unclear why it appears with package or without it.目前尚不清楚为什么它会出现在包装中或不带包装中。

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

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