/[classpath]/gjdoc/src/gnu/classpath/tools/doclets/xmldoclet/Driver.java
ViewVC logotype

Diff of /gjdoc/src/gnu/classpath/tools/doclets/xmldoclet/Driver.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.41 by julian, Thu Nov 25 16:26:32 2004 UTC revision 1.42 by julian, Fri Nov 26 13:29:56 2004 UTC
# Line 38  import java.util.HashSet; Line 38  import java.util.HashSet;
38  import java.util.TreeSet;  import java.util.TreeSet;
39  import java.util.Iterator;  import java.util.Iterator;
40  import java.util.LinkedHashMap;  import java.util.LinkedHashMap;
41    import java.util.LinkedList;
42  import java.util.List;  import java.util.List;
43  import java.util.Locale;  import java.util.Locale;
44  import java.util.Map;  import java.util.Map;
45  import java.util.HashMap;  import java.util.HashMap;
46  import java.util.Properties;  import java.util.Properties;
47  import java.util.Set;  import java.util.Set;
48    import java.util.SortedSet;
49  import java.util.StringTokenizer;  import java.util.StringTokenizer;
50  import java.util.TreeMap;  import java.util.TreeMap;
51    
# Line 212  public class Driver { Line 214  public class Driver {
214     private String tagletPath = null;     private String tagletPath = null;
215    
216     /**     /**
217      * The current class that is being processed.      *  The current class that is being processed.
218      * Set in outputClassDoc().      *  Set in outputClassDoc().
219      */      */
220     private ClassDoc currentClass;     private ClassDoc currentClass;
221    
222     /**     /**
223      * The current member that is being processed.      *  The current member that is being processed.
224      * Set in outputMemberDoc().      *  Set in outputMemberDoc().
225      */      */
226     private MemberDoc currentMember;     private MemberDoc currentMember;
227    
228     /**     /**
229      * The current constructor/method that is being processed.      *  The current constructor/method that is being processed.
230      * Set in outputExecutableMemberDoc().      *  Set in outputExecutableMemberDoc().
231      */      */
232     private ExecutableMemberDoc currentExecMember;     private ExecutableMemberDoc currentExecMember;
233    
234     /**     /**
235      * Mapping from tag type to Taglet.      *  Mapping from tag type to Taglet for user Taglets specified on
236        *  the command line.
237      */      */
238     private Map tagletMap = new LinkedHashMap();     private Map tagletMap = new LinkedHashMap();
239    
240     /**     /**
241      * Stores options to be passed to the DocTranslet.      *  Keeps track of the tags mentioned by the user during option
242        *  processiong so that an error can be emitted if a tag is
243        *  mentioned more than once.
244        */
245       private List mentionedTags = new LinkedList();
246    
247       /**
248        *  Stores options to be passed to the DocTranslet.
249      */      */
250     private DocTransletOptions docTransletOptions = new DocTransletOptions();       private DocTransletOptions docTransletOptions = new DocTransletOptions();  
251    
252       /**
253        *  Stores the package groups specified in the user
254        *  options. Contains objects of type PackageGroup.
255        */
256       private List packageGroups = new LinkedList();
257    
258       private HtmlRepairer htmlRepairer;
259    
260     public static boolean start(TemporaryStore _rootDocWrapper) {     public static boolean start(TemporaryStore _rootDocWrapper) {
261        return new Driver().instanceStart((RootDoc)_rootDocWrapper.getAndClear());        return new Driver().instanceStart((RootDoc)_rootDocWrapper.getAndClear());
262     }     }
# Line 557  public class Driver { Line 575  public class Driver {
575    
576        if (doc.tags().length > 0) {        if (doc.tags().length > 0) {
577           printOpenTag(level, "tags");           printOpenTag(level, "tags");
578           outputTags(level+1, doc.tags(), true, context);           outputTaglets(level+1, doc.tags(), true, context);
579           printCloseTag(level, "tags");           printCloseTag(level, "tags");
580        }        }
581    
# Line 599  public class Driver { Line 617  public class Driver {
617    
618     protected void outputTags(int level, Tag[] tags, boolean descend, int context) {     protected void outputTags(int level, Tag[] tags, boolean descend, int context) {
619    
620        HtmlRepairer htmlRepairer = new HtmlRepairer(rootDoc, noHTMLWarn, noEmailWarn,        for (int i=0; i<tags.length; ++i) {
621                                                     currentClass, currentMember);           outputTag(tags[i], level, descend, context, i == tags.length-1);
622          }
623        for (int i=0, ilim=tags.length; i<ilim; ++i) {     }
          Tag tag = tags[i];  
   
          if (!"Text".equals(tag.name())) {  
             printOpenTag(0 /* don't introduce additional whitespace */,  
                          "tag kind=\""+tag.kind()+"\" name=\""+tag.name()+"\"", false);  
          }  
          if (tag instanceof ThrowsTag) {  
             ThrowsTag throwsTag = (ThrowsTag)tag;  
             if (null!=throwsTag.exception()) {  
                outputType(level+1, "exception", throwsTag.exception());  
             }  
             else {  
                StringBuffer sb = new StringBuffer("Exception ");  
                sb.append(throwsTag.exceptionName());  
                sb.append(" not found in ");  
                if (currentExecMember instanceof MethodDoc) {  
                    MethodDoc m = (MethodDoc)currentExecMember;  
                    sb.append(m.returnType().typeName());  
                    sb.append(m.returnType().dimension());  
                    sb.append(' ');  
                }  
                sb.append(currentClass.qualifiedName());  
                sb.append('.');  
                sb.append(currentExecMember.name());  
                sb.append('(');  
                Parameter[] params = currentExecMember.parameters();  
                for (int j=0; j < params.length; j++) {  
                    sb.append(params[j].type().typeName());  
                    sb.append(params[j].type().dimension());  
                    sb.append(' ');  
                    sb.append(params[j].name());  
                    if (j != params.length-1)  
                         sb.append(", ");  
                }  
                sb.append(')');  
                printWarning(sb.toString());  
624    
625                 printAtomTag(level+1, "exception typename=\""+throwsTag.exceptionName()+"\"");     protected void outputTag(Tag tag, int level, boolean descend, int context, boolean lastTag) {
             }  
          }  
          else if (tag instanceof ParamTag) {  
             ParamTag paramTag = (ParamTag)tag;  
             printAtomTag(level+1, "parameter name=\""+paramTag.parameterName()+"\"");  
          }  
626    
627           if (null != tag.text()) {        if (!"Text".equals(tag.name())) {
628              //printOpenTag(level+1, "text", false);           printOpenTag(0 /* don't introduce additional whitespace */,
629              if (fixHTML) {                        "tag kind=\""+tag.kind()+"\" name=\""+tag.name()+"\"", false);
630                 print(htmlRepairer.getWellformedHTML(tag.text()));        }
631                 print(htmlRepairer.terminateText());        if (tag instanceof ThrowsTag) {
632              }           ThrowsTag throwsTag = (ThrowsTag)tag;
633              else {           if (null!=throwsTag.exception()) {
634                 print("<![CDATA["+cdata(tag.text())+"]]>");              outputType(level+1, "exception", throwsTag.exception());
635              }           }
636              //printCloseTag(0 /* don't introduce additional whitespace */, "text");           else {
637           }              StringBuffer sb = new StringBuffer("Exception ");
638           else {              sb.append(throwsTag.exceptionName());
639              printWarning("Tag got null text: "+tag);              sb.append(" not found in ");
640           }              if (currentExecMember instanceof MethodDoc) {
641                   MethodDoc m = (MethodDoc)currentExecMember;
642                   sb.append(m.returnType().typeName());
643                   sb.append(m.returnType().dimension());
644                   sb.append(' ');
645                }
646                sb.append(currentClass.qualifiedName());
647                sb.append('.');
648                sb.append(currentExecMember.name());
649                sb.append('(');
650                Parameter[] params = currentExecMember.parameters();
651                for (int j=0; j < params.length; j++) {
652                   sb.append(params[j].type().typeName());
653                   sb.append(params[j].type().dimension());
654                   sb.append(' ');
655                   sb.append(params[j].name());
656                   if (j != params.length-1)
657                      sb.append(", ");
658                }
659                sb.append(')');
660                printWarning(sb.toString());
661    
662                printAtomTag(level+1, "exception typename=\""+throwsTag.exceptionName()+"\"");
663             }
664          }
665          else if (tag instanceof ParamTag) {
666             ParamTag paramTag = (ParamTag)tag;
667             printAtomTag(level+1, "parameter name=\""+paramTag.parameterName()+"\"");
668          }
669    
670          if (null != tag.text()) {
671             //printOpenTag(level+1, "text", false);
672             if (fixHTML) {
673                print(htmlRepairer.getWellformedHTML(tag.text()));
674                print(htmlRepairer.terminateText());
675             }
676             else {
677                print("<![CDATA["+cdata(tag.text())+"]]>");
678             }
679             //printCloseTag(0 /* don't introduce additional whitespace */, "text");
680          }
681          else {
682             printWarning("Tag got null text: "+tag);
683          }
684    
685           if ((descend && ("@throws".equals(tag.name()) || "@param".equals(tag.name()))) || "@deprecated".equals(tag.name())) {        if ((descend && ("@throws".equals(tag.name()) || "@param".equals(tag.name()))) || "@deprecated".equals(tag.name())) {
686              if (tag.firstSentenceTags().length>0) {           if (tag.firstSentenceTags().length>0) {
687                 printOpenTag(level+1, "firstSentenceTags", false);              printOpenTag(level+1, "firstSentenceTags", false);
688                 outputTags(level+2, tag.firstSentenceTags(), false, context);              outputTags(level+2, tag.firstSentenceTags(), false, context);
689                 printCloseTag(0, "firstSentenceTags");              printCloseTag(0, "firstSentenceTags");
690              }           }
691                            
692              if (tag.inlineTags().length>0) {           if (tag.inlineTags().length>0) {
693                 printOpenTag(level+1, "inlineTags", false);              printOpenTag(level+1, "inlineTags", false);
694                 outputTags(level+2, tag.firstSentenceTags(), false, context);              outputTags(level+2, tag.firstSentenceTags(), false, context);
695                 printCloseTag(0, "inlineTags");              printCloseTag(0, "inlineTags");
696              }           }
697           }        }
698    
699           if (fixHTML && i == ilim - 1) {        if (fixHTML && lastTag) {
700              String terminateText = htmlRepairer.terminateText();           String terminateText = htmlRepairer.terminateText();
701              if (null != terminateText && terminateText.length() > 0) {           if (null != terminateText && terminateText.length() > 0) {
702                 print(terminateText);              print(terminateText);
703              }           }
704           }        }
705    
706           if (!"Text".equals(tag.name())) {        if (!"Text".equals(tag.name())) {
707    
708              Taglet inlineTaglet = (Taglet)tagletMap.get(tag.name().substring(1));           Taglet inlineTaglet = (Taglet)tagletMap.get(tag.name().substring(1));
709              if (null != inlineTaglet && inlineTaglet.isInlineTag()) {           if (null != inlineTaglet && inlineTaglet.isInlineTag()) {
710                 printOpenTag(0, "inlineTagletText", false);              printOpenTag(0, "inlineTagletText", false);
711                 print(inlineTaglet.toString(tag));              print(inlineTaglet.toString(tag));
712                 printCloseTag(0, "inlineTagletText");              printCloseTag(0, "inlineTagletText");
713              }           }
714    
715              printCloseTag(0, "tag", false);           printCloseTag(0, "tag", false);
          }  
716        }        }
   
       outputTagletText(tags, context, htmlRepairer);  
717     }     }
     
    void outputTagletText(Tag[] tags, int context, HtmlRepairer htmlRepairer) {  
718    
719       void outputTaglets(int level, Tag[] tags, boolean descend, int context)
720       {
721        for (Iterator it = tagletMap.keySet().iterator(); it.hasNext(); ) {        for (Iterator it = tagletMap.keySet().iterator(); it.hasNext(); ) {
722           String tagName = (String)it.next();           String tagName = (String)it.next();
723           Object o = tagletMap.get(tagName);           Object o = tagletMap.get(tagName);
724           Taglet taglet = (Taglet)o;           Taglet taglet = (Taglet)o;
          List tagsOfThisType = new ArrayList();  
725    
726           if (!taglet.isInlineTag()           if (!taglet.isInlineTag()
727               && ((context != CONTEXT_CONSTRUCTOR || taglet.inConstructor())               && ((context != CONTEXT_CONSTRUCTOR || taglet.inConstructor())
# Line 716  public class Driver { Line 731  public class Driver {
731                   || (context != CONTEXT_PACKAGE || taglet.inPackage())                   || (context != CONTEXT_PACKAGE || taglet.inPackage())
732                   || (context != CONTEXT_TYPE || taglet.inType()))) {                   || (context != CONTEXT_TYPE || taglet.inType()))) {
733                            
734                List tagsOfThisType = new ArrayList();
735              for (int i=0, ilim=tags.length; i<ilim; ++i) {              for (int i=0, ilim=tags.length; i<ilim; ++i) {
736                 if (tags[i].name().substring(1).equals(tagName)) {                 if (tags[i].name().substring(1).equals(tagName)) {
737                    tagsOfThisType.add(tags[i]);                    tagsOfThisType.add(tags[i]);
738                 }                 }
739              }              }
740    
741              if (!tagsOfThisType.isEmpty()) {              if (!tagsOfThisType.isEmpty()) {
742                 Tag[] tagletTags = (Tag[])tagsOfThisType.toArray(new Tag[tagsOfThisType.size()]);                 Tag[] tagletTags = (Tag[])tagsOfThisType.toArray(new Tag[tagsOfThisType.size()]);
743                 String tagletString = getTagletForName(tagName).toString(tagletTags);                 if (taglet instanceof StandardTaglet) {
744                 if (null != tagletString) {                    Iterator tagIterator = tagsOfThisType.iterator();
745                    printOpenTag(0, "tagletText tagName=\"" + tagName + "\"");                    while (tagIterator.hasNext()) {
746                    if (fixHTML) {                       Tag tag = (Tag)tagIterator.next();
747                       print(htmlRepairer.getWellformedHTML(tagletString));                       outputTag(tag, level, descend, context, !tagIterator.hasNext());
                      print(htmlRepairer.terminateText());  
748                    }                    }
749                    else {                 }
750                       print("<![CDATA["+cdata(tagletString)+"]]>");                 else {
751                      String tagletString = taglet.toString(tagletTags);
752                      if (null != tagletString) {
753                         printOpenTag(0, "tag name=\"" + tagName + "\" taglet-generated=\"true\"");
754                         if (fixHTML) {
755                            print(htmlRepairer.getWellformedHTML(tagletString));
756                            print(htmlRepairer.terminateText());
757                         }
758                         else {
759                            print("<![CDATA["+cdata(tagletString)+"]]>");
760                         }
761                         printCloseTag(0, "tag", false);
762                    }                    }
                   printCloseTag(0, "tagletText", false);  
763                 }                 }
764              }              }
765           }           }
766        }        }
767     }     }
     
   
    protected Taglet getTagletForName(String name) {  
       return (Taglet)tagletMap.get(name);  
    }  
768    
769     /**     /**
770      *  Inofficial entry point. We got an instance here.      *  Inofficial entry point. We got an instance here.
# Line 755  public class Driver { Line 776  public class Driver {
776    
777        boolean xmlOnly = false;        boolean xmlOnly = false;
778    
779          // Set the default Taglet order
780    
781          registerTaglet(new VersionTaglet());
782          registerTaglet(new AuthorTaglet());
783          registerTaglet(new SinceTaglet());
784          registerTaglet(new StandardTaglet("deprecated"));
785          registerTaglet(new StandardTaglet("see"));
786          registerTaglet(new StandardTaglet("param"));
787    
788          // Set the built-in Taglet filter
789    
790        AuthorTaglet.setTagletEnabled(false);        AuthorTaglet.setTagletEnabled(false);
791        VersionTaglet.setTagletEnabled(false);        VersionTaglet.setTagletEnabled(false);
792        SinceTaglet.setTagletEnabled(true);        SinceTaglet.setTagletEnabled(true);
# Line 907  public class Driver { Line 939  public class Driver {
939                          printError("Taglet class '" + option[1] + "' found, but register method isn't public static, or is abstract..");                          printError("Taglet class '" + option[1] + "' found, but register method isn't public static, or is abstract..");
940                       }                       }
941                       else {                       else {
942                          registerTagletMethod.invoke(null, new Object[] { tagletMap });                          Map tempMap = new HashMap();
943                            registerTagletMethod.invoke(null, new Object[] { tempMap });
944                          tagletLoaded = true;                          tagletLoaded = true;
945                            String name = (String)tempMap.keySet().iterator().next();
946                            Taglet taglet = (Taglet)tempMap.get(name);
947                            tagletMap.put(name, taglet);
948                            mentionedTags.add(taglet);
949                       }                       }
950                    }                    }
951                    catch (NoSuchMethodException e) {                    catch (NoSuchMethodException e) {
# Line 1028  public class Driver { Line 1065  public class Driver {
1065                 else if ("-uses".equals(optionTag)) {                 else if ("-uses".equals(optionTag)) {
1066                    docTransletOptions.uses = true;                    docTransletOptions.uses = true;
1067                 }                 }
1068                   else if ("-group".equals(optionTag)) {
1069                      if (!processGroupOption(option[1], option[2])) {
1070                         printError("Invalid package wildcard list in -group option \"" + option[1] + "\" " + option[2]);
1071                         return false;
1072                      }
1073                   }
1074                 else if ("-tag".equals(optionTag)) {                 else if ("-tag".equals(optionTag)) {
1075                    String tagSpec = option[1];                    String tagSpec = option[1];
1076                    boolean validTagSpec = false;                    boolean validTagSpec = false;
1077                    int ndx1 = tagSpec.indexOf(':');                    int ndx1 = tagSpec.indexOf(':');
1078                    if (ndx1 >= 0) {                    if (ndx1 < 0) {
1079                         Taglet taglet = (Taglet)tagletMap.get(tagSpec);
1080                         if (null == taglet) {
1081                            printError("There is no standard tag '" + tagSpec + "'.");
1082                         }
1083                         else {
1084                            if (mentionedTags.contains(taglet)) {
1085                               printError("Tag '" + tagSpec + "' has been added or moved before.");
1086                            }
1087                            else {
1088                               mentionedTags.add(taglet);
1089                              
1090                               // re-append taglet
1091                               tagletMap.remove(tagSpec);
1092                               tagletMap.put(tagSpec, taglet);
1093                            }
1094                         }
1095                      }
1096                      else {
1097                       int ndx2 = tagSpec.indexOf(':', ndx1 + 1);                       int ndx2 = tagSpec.indexOf(':', ndx1 + 1);
1098                       if (ndx2 > ndx1 && ndx2 < tagSpec.length() - 1) {                       if (ndx2 > ndx1 && ndx2 < tagSpec.length() - 1) {
1099                          String tagName = tagSpec.substring(0, ndx1);                          String tagName = tagSpec.substring(0, ndx1);
# Line 1106  public class Driver { Line 1167  public class Driver {
1167                                                    tagScopeFields);                                                    tagScopeFields);
1168                             taglet.setTagletEnabled(!tagDisabled);                             taglet.setTagletEnabled(!tagDisabled);
1169                             taglet.register(tagletMap);                             taglet.register(tagletMap);
1170                               mentionedTags.add(taglet);
1171                          }                          }
1172                       }                       }
1173                    }                    }
# Line 1187  public class Driver { Line 1249  public class Driver {
1249                 }                 }
1250              }              }
1251    
             // Register standard taglets  
   
             AuthorTaglet.register(tagletMap);  
             VersionTaglet.register(tagletMap);  
             SinceTaglet.register(tagletMap);  
             DeprecatedTaglet.register(tagletMap);  
   
1252              // Check for deprecation              // Check for deprecation
1253    
1254              boolean hasDeprecatedClasses = false;              boolean hasDeprecatedClasses = false;
# Line 1243  public class Driver { Line 1298  public class Driver {
1298                 }                 }
1299              }              }
1300    
1301                htmlRepairer = new HtmlRepairer(rootDoc, noHTMLWarn, noEmailWarn,
1302                                                currentClass, currentMember);
1303    
1304              collectUsage();              collectUsage();
1305    
1306              // Begin XML generation              // Begin XML generation
# Line 1319  public class Driver { Line 1377  public class Driver {
1377                 printAtomTag(1, "specifiedpackage name=\""+sp.name()+"\"");                 printAtomTag(1, "specifiedpackage name=\""+sp.name()+"\"");
1378              }              }
1379              specifiedPackages = null;              specifiedPackages = null;
1380            
1381                // Output package group information specified on the
1382                // command line
1383    
1384                println();
1385                println(1, "<!-- Package groups specified by user on command line -->");
1386                {
1387                   Iterator packageGroupIt = packageGroups.iterator();
1388                   while (packageGroupIt.hasNext()) {
1389                      PackageGroup packageGroup = (PackageGroup)packageGroupIt.next();
1390                      SortedSet groupedPackages = packageGroup.getPackages();
1391                      if (groupedPackages.isEmpty()) {
1392                         printWarning("Package group named '"
1393                                      + packageGroup.getName() + "' didn't match any packages.");
1394                      }
1395                      else {
1396                         printOpenTag(1, "packagegroup name=\"" + packageGroup.getName() + "\"");
1397                         Iterator groupedPackageIt = groupedPackages.iterator();
1398                         while (groupedPackageIt.hasNext()) {
1399                            PackageDoc groupedPackageDoc = (PackageDoc)groupedPackageIt.next();
1400                            printAtomTag(2, "package name=\"" + groupedPackageDoc.name() + "\"");
1401                         }
1402                         printCloseTag(1, "packagegroup");
1403                      }
1404                   }
1405                   packageGroups = null;
1406                }
1407    
1408              // Output information on all packages for which documentation              // Output information on all packages for which documentation
1409              // has been made available via the Doclet API              // has been made available via the Doclet API
1410    
# Line 1673  public class Driver { Line 1758  public class Driver {
1758        else if ("-doctitle".equals(option)) return 2;        else if ("-doctitle".equals(option)) return 2;
1759        else if ("-nodeprecatedlist".equals(option)) return 1;        else if ("-nodeprecatedlist".equals(option)) return 1;
1760        else if ("-uses".equals(option)) return 1;        else if ("-uses".equals(option)) return 1;
1761          else if ("-group".equals(option)) return 3;
1762    
1763        else return -1;        else return -1;
1764     }     }
# Line 2235  public class Driver { Line 2321  public class Driver {
2321           printCloseTag(level, "references");           printCloseTag(level, "references");
2322        }        }
2323     }     }
2324    
2325       private boolean processGroupOption(String groupName, String colonSeparatedPackageList)
2326       {
2327          try {
2328             PackageMatcher packageMatcher = new PackageMatcher();
2329    
2330             StringTokenizer tokenizer = new StringTokenizer(colonSeparatedPackageList, ":");
2331             while (tokenizer.hasMoreTokens()) {
2332                String packageWildcard = tokenizer.nextToken();
2333                packageMatcher.addWildcard(packageWildcard);
2334             }
2335    
2336             SortedSet groupPackages = packageMatcher.match(rootDoc.specifiedPackages());
2337    
2338             packageGroups.add(new PackageGroup(groupName, groupPackages));
2339    
2340             return true;
2341          }
2342          catch (InvalidPackageWildcardException e) {
2343             return false;
2344          }
2345       }
2346    
2347       private void registerTaglet(Taglet taglet)
2348       {
2349          tagletMap.put(taglet.getName(), taglet);
2350       }
2351  }  }

Legend:
Removed from v.1.41  
changed lines
  Added in v.1.42

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26