8012174: {@literal} and {@code} should use \"new\" Taglet, not old.
authorjjg
Tue, 14 May 2013 10:14:54 -0700
changeset 17565 a705fe5e539f
parent 17564 c329fe11193d
child 17566 7e1a338e1085
8012174: {@literal} and {@code} should use \"new\" Taglet, not old. Reviewed-by: darcy
langtools/src/share/classes/com/sun/tools/doclets/formats/html/TagletWriterImpl.java
langtools/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlTag.java
langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/CodeTaglet.java
langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/ExpertTaglet.java
langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/LiteralTaglet.java
langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/TagletManager.java
langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/TagletWriter.java
--- a/langtools/src/share/classes/com/sun/tools/doclets/formats/html/TagletWriterImpl.java	Tue May 14 10:14:53 2013 -0700
+++ b/langtools/src/share/classes/com/sun/tools/doclets/formats/html/TagletWriterImpl.java	Tue May 14 10:14:54 2013 -0700
@@ -26,6 +26,10 @@
 package com.sun.tools.doclets.formats.html;
 
 import com.sun.javadoc.*;
+import com.sun.tools.doclets.formats.html.markup.HtmlAttr;
+import com.sun.tools.doclets.formats.html.markup.HtmlTag;
+import com.sun.tools.doclets.formats.html.markup.HtmlTree;
+import com.sun.tools.doclets.formats.html.markup.StringContent;
 import com.sun.tools.doclets.internal.toolkit.*;
 import com.sun.tools.doclets.internal.toolkit.builders.SerializedFormBuilder;
 import com.sun.tools.doclets.internal.toolkit.taglets.*;
@@ -65,6 +69,14 @@
     /**
      * {@inheritDoc}
      */
+    protected TagletOutput codeTagOutput(Tag tag) {
+        Content result = HtmlTree.CODE(new StringContent(tag.text()));
+        return new TagletOutputImpl(result.toString());
+    }
+
+    /**
+     * {@inheritDoc}
+     */
     public TagletOutput getDocRootOutput() {
         if (configuration.docrootparent.length() > 0)
             return new TagletOutputImpl(configuration.docrootparent);
@@ -121,6 +133,23 @@
     /**
      * {@inheritDoc}
      */
+    protected TagletOutput expertTagOutput(Tag tag) {
+        HtmlTree result = new HtmlTree(HtmlTag.SUB, new StringContent(tag.text()));
+        result.addAttr(HtmlAttr.ID, "expert");
+        return new TagletOutputImpl(result.toString());
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    protected TagletOutput literalTagOutput(Tag tag) {
+        Content result = new StringContent(tag.text());
+        return new TagletOutputImpl(result.toString());
+    }
+
+    /**
+     * {@inheritDoc}
+     */
     public MessageRetriever getMsgRetriever() {
         return configuration.message;
     }
--- a/langtools/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlTag.java	Tue May 14 10:14:53 2013 -0700
+++ b/langtools/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlTag.java	Tue May 14 10:14:54 2013 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -75,6 +75,7 @@
     SMALL(BlockType.INLINE, EndTag.END),
     SPAN(BlockType.INLINE, EndTag.END),
     STRONG(BlockType.INLINE, EndTag.END),
+    SUB(BlockType.INLINE, EndTag.END),
     TABLE,
     TBODY,
     TD,
--- a/langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/CodeTaglet.java	Tue May 14 10:14:53 2013 -0700
+++ b/langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/CodeTaglet.java	Tue May 14 10:14:54 2013 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -26,7 +26,6 @@
 
 import java.util.Map;
 import com.sun.javadoc.Tag;
-import com.sun.tools.doclets.Taglet;
 
 /**
  * An inline Taglet used to denote literal code fragments.
@@ -49,23 +48,23 @@
  * @since 1.5
  */
 
-public class CodeTaglet extends LiteralTaglet {
+public class CodeTaglet extends BaseInlineTaglet {
 
-        private static final String NAME = "code";
+    private static final String NAME = "code";
 
-        public static void register(Map<String, Taglet> map) {
-                map.remove(NAME);
-                map.put(NAME, new CodeTaglet());
-        }
+    public static void register(Map<String, Taglet> map) {
+            map.remove(NAME);
+            map.put(NAME, new CodeTaglet());
+    }
 
-        public String getName() {
-                return NAME;
-        }
+    public String getName() {
+            return NAME;
+    }
 
-        /*
-         * Wraps @literal's result in a <code> element.
-         */
-        public String toString(Tag tag) {
-                return "<code>" + super.toString(tag) + "</code>";
-        }
+    /**
+     * {@inheritDoc}
+     */
+    public TagletOutput getTagletOutput(Tag tag, TagletWriter writer) {
+        return writer.codeTagOutput(tag);
+    }
 }
--- a/langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/ExpertTaglet.java	Tue May 14 10:14:53 2013 -0700
+++ b/langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/ExpertTaglet.java	Tue May 14 10:14:54 2013 -0700
@@ -27,7 +27,6 @@
 
 import java.util.Map;
 
-import com.sun.tools.doclets.Taglet;
 import com.sun.javadoc.Tag;
 
 /**
@@ -39,11 +38,9 @@
  *  deletion without notice.</b>
  *
  */
-public class ExpertTaglet implements Taglet {
+public class ExpertTaglet extends BaseTaglet {
 
     private static final String NAME = "expert";
-    private static final String START_TAG = "<sub id=\"expert\">";
-    private static final String END_TAG = "</sub>";
 
     /**
      * {@inheritDoc}
@@ -85,22 +82,10 @@
         map.put(NAME, new ExpertTaglet());
     }
 
-    public String toString(Tag tag) {
-        return (tag.text() == null || tag.text().length() == 0) ? null :
-            START_TAG + LiteralTaglet.textToString(tag.text()) + END_TAG;
+    /**
+     * {@inheritDoc}
+     */
+    public TagletOutput getTagletOutput(Tag tag, TagletWriter writer) {
+        return writer.expertTagOutput(tag);
     }
-
-
-    public String toString(Tag[] tags) {
-        if (tags == null || tags.length == 0) return null;
-
-        StringBuffer sb = new StringBuffer(START_TAG);
-
-        for(Tag t:tags) {
-            sb.append(LiteralTaglet.textToString(t.text()));
-        }
-        sb.append(END_TAG);
-        return sb.toString();
-    }
-
 }
--- a/langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/LiteralTaglet.java	Tue May 14 10:14:53 2013 -0700
+++ b/langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/LiteralTaglet.java	Tue May 14 10:14:54 2013 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -25,8 +25,9 @@
 package com.sun.tools.doclets.internal.toolkit.taglets;
 
 import java.util.Map;
+
+import com.sun.javadoc.Doc;
 import com.sun.javadoc.Tag;
-import com.sun.tools.doclets.Taglet;
 
 
 /**
@@ -47,60 +48,23 @@
  * @since 1.5
  */
 
-public class LiteralTaglet implements Taglet {
+public class LiteralTaglet extends BaseInlineTaglet {
 
     private static final String NAME = "literal";
 
-    public static void register(Map<String,Taglet> map) {
-           map.remove(NAME);
-           map.put(NAME, new LiteralTaglet());
+    public static void register(Map<String, Taglet> map) {
+        map.remove(NAME);
+        map.put(NAME, new LiteralTaglet());
     }
 
     public String getName() {
         return NAME;
     }
 
-    public String toString(Tag tag) {
-        return textToString(tag.text());
-    }
-
-    public String toString(Tag[] tags) { return null; }
-
-    public boolean inField() { return false; }
-
-    public boolean inConstructor() { return false; }
-
-    public boolean inMethod() { return false; }
-
-    public boolean inOverview() { return false; }
-
-    public boolean inPackage() { return false; }
-
-    public boolean inType() { return false; }
-
-    public boolean isInlineTag() { return true; }
-
-    /*
-     * Replace occurrences of the following characters:  < > &
+    /**
+     * {@inheritDoc}
      */
-    protected static String textToString(String text) {
-           StringBuilder buf = new StringBuilder();
-           for (int i = 0; i < text.length(); i++) {
-               char c = text.charAt(i);
-               switch (c) {
-                   case '<':
-                          buf.append("&lt;");
-                          break;
-                   case '>':
-                          buf.append("&gt;");
-                          break;
-                   case '&':
-                          buf.append("&amp;");
-                          break;
-                   default:
-                          buf.append(c);
-               }
-           }
-           return buf.toString();
+    public TagletOutput getTagletOutput(Tag tag, TagletWriter writer) {
+        return writer.literalTagOutput(tag);
     }
 }
--- a/langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/TagletManager.java	Tue May 14 10:14:53 2013 -0700
+++ b/langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/TagletManager.java	Tue May 14 10:14:54 2013 -0700
@@ -659,10 +659,8 @@
         customTags.put((temp = new DocRootTaglet()).getName(), temp);
         customTags.put((temp = new InheritDocTaglet()).getName(), temp);
         customTags.put((temp = new ValueTaglet()).getName(), temp);
-        customTags.put((temp = new LegacyTaglet(new LiteralTaglet())).getName(),
-            temp);
-        customTags.put((temp = new LegacyTaglet(new CodeTaglet())).getName(),
-            temp);
+        customTags.put((temp = new LiteralTaglet()).getName(), temp);
+        customTags.put((temp = new CodeTaglet()).getName(), temp);
 
         //Keep track of the names of standard tags for error
         //checking purposes.
@@ -705,7 +703,7 @@
             SimpleTaglet.FIELD + SimpleTaglet.METHOD)).getName(), temp);
         customTags.put((temp = new SimpleTaglet("treatAsPrivate", null,
                 SimpleTaglet.FIELD + SimpleTaglet.METHOD + SimpleTaglet.TYPE)).getName(), temp);
-        customTags.put((temp = new LegacyTaglet(new ExpertTaglet())).getName(), temp);
+        customTags.put((temp = new ExpertTaglet()).getName(), temp);
 
         standardTags.add("propertyGetter");
         standardTags.add("propertySetter");
--- a/langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/TagletWriter.java	Tue May 14 10:14:53 2013 -0700
+++ b/langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/TagletWriter.java	Tue May 14 10:14:54 2013 -0700
@@ -53,11 +53,19 @@
     }
 
     /**
-     * @return an instance of the output object.
+     * @return an instance of an output object.
      */
     public abstract TagletOutput getOutputInstance();
 
     /**
+     * Return the output for a {@code...} tag.
+     *
+     * @param tag the tag.
+     * @return the output of the taglet.
+     */
+    protected abstract TagletOutput codeTagOutput(Tag tag);
+
+    /**
      * Returns the output for the DocRoot inline tag.
      * @return the output for the DocRoot inline tag.
      */
@@ -72,6 +80,23 @@
     protected abstract TagletOutput deprecatedTagOutput(Doc doc);
 
     /**
+     * Return the output for a {@expert...} tag.
+     *
+     * @param tag the tag.
+     * @return the output of the taglet.
+     */
+    // TODO: remove this taglet
+    protected abstract TagletOutput expertTagOutput(Tag tag);
+
+    /**
+     * Return the output for a {@literal...} tag.
+     *
+     * @param tag the tag.
+     * @return the output of the taglet.
+     */
+    protected abstract TagletOutput literalTagOutput(Tag tag);
+
+    /**
      * Returns {@link MessageRetriever} for output purposes.
      *
      * @return {@link MessageRetriever} for output purposes.