Short and sweet: despite the fact that I am asking the Javadoc API to give me the fully-qualified name of an annotation, it is only returning the simple type name.
I am writing a Javadoc doclet that relies heavily on the inspection of annotations. As such, I have created a utility function that will take an array of AnnotationDesc
objects and return a Map
that associates the fully-qualified name of the annotation to the AnnotationDesc
object that describes it. Here are the relevant functions:
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(); }
For what it's worth, I have also tried using qualifiedName
, which is another method exposed by the return value of the AnnotationDesc.annotationType
method.
In my integration tests, this is all working great. However, when I push my doclet out to Artifactory, pull it down into another project and try to invoke it by way of a Gradle task, the keys in my map are the simple type names of the annotations.
Here is the definition of my Gradle task:
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>
}
I have noticed that if a program element is annotated with a fully-qualified annotation, then the fully-qualified name is actually picked up by the Javadoc API. Eg: @com.package.Annotation
results in the expected behavior, but @Annotation
does not.
Can someone please help me to understand why this is happening and, more importantly, how I can achieve the expected/desired behavior?
The problem was that the annotations were not on the classpath of the doclet at "documentation time". In order to fix this problem I augmented my Gradle Javadoc task with the following line: options.classpath = sourceSets.main.runtimeClasspath.asType(List)
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.