无法从 Javadoc 元素获取完全限定的类型名称
Unable to Get Fully-Qualified Type Name from Javadoc Element
简短而贴心:尽管我要求 Javadoc API 给我注释的完全限定名称,但它只是 return 简单的类型名称。
我正在编写一个严重依赖注释检查的 Javadoc doclet。因此,我创建了一个实用程序函数,该函数将采用 AnnotationDesc
对象数组和 return 一个 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
方法的 return 值公开的另一种方法。
在我的集成测试中,这一切都很好。但是,当我将我的 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
不会。
谁能帮我理解为什么会这样,更重要的是,我如何才能实现 expected/desired 行为?
问题是注释不在 "documentation time" 的 doclet 的类路径中。为了解决这个问题,我使用以下行扩充了我的 Gradle Javadoc 任务:options.classpath = sourceSets.main.runtimeClasspath.asType(List)
.
简短而贴心:尽管我要求 Javadoc API 给我注释的完全限定名称,但它只是 return 简单的类型名称。
我正在编写一个严重依赖注释检查的 Javadoc doclet。因此,我创建了一个实用程序函数,该函数将采用 AnnotationDesc
对象数组和 return 一个 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
方法的 return 值公开的另一种方法。
在我的集成测试中,这一切都很好。但是,当我将我的 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
不会。
谁能帮我理解为什么会这样,更重要的是,我如何才能实现 expected/desired 行为?
问题是注释不在 "documentation time" 的 doclet 的类路径中。为了解决这个问题,我使用以下行扩充了我的 Gradle Javadoc 任务:options.classpath = sourceSets.main.runtimeClasspath.asType(List)
.