TexinfoDoclet.java 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /* Copyright (C) 2001 Free Software Foundation
  2. This file is part of libgcj.
  3. This software is copyrighted work licensed under the terms of the
  4. Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
  5. details. */
  6. import java.io.*;
  7. import com.sun.javadoc.*;
  8. public class TexinfoDoclet
  9. {
  10. static PrintStream outfile;
  11. public static int optionLength(String option)
  12. {
  13. if (option.equals("-outfile"))
  14. return 2;
  15. return 0;
  16. }
  17. private static String replace (String s, String text, String replacement)
  18. {
  19. int i = s.indexOf (text);
  20. while (i != -1)
  21. {
  22. s = s.substring(0, i) + replacement + s.substring(i+text.length());
  23. i = s.indexOf (text);
  24. }
  25. return s;
  26. }
  27. private static String texify (String s)
  28. {
  29. if (s.indexOf('<') == -1)
  30. return s;
  31. s = replace (s, "<code>", "@code{");
  32. s = replace (s, "</code>", "}");
  33. s = replace (s, "<ol>", "\n@itemize @bullet\n");
  34. s = replace (s, "</ol>", "\n@end itemize\n");
  35. s = replace (s, "<ul>", "\n@itemize @bullet\n");
  36. s = replace (s, "</ul>", "\n@end itemize\n");
  37. s = replace (s, "<li>", "\n@item\n");
  38. s = replace (s, "</li>", "\n");
  39. s = replace (s, "<p>", "\n\n");
  40. s = replace (s, "<CODE>", "@code{");
  41. s = replace (s, "</CODE>", "}");
  42. s = replace (s, "<OL>", "\n@itemize @bullet\n");
  43. s = replace (s, "</OL>", "\n@end itemize\n");
  44. s = replace (s, "<UL>", "\n@itemize @bullet\n");
  45. s = replace (s, "</UL>", "\n@end itemize\n");
  46. s = replace (s, "<LI>", "\n@item\n");
  47. s = replace (s, "</LI>", "\n");
  48. s = replace (s, "<P>", "\n\n");
  49. return s;
  50. }
  51. private static void emitMethod (ClassDoc c, MethodDoc m)
  52. {
  53. outfile.print ("@deftypemethod " + c.typeName()
  54. + " {" + m.modifiers()
  55. + " " + m.returnType().typeName()
  56. + "} " + m.name());
  57. outfile.print (" (");
  58. Parameter p[] = m.parameters();
  59. boolean first = true;
  60. for (int i = 0; i < p.length; i++)
  61. {
  62. if (!first)
  63. outfile.print (", ");
  64. outfile.print (p[i].typeName()
  65. + "@w{ }@var{"
  66. + p[i].name()
  67. + "}");
  68. first = false;
  69. }
  70. outfile.print (") ");
  71. ClassDoc exceptions[] = m.thrownExceptions();
  72. if (exceptions.length > 0)
  73. {
  74. outfile.print ("@*throws ");
  75. first = true;
  76. for (int i = 0; i < exceptions.length; i++)
  77. {
  78. if (!first)
  79. outfile.print (", ");
  80. outfile.print (exceptions[i].typeName());
  81. first = false;
  82. }
  83. }
  84. outfile.println ("");
  85. outfile.println (texify (m.commentText()));
  86. outfile.println ("@end deftypemethod");
  87. }
  88. private static void emitClass (ClassDoc c)
  89. {
  90. MethodDoc[] methods = c.methods();
  91. for (int i = 0; i < methods.length; i++)
  92. {
  93. emitMethod (c, methods[i]);
  94. }
  95. }
  96. public static boolean start (RootDoc root)
  97. {
  98. String options[][] = root.options ();
  99. for (int i = 0; i < options.length; i++)
  100. {
  101. try
  102. {
  103. if (options[i][0].equals ("-outfile"))
  104. {
  105. outfile = new PrintStream (new FileOutputStream (options[i][1]));
  106. }
  107. } catch (java.io.IOException e) {
  108. System.err.println ("Can't write to file " + options[i][1]);
  109. return false;
  110. }
  111. }
  112. ClassDoc[] classes = root.classes();
  113. for (int i = 0; i < classes.length; i++)
  114. {
  115. emitClass (classes[i]);
  116. }
  117. return true;
  118. }
  119. }