Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

problems to handle some 5.0 language features -- enums and annotations -- in a custom doclet

jrcampins-JavaNetJan 17 2014 — edited Jan 19 2014

I am writing a brand new custom doclet using JDK 1.7. These are the problems I have found so far:

Doc methods isAnnotationType(), isAnnotationTypeElement(), isEnum() and isEnumConstant() do not work. They always return false.

PackageDoc method enums() always returns an empty array. Enums are included in the result of methods allClasses() and ordinaryClasses().

ClassDoc method enumConstants() always returns an empty array. Enum constants are included in the result of method fields().

PackageDoc method annotationTypes() always returns an empty array. Annotations are included in the result of method interfaces(), so I could implement the following work-around:

    AnnotationTypeDoc annotationDoc;

    ClassDoc[] interfaces = packageDoc.interfaces();

    for (ClassDoc classDoc : interfaces) {

    if (classDoc instanceof AnnotationTypeDoc) {

        annotationDoc = (AnnotationTypeDoc) classDoc;

    } else {

        continue;

    }

    process(annotationDoc);

    }

Based on something that I found in the "What's New in Javadoc 5.0" page (http://docs.oracle.com/javase/7/docs/technotes/guides/javadoc/whatsnew-1.5.0.html) I am guessing that, even though I am writing it with JDK 1.7, my doclet is working in some kind of pre-5.0 compatibility mode. This is what I found in the "What's New in Javadoc 5.0" page:

Incompatibilities with Custom Doclets

Custom doclets written prior to 5.0 will have compatibility problems when run on source files that use new language features in 5.0. New Language Features: The Doclet API and standard doclet were revised to handle the new 5.0 language features -- generics, enums, varargs and annotations. To handle these features, custom doclets would also need to be revised. The Javadoc tool tries -- to the extent possible -- to present so-called "legacy" doclets with a view of the program that 1) continues to work with pre-5.0 source code, and 2) matches their expectations for 5.0 source code. So, for example, type parameters and type arguments are stripped from generic constructs, type variables and wildcard types are replaced by their erasures, and ClassDoc.fields() will return enum constants.

This post has been answered by jrcampins-JavaNet on Jan 19 2014
Jump to Answer

Comments

Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Feb 16 2014
Added on Jan 17 2014
1 comment
1,310 views