8 Replies Latest reply: Oct 7, 2010 12:54 PM by 799936 RSS

    how to get imports of a class OR how to fix javadoc-@link/@see

    799936
      I'm generating classes based on existing classes. The new code also contains the javadoc-comments. These comments can contain @link- and @see-tags.

      In the original source everything works nicely since all necessary classes are imported. However, inside the generated class I currently don't have those imports available to me (I'd assume that TypeElement would provide a method to get them, but it doesn't). One way would be to run through all comments and replace all class names with the fully qualified name. However, that's one time consuming process and I know that at one point people will forget to always write the fully qualified name.

      The main goal is to have javadoc generate the documentation with all cross-linking working.

      Is there a way to make @link- and @see-tags work?
        • 1. Re: how to get imports of a class OR how to fix javadoc-@link/@see
          799936
          Forgot to say: the problem exists for the element I link to and for the types of parameters in case it's a method.
          • 2. Re: how to get imports of a class OR how to fix javadoc-@link/@see
            aksarben
            By "generating" I assume you mean a code generator is creating the new classes (vice writing them by hand and merely extending the existing classes)?
            • 3. Re: how to get imports of a class OR how to fix javadoc-@link/@see
              799936
              Correct. The processor basically strips out the method bodies and replaces them with proper return statements when applicable.
              • 4. Re: how to get imports of a class OR how to fix javadoc-@link/@see
                796367
                verminator wrote:
                The main goal is to have javadoc generate the documentation with all cross-linking working.

                Is there a way to make @link- and @see-tags work?
                Do you mean the <tt>-link</tt> command when running javadoc?

                For example, if the CORE JAVA CLASSES documentation (API) is in <tt>C:/jdk/docs/api</tt>, then run this command line:
                javadoc -link C:/jdk/docs/api MyClass.java
                • 5. Re: how to get imports of a class OR how to fix javadoc-@link/@see
                  799936
                  No, as I said in the thread title and OP, this is about javadoc. It has @link and @see among other tags.

                  To learn more about those tags, please go here.
                  • 6. Re: how to get imports of a class OR how to fix javadoc-@link/@see
                    Darryl Burke
                    I don't think what you're looking for is possible, and I don't think it can be possible. Imports disambiguate classes.

                    Without imports, how can any system possibly differentiate between java.util.List and java.awt.List? or the three Timers in the JDK? or indeed any of your own classes that might share the same name.

                    db
                    • 7. Re: how to get imports of a class OR how to fix javadoc-@link/@see
                      799936
                      Darryl Burke wrote:
                      I don't think what you're looking for is possible, and I don't think it can be possible. Imports disambiguate classes.

                      Without imports, how can any system possibly differentiate between java.util.List and java.awt.List? or the three Timers in the JDK? or indeed any of your own classes that might share the same name.

                      db
                      That's why I'm looking for a way to get those imports. If I access any type in the annotation processor I always get the fully qualified name. Since in a way I am the annotation processor, I'd assume that I have access to how the compiler figured out which List the original source refers to.

                      I mean if the code is
                      java.util.List<String> myList;
                      it's easy. However, I usually code
                      import java.util.List;
                      :
                      List<String> myList;
                      and the compiler does the match. If the processor accesses the type of myList, it sees java.util.List in both variations. Obviously the compiler did some magic there. In my naive thinking I'd assume that I get access to the magic. The import declaration at the top of the source would be the "magic" to me.

                      The tragedy starts if the original code looks like this:
                      import java.util.List;
                      :
                      List<String> myList;
                      java.awt.List myGorgeousList;
                      :
                      /** blah blah {@link List} blah
                      */
                      This is the reason why I can't collect all kinds of types I run into while parsing the original source and simply pick the first matching one. I'd end up with both java.util.List and java.awt.List. Now how would I know which List the comment is referring to? I can only do this if I have access to imports. Then I'd see that there's a List declared as java.util.List. Since the List in the comment isn't fully qualified, java.util.List would be my choice.

                      But I don't have this! I already checked the API of Java SE 6, whether there is some getter-method with "import" in its name, but I couldn't find anything. :(

                      If I code something in an ambiguous fashion, the compiler complains and I can fix this. However, with my current knowledge I can't think of a way to solve the ambiguity inside my processor.

                      Which is why I started this thread :)
                      • 8. Re: how to get imports of a class OR how to fix javadoc-@link/@see
                        799936
                        Doesn't anyone have even the tiniest little bit of hint for me? Please?