【问题标题】:Unable to Get Fully-Qualified Type Name from Javadoc Element无法从 Javadoc 元素获取完全限定的类型名称
【发布时间】:2017-06-20 01:21:41
【问题描述】:

简短而甜蜜:尽管我要求 Javadoc API 为我提供注解的完全限定名称,但它只返回简单类型名称。

我正在编写一个严重依赖于注解检查的 Javadoc doclet。因此,我创建了一个实用函数,它将采用 AnnotationDesc 对象数组并返回一个 Map ,它将注释的完全限定名称与描述它的 AnnotationDesc 对象相关联。以下是相关功能:

public static final Map<String, AnnotationDesc> getAnnotationMap(AnnotationDesc[] notes)
{
    if (notes == null)
    {
        return Collections.emptyMap();
    }

    return Collections.unmodifiableMap(Arrays.stream(notes).collect(Collectors.toMap(AnnotationUtils::getNoteName, note -> note)));
}

private static String getNoteName(AnnotationDesc note) { return note.annotationType().qualifiedTypeName(); }

对于它的价值,我也尝试过使用qualifiedName,这是AnnotationDesc.annotationType方法的返回值暴露的另一种方法。

在我的集成测试中,这一切都很好。但是,当我将 doclet 推送到 Artifactory 时,将其拉入另一个项目并尝试通过 Gradle 任务调用它,我的映射中的键是注释的简单类型名称。

这是我的 Gradle 任务的定义:

task myDocletTask(type: Javadoc) {
    source = sourceSets.main.allJava
    destinationDir = reporting.file("my-doclet-dir")
    options.docletpath = configurations.jaxDoclet.files.asType(List)
    options.doclet = <redacted - fully qualified type name of custom doclet>
}

我注意到,如果一个程序元素被一个完全限定的注解所注解,那么这个完全限定的名称实际上会被 Javadoc API 拾取。例如:@com.package.Annotation 会产生预期的行为,但 @Annotation 不会。

有人可以帮我理解为什么会发生这种情况,更重要的是,我可以如何实现预期/期望的行为?

【问题讨论】:

  • -AnnotationUtils 类从何而来?- 啊,我看到它是包含类,getNoteName 方法在下面。

标签: java gradle annotations javadoc


【解决方案1】:

问题是注释在“文档化时间”时不在 doclet 的类路径上。为了解决这个问题,我使用以下行扩充了我的 Gradle Javadoc 任务:options.classpath = sourceSets.main.runtimeClasspath.asType(List)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-03-25
    • 1970-01-01
    • 2014-06-04
    • 2016-09-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多