- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在开发一个基于多模块 Maven 的项目,其中一个模块包含一些注释处理器,用于其他模块使用的自定义注释。当我将注释处理器模块的依赖项添加到任何其他模块时,该模块的注释将由这些注释处理器处理。
但最近我整合了Checker Framework (用于类型注释)然后所有自定义注释处理器(我上面提到的)停止工作。非常感谢关于如何让它们甚至使用 Checker Framework 工作的想法?
清除场景,
假设我有一个名为 module_A 的 Maven 模块。在这个模块中,我有一个名为“@FoodItem”的注释(类级别)。我需要强制执行一条规则,任何用“@FoodItem”注释注释的类都应该实现接口(interface)“Food”。因此,我在同一个模块 (module_A) 中编写了一个注解处理器“FoodItemAnnotationProcessor”,它处理这些类并检查是否符合该规则。
然后假设我有另一个名为 module_B 的模块,它对 module_A 具有 Maven 依赖性。在这个模块中,我有一个名为“Pizza”的类,它用“@FoodItem”注释进行注释。
如果使用上述配置构建项目(包含 module_A 和 module_B),“FoodItemAnnotationProcessor”将在编译阶段执行,并根据上述规则验证类“Pizza”。
之后,我将 Checker 框架集成到 module_B(如前所述 here )。然后在编译时按预期执行与检查器框架相关的验证,但“FoodItemAnnotationProcessor”停止工作。
最佳答案
要理解这个问题,您必须知道如何javac找到您的注解处理器。
如果您没有为 javac 提供 --processor
参数(请参阅 doc-javac-options ),则会激活注释处理器自动发现功能(请参阅 javac-doc: Annotation processing )。这意味着,javac 将在您的 classpath
(或 processorpath
,如果您已指定)中搜索所有可用的注释处理器。
包含 META-INF/services/javax.annotation.processing.Processor
文件的 Jar 可以指定它们的注解处理器类,javac 将自动使用它们。
“问题”是检查器框架有多个用于检查的注释处理器,但您可能只想使用其中的一些:因此无法使用注释发现过程,您必须手动指定所有注释处理器在您的构建文件中运行。
对于 Maven 构建,您可以这样做:checker-framework doc for Maven
<annotationProcessors>
<!-- Add all the checkers you want to enable here -->
<annotationProcessor>org.checkerframework.checker.nullness.NullnessChecker</annotationProcessor>
</annotationProcessors>
这将为 javac 显式设置 --processor
参数(参见 doc-javac-options ),这会禁用默认的注释发现过程。
所以解决方案是手动添加所有要运行的注释处理器(除了检查器框架检查器)。
例如当你想运行 NullnessChecker和 Dagger ,您必须同时指定:
<annotationProcessors>
<!-- Add all the checkers you want to enable here -->
<annotationProcessor>org.checkerframework.checker.nullness.NullnessChecker</annotationProcessor>
<!-- Add all your other annotation processors here -->
<annotationProcessor>dagger.internal.codegen.ComponentProcessor</annotationProcessor>
</annotationProcessors>
提示:
要找出您当前使用的注释处理器,请运行您的构建并将非标准选项 -XprintProcessorInfo
传递给 javac。
更新:
检查器还支持某种自动发现 ( doc-ref ) - 注意:我还没有使用过。
2.2.3 Checker auto-discovery
“Auto-discovery” makes the javac compiler always run a checker plugin, even if you do not explicitly pass the -processor command-line option. This can make your command line shorter, and ensures that your code is checked even if you forget the command-line option.
To enable auto-discovery, place a configuration file named META-INF/services/javax.annotation.processing.Processor in your classpath. The file contains the names of the checker plugins to be used, listed one per line. For instance, to run the Nullness Checker and the Interning Checker automatically, the configuration file should contain:
org.checkerframework.checker.nullness.NullnessChecker
org.checkerframework.checker.interning.InterningChecker
关于java - 将自定义注释处理器与 Checker Framework 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38347443/
我正在尝试Checker Framework使用 Java 8 的 Nullness 检查器。当我在以下代码上运行检查器时: import java.util.HashMap; import java
从 IntellijIDEA 运行 Spring 应用程序时出现以下错误。 2017-04-20 18:20:50.645 ERROR 28680 --- [main] o.s.b.d.Logging
我正在使用为我的 HTML 文件启用的 Syntastic。由于我有一个非常大的文件,并且启用了“validator w3”检查器,因此在保存文件时 GVIM 或 VIM 变得非常慢 (:w)。 是否
正如您在标题中看到的,我正在尝试编写一个程序,该程序可以为我解决“晚间标准管测验”。它的一部分。它必须能够在地铁站名称中找到字谜。我在网上找到了很多代码来检查两个单词是否是字谜。但我需要一些不同的东西
以下是如何使用 C++ Core Checker 的说明:C++ Core Guidelines Checkers available for VS 2015 Update 1. 我成功安装了 NuG
我有一张 table : CREATE TABLE MENUPOINT ( id BIGINT NOT NULL, parent BIGINT, name VARCHAR(64), C
我以前用过它,当有人问及从样式表中删除未使用的 CSS 的工具时,我想起了它。 我回到链接,但是它不见了,这是怎么回事?它永远消失了还是有人知道备份?或者仍然可以根据 HTML 检查您的 CSS 并去
我在我的 React 应用程序的控制台中收到这条奇怪的警告消息。 Warning: Failed propType: checker is not a function Check the rende
如标题所述,我使用 bundle 搜索插件查找依赖项漏洞,但在我的项目中找不到任何漏洞。 我用的是IntelliJ IDEA 2022.1.3(旗舰版),我检查了一下,比如把spring-boot-s
为什么在下面的代码中,使用数组切片有效,但使用 Vec 的切片却无效? use rand::{rngs::adapter::ReadRng, RngCore}; use std::io::Read;
看起来 checkZip 函数是在用户的 zip 绑定(bind)到参数之前触发的。有没有更好的方法使用 Angular 工具来完成此任务?我想在用户输入正确的邮政编码后立即启动用户流程的下一步。 H
我指的是nullness-example in the docs (检查框架版本:2.1.14) 当我按照建议运行示例来检查NullnessExampleWithWarnings.java时: jav
我安装了 Eclipse 4.6.2 和插件“Checker Framework Feature”2.1.7。 首次使用该插件时(例如,当我右键单击并将鼠标悬停在上下文菜单项“Checker Fram
我正在尝试检查两个单词是否是变位词,并尝试使用 LinkedList 来做到这一点。为此,首先,我创建了一个名为 LinkedList 的类: class LinkedList { priv
我已经将 Checker Framework v2.1.6 引入到一个 java8 项目中,并修复了所有的 nullness 错误,但我仍然遇到以下错误 Main.java:52: error: [a
abi-compliance-checker 是一个 perl 程序,可以检查 linux 上库的 ABI ( https://lvc.github.io/abi-compliance-checker
我目前正在使用 Alexander Potochkin 的 AspectJ EDTChecker code (帖子底部的相关代码)。 此代码(基于我对 AspectJ 的一点了解)提示在 Swing
我正在开发一个基于多模块 Maven 的项目,其中一个模块包含一些注释处理器,用于其他模块使用的自定义注释。当我将注释处理器模块的依赖项添加到任何其他模块时,该模块的注释将由这些注释处理器处理。 但最
我想使用我自定义的列表来实现列表的常规应用实例: import Control.Monad import Test.QuickCheck import Test.QuickCheck.Checkers
考虑这个 github 存储库。 https://github.com/dfabulich/bazel-checker-framework-bug 它包括一个样本 X.java公然违反 @Nonnul
我是一名优秀的程序员,十分优秀!