changeset 2136:997c0fae2b12 jdk8-b91

Merge
author lana
date Fri, 17 May 2013 10:13:34 -0700
parents 9717b9523d46 445b8b5ae9f4
children 4830d661c4f9 58eace4d997f 31344e8e3343 f1b90ea7d402
files src/share/classes/com/sun/tools/doclets/formats/html/TagletOutputImpl.java src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/ExpertTaglet.java src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/TagletOutput.java src/share/classes/javax/tools/annotation/GenerateNativeHeader.java test/tools/javac/nativeHeaders/javahComparison/TestClass2.java test/tools/javac/nativeHeaders/javahComparison/TestClass3.java
diffstat 309 files changed, 12938 insertions(+), 3600 deletions(-) [+]
line wrap: on
line diff
--- a/make/tools/genstubs/GenStubs.java	Thu May 16 12:16:07 2013 -0700
+++ b/make/tools/genstubs/GenStubs.java	Fri May 17 10:13:34 2013 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2009, 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
@@ -37,6 +37,7 @@
 import com.sun.tools.javac.code.Flags;
 import com.sun.tools.javac.code.TypeTag;
 import com.sun.tools.javac.tree.JCTree;
+import com.sun.tools.javac.tree.JCTree.JCClassDecl;
 import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
 import com.sun.tools.javac.tree.JCTree.JCFieldAccess;
 import com.sun.tools.javac.tree.JCTree.JCIdent;
@@ -208,6 +209,21 @@
          * methods: remove method bodies, make methods native
          */
         @Override
+        public void visitClassDef(JCClassDecl tree) {
+            long prevClassMods = currClassMods;
+            currClassMods = tree.mods.flags;
+            try {
+                super.visitClassDef(tree);;
+            } finally {
+                currClassMods = prevClassMods;
+            }
+        }
+        private long currClassMods = 0;
+
+        /**
+         * methods: remove method bodies, make methods native
+         */
+        @Override
         public void visitMethodDef(JCMethodDecl tree) {
             tree.mods = translate(tree.mods);
             tree.restype = translate(tree.restype);
@@ -215,7 +231,11 @@
             tree.params = translateVarDefs(tree.params);
             tree.thrown = translate(tree.thrown);
             if (tree.restype != null && tree.body != null) {
-                tree.mods.flags |= Flags.NATIVE;
+                if ((currClassMods & Flags.INTERFACE) != 0) {
+                    tree.mods.flags &= ~Flags.DEFAULT;
+                } else {
+                    tree.mods.flags |= Flags.NATIVE;
+                }
                 tree.body = null;
             }
             result = tree;
--- a/makefiles/BuildLangtools.gmk	Thu May 16 12:16:07 2013 -0700
+++ b/makefiles/BuildLangtools.gmk	Fri May 17 10:13:34 2013 -0700
@@ -1,5 +1,5 @@
 #
-# Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2011, 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
@@ -123,10 +123,10 @@
              genstubs.GenStubs
         # We fetch source from the JDK...
         JDKS=$(JDK_TOPDIR)/src/share/classes
-        # Build the list of classes to generate stubs from. java/util/Objects.java isn't
+        # Build the list of classes to generate stubs from. java/util/function/Predicate.java isn't
         # currently needed, but is used as a demo for now.
 	 STUBSOURCES:=$(shell $(FIND) $(JDKS) -name "*.java" | $(GREP) \
-		    -e "$(JDKS)/java/util/Objects.java")
+		    -e "$(JDKS)/java/util/function/Predicate.java")
         # Rewrite the file names into class names because the GenStubs tool require this.
         STUBCLASSES:=$(subst /,.,$(patsubst $(JDKS)/%.java,%,$(STUBSOURCES)))
 
--- a/src/share/classes/com/sun/source/tree/VariableTree.java	Thu May 16 12:16:07 2013 -0700
+++ b/src/share/classes/com/sun/source/tree/VariableTree.java	Fri May 17 10:13:34 2013 -0700
@@ -33,6 +33,7 @@
  * For example:
  * <pre>
  *   <em>modifiers</em> <em>type</em> <em>name</em> <em>initializer</em> ;
+ *   <em>modifiers</em> <em>type</em> <em>qualified-name</em>.this
  * </pre>
  *
  * @jls sections 8.3 and 14.4
@@ -45,6 +46,7 @@
 public interface VariableTree extends StatementTree {
     ModifiersTree getModifiers();
     Name getName();
+    ExpressionTree getNameExpression();
     Tree getType();
     ExpressionTree getInitializer();
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/share/classes/com/sun/source/util/DocTreePath.java	Fri May 17 10:13:34 2013 -0700
@@ -0,0 +1,171 @@
+/*
+ * Copyright (c) 2006, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.sun.source.util;
+
+import com.sun.source.doctree.DocCommentTree;
+import com.sun.source.doctree.DocTree;
+import java.util.Iterator;
+
+/**
+ * A path of tree nodes, typically used to represent the sequence of ancestor
+ * nodes of a tree node up to the top level DocCommentTree node.
+ *
+ * @since 1.8
+ */
+@jdk.Supported
+public class DocTreePath implements Iterable<DocTree> {
+    /**
+     * Gets a documentation tree path for a tree node within a compilation unit.
+     * @return null if the node is not found
+     */
+    public static DocTreePath getPath(TreePath treePath, DocCommentTree doc, DocTree target) {
+        return getPath(new DocTreePath(treePath, doc), target);
+    }
+
+    /**
+     * Gets a documentation tree path for a tree node within a subtree identified by a DocTreePath object.
+     * @return null if the node is not found
+     */
+    public static DocTreePath getPath(DocTreePath path, DocTree target) {
+        path.getClass();
+        target.getClass();
+
+        class Result extends Error {
+            static final long serialVersionUID = -5942088234594905625L;
+            DocTreePath path;
+            Result(DocTreePath path) {
+                this.path = path;
+            }
+        }
+
+        class PathFinder extends DocTreePathScanner<DocTreePath,DocTree> {
+            public DocTreePath scan(DocTree tree, DocTree target) {
+                if (tree == target) {
+                    throw new Result(new DocTreePath(getCurrentPath(), target));
+                }
+                return super.scan(tree, target);
+            }
+        }
+
+        if (path.getLeaf() == target) {
+            return path;
+        }
+
+        try {
+            new PathFinder().scan(path, target);
+        } catch (Result result) {
+            return result.path;
+        }
+        return null;
+    }
+
+    /**
+     * Creates a DocTreePath for a root node.
+     *
+     * @param treePath the TreePath from which the root node was created.
+     * @param t the DocCommentTree to create the path for.
+     */
+    public DocTreePath(TreePath treePath, DocCommentTree t) {
+        treePath.getClass();
+        t.getClass();
+
+        this.treePath = treePath;
+        this.docComment = t;
+        this.parent = null;
+        this.leaf = t;
+    }
+
+    /**
+     * Creates a DocTreePath for a child node.
+     */
+    public DocTreePath(DocTreePath p, DocTree t) {
+        if (t.getKind() == DocTree.Kind.DOC_COMMENT) {
+            throw new IllegalArgumentException("Use DocTreePath(TreePath, DocCommentTree) to construct DocTreePath for a DocCommentTree.");
+        } else {
+            treePath = p.treePath;
+            docComment = p.docComment;
+            parent = p;
+        }
+        leaf = t;
+    }
+
+    /**
+     * Get the TreePath associated with this path.
+     * @return TreePath for this DocTreePath
+     */
+    public TreePath getTreePath() {
+        return treePath;
+    }
+
+    /**
+     * Get the DocCommentTree associated with this path.
+     * @return DocCommentTree for this DocTreePath
+     */
+    public DocCommentTree getDocComment() {
+        return docComment;
+    }
+
+    /**
+     * Get the leaf node for this path.
+     * @return DocTree for this DocTreePath
+     */
+    public DocTree getLeaf() {
+        return leaf;
+    }
+
+    /**
+     * Get the path for the enclosing node, or null if there is no enclosing node.
+     * @return DocTreePath of parent
+     */
+    public DocTreePath getParentPath() {
+        return parent;
+    }
+
+    public Iterator<DocTree> iterator() {
+        return new Iterator<DocTree>() {
+            public boolean hasNext() {
+                return next != null;
+            }
+
+            public DocTree next() {
+                DocTree t = next.leaf;
+                next = next.parent;
+                return t;
+            }
+
+            public void remove() {
+                throw new UnsupportedOperationException();
+            }
+
+            private DocTreePath next = DocTreePath.this;
+        };
+    }
+
+    private final TreePath treePath;
+    private final DocCommentTree docComment;
+    private final DocTree leaf;
+    private final DocTreePath parent;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/share/classes/com/sun/source/util/DocTreePathScanner.java	Fri May 17 10:13:34 2013 -0700
@@ -0,0 +1,80 @@
+/*
+ * Copyright (c) 2006, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.sun.source.util;
+
+import com.sun.source.doctree.DocTree;
+
+/**
+ * A DocTreeVisitor that visits all the child tree nodes, and provides
+ * support for maintaining a path for the parent nodes.
+ * To visit nodes of a particular type, just override the
+ * corresponding visitorXYZ method.
+ * Inside your method, call super.visitXYZ to visit descendant
+ * nodes.
+ *
+ * @since 1.8
+ */
+@jdk.Supported
+public class DocTreePathScanner<R, P> extends DocTreeScanner<R, P> {
+    /**
+     * Scan a tree from a position identified by a TreePath.
+     */
+    public R scan(DocTreePath path, P p) {
+        this.path = path;
+        try {
+            return path.getLeaf().accept(this, p);
+        } finally {
+            this.path = null;
+        }
+    }
+
+    /**
+     * Scan a single node.
+     * The current path is updated for the duration of the scan.
+     */
+    @Override
+    public R scan(DocTree tree, P p) {
+        if (tree == null)
+            return null;
+
+        DocTreePath prev = path;
+        path = new DocTreePath(path, tree);
+        try {
+            return tree.accept(this, p);
+        } finally {
+            path = prev;
+        }
+    }
+
+    /**
+     * Get the current path for the node, as built up by the currently
+     * active set of scan calls.
+     */
+    public DocTreePath getCurrentPath() {
+        return path;
+    }
+
+    private DocTreePath path;
+}
--- a/src/share/classes/com/sun/source/util/DocTrees.java	Thu May 16 12:16:07 2013 -0700
+++ b/src/share/classes/com/sun/source/util/DocTrees.java	Fri May 17 10:13:34 2013 -0700
@@ -67,10 +67,10 @@
     public abstract DocCommentTree getDocCommentTree(TreePath path);
 
     /**
-     * Gets the language model element referred to by a ReferenceTree that
-     * appears on the declaration identified by the given path.
+     * Gets the language model element referred to by the leaf node of the given
+     * {@link DocTreePath}, or null if unknown.
      */
-    public abstract Element getElement(TreePath path, ReferenceTree reference);
+    public abstract Element getElement(DocTreePath path);
 
     public abstract DocSourcePositions getSourcePositions();
 
--- a/src/share/classes/com/sun/source/util/TreeScanner.java	Thu May 16 12:16:07 2013 -0700
+++ b/src/share/classes/com/sun/source/util/TreeScanner.java	Fri May 17 10:13:34 2013 -0700
@@ -149,6 +149,7 @@
     public R visitVariable(VariableTree node, P p) {
         R r = scan(node.getModifiers(), p);
         r = scanAndReduce(node.getType(), p, r);
+        r = scanAndReduce(node.getNameExpression(), p, r);
         r = scanAndReduce(node.getInitializer(), p, r);
         return r;
     }
--- a/src/share/classes/com/sun/tools/classfile/ClassWriter.java	Thu May 16 12:16:07 2013 -0700
+++ b/src/share/classes/com/sun/tools/classfile/ClassWriter.java	Fri May 17 10:13:34 2013 -0700
@@ -751,7 +751,7 @@
                 break;
             // exception parameter
             case EXCEPTION_PARAMETER:
-                out.writeByte(p.exception_index);
+                out.writeShort(p.exception_index);
                 break;
             // method receiver
             case METHOD_RECEIVER:
@@ -770,11 +770,11 @@
                 break;
             // class extends or implements clause
             case CLASS_EXTENDS:
-                out.writeByte(p.type_index);
+                out.writeShort(p.type_index);
                 break;
             // throws
             case THROWS:
-                out.writeByte(p.type_index);
+                out.writeShort(p.type_index);
                 break;
             // method parameter
             case METHOD_FORMAL_PARAMETER:
--- a/src/share/classes/com/sun/tools/classfile/TypeAnnotation.java	Thu May 16 12:16:07 2013 -0700
+++ b/src/share/classes/com/sun/tools/classfile/TypeAnnotation.java	Fri May 17 10:13:34 2013 -0700
@@ -111,7 +111,7 @@
             break;
         // exception parameter
         case EXCEPTION_PARAMETER:
-            position.exception_index = cr.readUnsignedByte();
+            position.exception_index = cr.readUnsignedShort();
             break;
         // method receiver
         case METHOD_RECEIVER:
@@ -198,7 +198,7 @@
             break;
         // exception parameter
         case EXCEPTION_PARAMETER:
-            n += 1; // exception_index
+            n += 2; // exception_index
             break;
         // method receiver
         case METHOD_RECEIVER:
--- a/src/share/classes/com/sun/tools/doclets/formats/html/AbstractExecutableMemberWriter.java	Thu May 16 12:16:07 2013 -0700
+++ b/src/share/classes/com/sun/tools/doclets/formats/html/AbstractExecutableMemberWriter.java	Fri May 17 10:13:34 2013 -0700
@@ -60,17 +60,24 @@
      * @param htmltree the content tree to which the parameters will be added.
      * @return the display length required to write this information.
      */
-    protected int addTypeParameters(ExecutableMemberDoc member, Content htmltree) {
+    protected void addTypeParameters(ExecutableMemberDoc member, Content htmltree) {
+        Content typeParameters = getTypeParameters(member);
+        if (!typeParameters.isEmpty()) {
+            htmltree.addContent(typeParameters);
+            htmltree.addContent(writer.getSpace());
+        }
+    }
+
+    /**
+     * Get the type parameters for the executable member.
+     *
+     * @param member the member for which to get the type parameters.
+     * @return the type parameters.
+     */
+    protected Content getTypeParameters(ExecutableMemberDoc member) {
         LinkInfoImpl linkInfo = new LinkInfoImpl(configuration,
-            LinkInfoImpl.CONTEXT_MEMBER_TYPE_PARAMS, member, false);
-        String typeParameters = writer.getTypeParameterLinks(linkInfo);
-        if (linkInfo.displayLength > 0) {
-            Content linkContent = new RawHtml(typeParameters);
-            htmltree.addContent(linkContent);
-            htmltree.addContent(writer.getSpace());
-            writer.displayLength += linkInfo.displayLength + 1;
-        }
-        return linkInfo.displayLength;
+            LinkInfoImpl.Kind.MEMBER_TYPE_PARAMS, member);
+        return writer.getTypeParameterLinks(linkInfo);
     }
 
     /**
@@ -78,7 +85,7 @@
      */
     protected Content getDeprecatedLink(ProgramElementDoc member) {
         ExecutableMemberDoc emd = (ExecutableMemberDoc)member;
-        return writer.getDocLink(LinkInfoImpl.CONTEXT_MEMBER, (MemberDoc) emd,
+        return writer.getDocLink(LinkInfoImpl.Kind.MEMBER, (MemberDoc) emd,
                 emd.qualifiedName() + emd.flatSignature());
     }
 
@@ -90,16 +97,15 @@
      * @param member the member being linked to
      * @param tdSummary the content tree to which the link will be added
      */
-    protected void addSummaryLink(int context, ClassDoc cd, ProgramElementDoc member,
+    protected void addSummaryLink(LinkInfoImpl.Kind context, ClassDoc cd, ProgramElementDoc member,
             Content tdSummary) {
         ExecutableMemberDoc emd = (ExecutableMemberDoc)member;
         String name = emd.name();
-        Content strong = HtmlTree.STRONG(new RawHtml(
+        Content strong = HtmlTree.STRONG(
                 writer.getDocLink(context, cd, (MemberDoc) emd,
-                name, false)));
+                name, false));
         Content code = HtmlTree.CODE(strong);
-        writer.displayLength = name.length();
-        addParameters(emd, false, code);
+        addParameters(emd, false, code, name.length() - 1);
         tdSummary.addContent(code);
     }
 
@@ -112,9 +118,9 @@
      */
     protected void addInheritedSummaryLink(ClassDoc cd,
             ProgramElementDoc member, Content linksTree) {
-        linksTree.addContent(new RawHtml(
-                writer.getDocLink(LinkInfoImpl.CONTEXT_MEMBER, cd, (MemberDoc) member,
-                member.name(), false)));
+        linksTree.addContent(
+                writer.getDocLink(LinkInfoImpl.Kind.MEMBER, cd, (MemberDoc) member,
+                member.name(), false));
     }
 
     /**
@@ -126,11 +132,11 @@
      * @param tree the content tree to which the parameter information will be added.
      */
     protected void addParam(ExecutableMemberDoc member, Parameter param,
-        boolean isVarArg, Content tree) {
+            boolean isVarArg, Content tree) {
         if (param.type() != null) {
-            Content link = new RawHtml(writer.getLink(new LinkInfoImpl(
-                    configuration, LinkInfoImpl.CONTEXT_EXECUTABLE_MEMBER_PARAM,
-                    param.type(), isVarArg)));
+            Content link = writer.getLink(new LinkInfoImpl(
+                    configuration, LinkInfoImpl.Kind.EXECUTABLE_MEMBER_PARAM,
+                    param.type()).varargs(isVarArg));
             tree.addContent(link);
         }
         if(param.name().length() > 0) {
@@ -153,8 +159,8 @@
         tree.addContent(writer.getSpace());
         tree.addContent(rcvrType.typeName());
         LinkInfoImpl linkInfo = new LinkInfoImpl(configuration,
-                LinkInfoImpl.CONTEXT_CLASS_SIGNATURE, rcvrType);
-        tree.addContent(new RawHtml(writer.getTypeParameterLinks(linkInfo)));
+                LinkInfoImpl.Kind.CLASS_SIGNATURE, rcvrType);
+        tree.addContent(writer.getTypeParameterLinks(linkInfo));
         tree.addContent(writer.getSpace());
         tree.addContent("this");
     }
@@ -166,8 +172,8 @@
      * @param member the member to write parameters for.
      * @param htmltree the content tree to which the parameters information will be added.
      */
-    protected void addParameters(ExecutableMemberDoc member, Content htmltree) {
-        addParameters(member, true, htmltree);
+    protected void addParameters(ExecutableMemberDoc member, Content htmltree, int indentSize) {
+        addParameters(member, true, htmltree, indentSize);
     }
 
     /**
@@ -178,15 +184,11 @@
      * @param htmltree the content tree to which the parameters information will be added.
      */
     protected void addParameters(ExecutableMemberDoc member,
-            boolean includeAnnotations, Content htmltree) {
+            boolean includeAnnotations, Content htmltree, int indentSize) {
         htmltree.addContent("(");
         String sep = "";
         Parameter[] params = member.parameters();
-        String indent = makeSpace(writer.displayLength);
-        if (configuration.linksource) {
-            //add spaces to offset indentation changes caused by link.
-            indent+= makeSpace(member.name().length());
-        }
+        String indent = makeSpace(indentSize + 1);
         Type rcvrType = member.receiverType();
         if (includeAnnotations && rcvrType instanceof AnnotatedType) {
             AnnotationDesc[] descList = rcvrType.asAnnotatedType().annotations();
@@ -240,53 +242,30 @@
      * @param member the member to write exceptions for.
      * @param htmltree the content tree to which the exceptions information will be added.
      */
-    protected void addExceptions(ExecutableMemberDoc member, Content htmltree) {
+    protected void addExceptions(ExecutableMemberDoc member, Content htmltree, int indentSize) {
         Type[] exceptions = member.thrownExceptionTypes();
-        if(exceptions.length > 0) {
+        if (exceptions.length > 0) {
             LinkInfoImpl memberTypeParam = new LinkInfoImpl(configuration,
-                    LinkInfoImpl.CONTEXT_MEMBER, member, false);
-            int retlen = getReturnTypeLength(member);
-            writer.getTypeParameterLinks(memberTypeParam);
-            retlen += memberTypeParam.displayLength == 0 ?
-                0 : memberTypeParam.displayLength + 1;
-            String indent = makeSpace(modifierString(member).length() +
-                    member.name().length() + retlen - 4);
+                    LinkInfoImpl.Kind.MEMBER, member);
+            String indent = makeSpace(indentSize + 1 - 7);
             htmltree.addContent(DocletConstants.NL);
             htmltree.addContent(indent);
             htmltree.addContent("throws ");
-            indent += "       ";
-            Content link = new RawHtml(writer.getLink(new LinkInfoImpl(configuration,
-                    LinkInfoImpl.CONTEXT_MEMBER, exceptions[0])));
+            indent = makeSpace(indentSize + 1);
+            Content link = writer.getLink(new LinkInfoImpl(configuration,
+                    LinkInfoImpl.Kind.MEMBER, exceptions[0]));
             htmltree.addContent(link);
             for(int i = 1; i < exceptions.length; i++) {
                 htmltree.addContent(",");
                 htmltree.addContent(DocletConstants.NL);
                 htmltree.addContent(indent);
-                Content exceptionLink = new RawHtml(writer.getLink(new LinkInfoImpl(
-                        configuration, LinkInfoImpl.CONTEXT_MEMBER, exceptions[i])));
+                Content exceptionLink = writer.getLink(new LinkInfoImpl(
+                        configuration, LinkInfoImpl.Kind.MEMBER, exceptions[i]));
                 htmltree.addContent(exceptionLink);
             }
         }
     }
 
-    protected int getReturnTypeLength(ExecutableMemberDoc member) {
-        if (member instanceof MethodDoc) {
-            MethodDoc method = (MethodDoc)member;
-            Type rettype = method.returnType();
-            if (rettype.isPrimitive()) {
-                return rettype.typeName().length() +
-                       rettype.dimension().length();
-            } else {
-                LinkInfoImpl linkInfo = new LinkInfoImpl(configuration,
-                    LinkInfoImpl.CONTEXT_MEMBER, rettype);
-                writer.getLink(linkInfo);
-                return linkInfo.displayLength;
-            }
-        } else {   // it's a constructordoc
-            return -1;
-        }
-    }
-
     protected ClassDoc implementsMethodInIntfac(MethodDoc method,
                                                 ClassDoc[] intfacs) {
         for (int i = 0; i < intfacs.length; i++) {
--- a/src/share/classes/com/sun/tools/doclets/formats/html/AbstractIndexWriter.java	Thu May 16 12:16:07 2013 -0700
+++ b/src/share/classes/com/sun/tools/doclets/formats/html/AbstractIndexWriter.java	Fri May 17 10:13:34 2013 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 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
@@ -139,9 +139,8 @@
      * @param dlTree the content tree to which the description will be added
      */
     protected void addDescription(ClassDoc cd, Content dlTree) {
-        Content link = new RawHtml(
-                getLink(new LinkInfoImpl(configuration,
-                        LinkInfoImpl.CONTEXT_INDEX, cd, true)));
+        Content link = getLink(new LinkInfoImpl(configuration,
+                        LinkInfoImpl.Kind.INDEX, cd).strong(true));
         Content dt = HtmlTree.DT(link);
         dt.addContent(" - ");
         addClassInfo(cd, dt);
@@ -152,7 +151,7 @@
     }
 
     /**
-     * Add the classkind(class, interface, exception, error of the class
+     * Add the classkind (class, interface, exception), error of the class
      * passed.
      *
      * @param cd the class being documented
@@ -161,8 +160,9 @@
     protected void addClassInfo(ClassDoc cd, Content contentTree) {
         contentTree.addContent(getResource("doclet.in",
                 Util.getTypeName(configuration, cd, false),
-                getPackageLinkString(cd.containingPackage(),
-                Util.getPackageName(cd.containingPackage()), false)));
+                getPackageLink(cd.containingPackage(),
+                    Util.getPackageName(cd.containingPackage()))
+                ));
     }
 
     /**
@@ -175,11 +175,8 @@
         String name = (member instanceof ExecutableMemberDoc)?
             member.name() + ((ExecutableMemberDoc)member).flatSignature() :
             member.name();
-        if (name.indexOf("<") != -1 || name.indexOf(">") != -1) {
-                name = Util.escapeHtmlChars(name);
-        }
         Content span = HtmlTree.SPAN(HtmlStyle.strong,
-                getDocLink(LinkInfoImpl.CONTEXT_INDEX, member, name));
+                getDocLink(LinkInfoImpl.Kind.INDEX, member, name));
         Content dt = HtmlTree.DT(span);
         dt.addContent(" - ");
         addMemberDesc(member, dt);
@@ -253,7 +250,7 @@
                         getResource("doclet.Method_in", classdesc));
             }
         }
-        addPreQualifiedClassLink(LinkInfoImpl.CONTEXT_INDEX, containing,
+        addPreQualifiedClassLink(LinkInfoImpl.Kind.INDEX, containing,
                 false, contentTree);
     }
 }
--- a/src/share/classes/com/sun/tools/doclets/formats/html/AbstractMemberWriter.java	Thu May 16 12:16:07 2013 -0700
+++ b/src/share/classes/com/sun/tools/doclets/formats/html/AbstractMemberWriter.java	Fri May 17 10:13:34 2013 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 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
@@ -91,7 +91,7 @@
      *
      * @return a string for the table caption
      */
-    public abstract String getCaption();
+    public abstract Content getCaption();
 
     /**
      * Get the summary table header for the member.
@@ -143,7 +143,7 @@
      */
     protected void addSummaryLink(ClassDoc cd, ProgramElementDoc member,
             Content tdSummary) {
-        addSummaryLink(LinkInfoImpl.CONTEXT_MEMBER, cd, member, tdSummary);
+        addSummaryLink(LinkInfoImpl.Kind.MEMBER, cd, member, tdSummary);
     }
 
     /**
@@ -154,7 +154,7 @@
      * @param member the member to be documented
      * @param tdSummary the content tree to which the summary link will be added
      */
-    protected abstract void addSummaryLink(int context,
+    protected abstract void addSummaryLink(LinkInfoImpl.Kind context,
             ClassDoc cd, ProgramElementDoc member, Content tdSummary);
 
     /**
@@ -193,14 +193,13 @@
     protected abstract void addNavDetailLink(boolean link, Content liNav);
 
     /**
-     * Add the member name to the content tree and modifies the display length.
+     * Add the member name to the content tree.
      *
      * @param name the member name to be added to the content tree.
      * @param htmltree the content tree to which the name will be added.
      */
     protected void addName(String name, Content htmltree) {
         htmltree.addContent(name);
-        writer.displayLength += name.length();
     }
 
     /**
@@ -259,7 +258,7 @@
             return "";
         }
         StringBuilder sb = new StringBuilder(len);
-        for(int i = 0; i < len; i++) {
+        for (int i = 0; i < len; i++) {
             sb.append(' ');
     }
         return sb.toString();
@@ -286,19 +285,22 @@
         } else {
             if (member instanceof ExecutableMemberDoc &&
                     ((ExecutableMemberDoc) member).typeParameters().length > 0) {
+                Content typeParameters = ((AbstractExecutableMemberWriter) this).getTypeParameters(
+                        (ExecutableMemberDoc) member);
+                    code.addContent(typeParameters);
                 //Code to avoid ugly wrapping in member summary table.
-                int displayLength = ((AbstractExecutableMemberWriter) this).addTypeParameters(
-                        (ExecutableMemberDoc) member, code);
-                if (displayLength > 10) {
+                if (typeParameters.charCount() > 10) {
                     code.addContent(new HtmlTree(HtmlTag.BR));
+                } else {
+                    code.addContent(writer.getSpace());
                 }
-                code.addContent(new RawHtml(
+                code.addContent(
                         writer.getLink(new LinkInfoImpl(configuration,
-                        LinkInfoImpl.CONTEXT_SUMMARY_RETURN_TYPE, type))));
+                        LinkInfoImpl.Kind.SUMMARY_RETURN_TYPE, type)));
             } else {
-                code.addContent(new RawHtml(
+                code.addContent(
                         writer.getLink(new LinkInfoImpl(configuration,
-                        LinkInfoImpl.CONTEXT_SUMMARY_RETURN_TYPE, type))));
+                        LinkInfoImpl.Kind.SUMMARY_RETURN_TYPE, type)));
             }
 
         }
@@ -346,10 +348,10 @@
      * @param contentTree the content tree to which the deprecated information will be added.
      */
     protected void addDeprecatedInfo(ProgramElementDoc member, Content contentTree) {
-        String output = (new DeprecatedTaglet()).getTagletOutput(member,
-            writer.getTagletWriterInstance(false)).toString().trim();
+        Content output = (new DeprecatedTaglet()).getTagletOutput(member,
+            writer.getTagletWriterInstance(false));
         if (!output.isEmpty()) {
-            Content deprecatedContent = new RawHtml(output);
+            Content deprecatedContent = output;
             Content div = HtmlTree.DIV(HtmlStyle.block, deprecatedContent);
             contentTree.addContent(div);
         }
@@ -378,7 +380,7 @@
      * @return a header content for the section.
      */
     protected Content getHead(MemberDoc member) {
-        Content memberContent = new RawHtml(member.name());
+        Content memberContent = new StringContent(member.name());
         Content heading = HtmlTree.HEADING(HtmlConstants.MEMBER_HEADING, memberContent);
         return heading;
     }
@@ -412,7 +414,7 @@
             String tableSummary, String[] tableHeader, Content contentTree) {
         if (deprmembers.size() > 0) {
             Content table = HtmlTree.TABLE(0, 3, 0, tableSummary,
-                writer.getTableCaption(configuration.getText(headingKey)));
+                writer.getTableCaption(configuration.getResource(headingKey)));
             table.addContent(writer.getSummaryTableHeader(tableHeader, "col"));
             Content tbody = new HtmlTree(HtmlTag.TBODY);
             for (int i = 0; i < deprmembers.size(); i++) {
@@ -444,7 +446,7 @@
      * @param contentTree the content tree to which the use information will be added
      */
     protected void addUseInfo(List<? extends ProgramElementDoc> mems,
-            String heading, String tableSummary, Content contentTree) {
+            Content heading, String tableSummary, Content contentTree) {
         if (mems == null) {
             return;
         }
@@ -483,7 +485,7 @@
                     tdLast.addContent(name);
                 }
                 addSummaryLink(pgmdoc instanceof ClassDoc ?
-                    LinkInfoImpl.CONTEXT_CLASS_USE : LinkInfoImpl.CONTEXT_MEMBER,
+                    LinkInfoImpl.Kind.CLASS_USE : LinkInfoImpl.Kind.MEMBER,
                     cd, pgmdoc, tdLast);
                 writer.addSummaryLinkComment(this, pgmdoc, tdLast);
                 tr.addContent(tdLast);
--- a/src/share/classes/com/sun/tools/doclets/formats/html/AbstractPackageIndexWriter.java	Thu May 16 12:16:07 2013 -0700
+++ b/src/share/classes/com/sun/tools/doclets/formats/html/AbstractPackageIndexWriter.java	Fri May 17 10:13:34 2013 -0700
@@ -158,10 +158,10 @@
             }
             body.addContent(div);
             if (configuration.showProfiles) {
-                String profileSummary = configuration.getText("doclet.Profiles");
-                String profilesTableSummary = configuration.getText("doclet.Member_Table_Summary",
-                configuration.getText("doclet.Profile_Summary"),
-                configuration.getText("doclet.profiles"));
+                Content profileSummary = configuration.getResource("doclet.Profiles");
+                Content profilesTableSummary = configuration.getResource("doclet.Member_Table_Summary",
+                        configuration.getResource("doclet.Profile_Summary"),
+                        configuration.getResource("doclet.profiles"));
                 addProfilesList(profileSummary, profilesTableSummary, body);
             }
             addPackagesList(packages, text, tableSummary, body);
@@ -217,7 +217,7 @@
      * @param profilesTableSummary the profiles table summary information
      * @param body the content tree to which the profiles list will be added
      */
-    protected void addProfilesList(String profileSummary, String profilesTableSummary,
+    protected void addProfilesList(Content profileSummary, Content profilesTableSummary,
             Content body) {
     }
 }
--- a/src/share/classes/com/sun/tools/doclets/formats/html/AbstractTreeWriter.java	Thu May 16 12:16:07 2013 -0700
+++ b/src/share/classes/com/sun/tools/doclets/formats/html/AbstractTreeWriter.java	Fri May 17 10:13:34 2013 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 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
@@ -152,7 +152,7 @@
                     } else {
                         contentTree.addContent(", ");
                     }
-                    addPreQualifiedClassLink(LinkInfoImpl.CONTEXT_TREE,
+                    addPreQualifiedClassLink(LinkInfoImpl.Kind.TREE,
                             interfaces[i], contentTree);
                     counter++;
                 }
@@ -170,7 +170,7 @@
      * @param contentTree the content tree to which the information will be added
      */
     protected void addPartialInfo(ClassDoc cd, Content contentTree) {
-        addPreQualifiedStrongClassLink(LinkInfoImpl.CONTEXT_TREE, cd, contentTree);
+        addPreQualifiedStrongClassLink(LinkInfoImpl.Kind.TREE, cd, contentTree);
     }
 
     /**
--- a/src/share/classes/com/sun/tools/doclets/formats/html/AllClassesFrameWriter.java	Thu May 16 12:16:07 2013 -0700
+++ b/src/share/classes/com/sun/tools/doclets/formats/html/AllClassesFrameWriter.java	Fri May 17 10:13:34 2013 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 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
@@ -156,14 +156,13 @@
             if (!Util.isCoreClass(cd)) {
                 continue;
             }
-            String label = italicsClassName(cd, false);
+            Content label = italicsClassName(cd, false);
             Content linkContent;
-            if(wantFrames){
-                linkContent = new RawHtml(getLink(new LinkInfoImpl(configuration,
-                        LinkInfoImpl.ALL_CLASSES_FRAME, cd, label, "classFrame")));
+            if (wantFrames) {
+                linkContent = getLink(new LinkInfoImpl(configuration,
+                        LinkInfoImpl.Kind.ALL_CLASSES_FRAME, cd).label(label).target("classFrame"));
             } else {
-                linkContent = new RawHtml(getLink(new LinkInfoImpl(
-                        configuration, cd, label)));
+                linkContent = getLink(new LinkInfoImpl(configuration, LinkInfoImpl.Kind.DEFAULT, cd).label(label));
             }
             Content li = HtmlTree.LI(linkContent);
             content.addContent(li);
--- a/src/share/classes/com/sun/tools/doclets/formats/html/AnnotationTypeOptionalMemberWriterImpl.java	Thu May 16 12:16:07 2013 -0700
+++ b/src/share/classes/com/sun/tools/doclets/formats/html/AnnotationTypeOptionalMemberWriterImpl.java	Fri May 17 10:13:34 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
@@ -111,8 +111,8 @@
     /**
      * {@inheritDoc}
      */
-    public String getCaption() {
-        return configuration.getText("doclet.Annotation_Type_Optional_Members");
+    public Content getCaption() {
+        return configuration.getResource("doclet.Annotation_Type_Optional_Members");
     }
 
     /**
--- a/src/share/classes/com/sun/tools/doclets/formats/html/AnnotationTypeRequiredMemberWriterImpl.java	Thu May 16 12:16:07 2013 -0700
+++ b/src/share/classes/com/sun/tools/doclets/formats/html/AnnotationTypeRequiredMemberWriterImpl.java	Fri May 17 10:13:34 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
@@ -105,9 +105,9 @@
         Content pre = new HtmlTree(HtmlTag.PRE);
         writer.addAnnotationInfo(member, pre);
         addModifiers(member, pre);
-        Content link = new RawHtml(
+        Content link =
                 writer.getLink(new LinkInfoImpl(configuration,
-                        LinkInfoImpl.CONTEXT_MEMBER, getType(member))));
+                        LinkInfoImpl.Kind.MEMBER, getType(member)));
         pre.addContent(link);
         pre.addContent(writer.getSpace());
         if (configuration.linksource) {
@@ -183,8 +183,8 @@
     /**
      * {@inheritDoc}
      */
-    public String getCaption() {
-        return configuration.getText("doclet.Annotation_Type_Required_Members");
+    public Content getCaption() {
+        return configuration.getResource("doclet.Annotation_Type_Required_Members");
     }
 
     /**
@@ -223,10 +223,10 @@
     /**
      * {@inheritDoc}
      */
-    protected void addSummaryLink(int context, ClassDoc cd, ProgramElementDoc member,
+    protected void addSummaryLink(LinkInfoImpl.Kind context, ClassDoc cd, ProgramElementDoc member,
             Content tdSummary) {
-        Content strong = HtmlTree.STRONG(new RawHtml(
-                writer.getDocLink(context, (MemberDoc) member, member.name(), false)));
+        Content strong = HtmlTree.STRONG(
+                writer.getDocLink(context, (MemberDoc) member, member.name(), false));
         Content code = HtmlTree.CODE(strong);
         tdSummary.addContent(code);
     }
@@ -251,7 +251,7 @@
      * {@inheritDoc}
      */
     protected Content getDeprecatedLink(ProgramElementDoc member) {
-        return writer.getDocLink(LinkInfoImpl.CONTEXT_MEMBER,
+        return writer.getDocLink(LinkInfoImpl.Kind.MEMBER,
                 (MemberDoc) member, ((MemberDoc)member).qualifiedName());
     }
 
--- a/src/share/classes/com/sun/tools/doclets/formats/html/AnnotationTypeWriterImpl.java	Thu May 16 12:16:07 2013 -0700
+++ b/src/share/classes/com/sun/tools/doclets/formats/html/AnnotationTypeWriterImpl.java	Fri May 17 10:13:34 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
@@ -116,9 +116,9 @@
     public Content getNavLinkPrevious() {
         Content li;
         if (prev != null) {
-            Content prevLink = new RawHtml(getLink(new LinkInfoImpl(configuration,
-                    LinkInfoImpl.CONTEXT_CLASS, prev.asClassDoc(), "",
-                    configuration.getText("doclet.Prev_Class"), true)));
+            Content prevLink = getLink(new LinkInfoImpl(configuration,
+                    LinkInfoImpl.Kind.CLASS, prev.asClassDoc())
+                    .label(configuration.getText("doclet.Prev_Class")).strong(true));
             li = HtmlTree.LI(prevLink);
         }
         else
@@ -134,9 +134,9 @@
     public Content getNavLinkNext() {
         Content li;
         if (next != null) {
-            Content nextLink = new RawHtml(getLink(new LinkInfoImpl(configuration,
-                    LinkInfoImpl.CONTEXT_CLASS, next.asClassDoc(), "",
-                    configuration.getText("doclet.Next_Class"), true)));
+            Content nextLink = getLink(new LinkInfoImpl(configuration,
+                    LinkInfoImpl.Kind.CLASS, next.asClassDoc())
+                    .label(configuration.getText("doclet.Next_Class")).strong(true));
             li = HtmlTree.LI(nextLink);
         }
         else
@@ -163,11 +163,11 @@
             div.addContent(pkgNameDiv);
         }
         LinkInfoImpl linkInfo = new LinkInfoImpl(configuration,
-                LinkInfoImpl.CONTEXT_CLASS_HEADER, annotationType, false);
+                LinkInfoImpl.Kind.CLASS_HEADER, annotationType);
         Content headerContent = new StringContent(header);
         Content heading = HtmlTree.HEADING(HtmlConstants.CLASS_PAGE_HEADING, true,
                 HtmlStyle.title, headerContent);
-        heading.addContent(new RawHtml(getTypeParameterLinks(linkInfo)));
+        heading.addContent(getTypeParameterLinks(linkInfo));
         div.addContent(heading);
         bodyTree.addContent(div);
         return bodyTree;
@@ -220,9 +220,9 @@
         addAnnotationInfo(annotationType, pre);
         pre.addContent(modifiers);
         LinkInfoImpl linkInfo = new LinkInfoImpl(configuration,
-                LinkInfoImpl.CONTEXT_CLASS_SIGNATURE, annotationType, false);
+                LinkInfoImpl.Kind.CLASS_SIGNATURE, annotationType);
         Content annotationName = new StringContent(annotationType.name());
-        Content parameterLinks = new RawHtml(getTypeParameterLinks(linkInfo));
+        Content parameterLinks = getTypeParameterLinks(linkInfo);
         if (configuration.linksource) {
             addSrcLink(annotationType, annotationName, pre);
             pre.addContent(parameterLinks);
--- a/src/share/classes/com/sun/tools/doclets/formats/html/ClassUseWriter.java	Thu May 16 12:16:07 2013 -0700
+++ b/src/share/classes/com/sun/tools/doclets/formats/html/ClassUseWriter.java	Fri May 17 10:13:34 2013 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 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
@@ -256,10 +256,10 @@
      */
     protected void addPackageList(Content contentTree) throws IOException {
         Content table = HtmlTree.TABLE(0, 3, 0, useTableSummary,
-                getTableCaption(configuration.getText(
+                getTableCaption(configuration.getResource(
                 "doclet.ClassUse_Packages.that.use.0",
-                getLink(new LinkInfoImpl(configuration, LinkInfoImpl.CONTEXT_CLASS_USE_HEADER, classdoc,
-                false)))));
+                getLink(new LinkInfoImpl(configuration, LinkInfoImpl.Kind.CLASS_USE_HEADER, classdoc
+                )))));
         table.addContent(getSummaryTableHeader(packageTableHeader, "col"));
         Content tbody = new HtmlTree(HtmlTag.TBODY);
         Iterator<PackageDoc> it = pkgSet.iterator();
@@ -291,10 +291,10 @@
             return;
         }
         Content table = HtmlTree.TABLE(0, 3, 0, useTableSummary,
-                getTableCaption(configuration.getText(
+                getTableCaption(configuration.getResource(
                 "doclet.ClassUse_PackageAnnotation",
                 getLink(new LinkInfoImpl(configuration,
-                        LinkInfoImpl.CONTEXT_CLASS_USE_HEADER, classdoc, false)))));
+                        LinkInfoImpl.Kind.CLASS_USE_HEADER, classdoc)))));
         table.addContent(getSummaryTableHeader(packageTableHeader, "col"));
         Content tbody = new HtmlTree(HtmlTag.TBODY);
         Iterator<PackageDoc> it = pkgToPackageAnnotations.iterator();
@@ -331,11 +331,10 @@
         for (Iterator<PackageDoc> it = pkgSet.iterator(); it.hasNext();) {
             PackageDoc pkg = it.next();
             Content li = HtmlTree.LI(HtmlStyle.blockList, getMarkerAnchor(pkg.name()));
-            Content link = new RawHtml(
-                    configuration.getText("doclet.ClassUse_Uses.of.0.in.1",
-                    getLink(new LinkInfoImpl(configuration, LinkInfoImpl.CONTEXT_CLASS_USE_HEADER,
-                    classdoc, false)),
-                    getPackageLinkString(pkg, Util.getPackageName(pkg), false)));
+            Content link = getResource("doclet.ClassUse_Uses.of.0.in.1",
+                    getLink(new LinkInfoImpl(configuration, LinkInfoImpl.Kind.CLASS_USE_HEADER,
+                    classdoc)),
+                    getPackageLink(pkg, Util.getPackageName(pkg)));
             Content heading = HtmlTree.HEADING(HtmlConstants.SUMMARY_HEADING, link);
             li.addContent(heading);
             addClassUse(pkg, li);
@@ -368,71 +367,71 @@
      * @param contentTree the content tree to which the class use information will be added
      */
     protected void addClassUse(PackageDoc pkg, Content contentTree) throws IOException {
-        String classLink = getLink(new LinkInfoImpl(configuration,
-            LinkInfoImpl.CONTEXT_CLASS_USE_HEADER, classdoc, false));
-        String pkgLink = getPackageLinkString(pkg, Util.getPackageName(pkg), false);
+        Content classLink = getLink(new LinkInfoImpl(configuration,
+            LinkInfoImpl.Kind.CLASS_USE_HEADER, classdoc));
+        Content pkgLink = getPackageLink(pkg, Util.getPackageName(pkg));
         classSubWriter.addUseInfo(pkgToClassAnnotations.get(pkg.name()),
-                configuration.getText("doclet.ClassUse_Annotation", classLink,
+                configuration.getResource("doclet.ClassUse_Annotation", classLink,
                 pkgLink), classUseTableSummary, contentTree);
         classSubWriter.addUseInfo(pkgToClassTypeParameter.get(pkg.name()),
-                configuration.getText("doclet.ClassUse_TypeParameter", classLink,
+                configuration.getResource("doclet.ClassUse_TypeParameter", classLink,
                 pkgLink), classUseTableSummary, contentTree);
         classSubWriter.addUseInfo(pkgToSubclass.get(pkg.name()),
-                configuration.getText("doclet.ClassUse_Subclass", classLink,
+                configuration.getResource("doclet.ClassUse_Subclass", classLink,
                 pkgLink), subclassUseTableSummary, contentTree);
         classSubWriter.addUseInfo(pkgToSubinterface.get(pkg.name()),
-                configuration.getText("doclet.ClassUse_Subinterface", classLink,
+                configuration.getResource("doclet.ClassUse_Subinterface", classLink,
                 pkgLink), subinterfaceUseTableSummary, contentTree);
         classSubWriter.addUseInfo(pkgToImplementingClass.get(pkg.name()),
-                configuration.getText("doclet.ClassUse_ImplementingClass", classLink,
+                configuration.getResource("doclet.ClassUse_ImplementingClass", classLink,
                 pkgLink), classUseTableSummary, contentTree);
         fieldSubWriter.addUseInfo(pkgToField.get(pkg.name()),
-                configuration.getText("doclet.ClassUse_Field", classLink,
+                configuration.getResource("doclet.ClassUse_Field", classLink,
                 pkgLink), fieldUseTableSummary, contentTree);
         fieldSubWriter.addUseInfo(pkgToFieldAnnotations.get(pkg.name()),
-                configuration.getText("doclet.ClassUse_FieldAnnotations", classLink,
+                configuration.getResource("doclet.ClassUse_FieldAnnotations", classLink,
                 pkgLink), fieldUseTableSummary, contentTree);
         fieldSubWriter.addUseInfo(pkgToFieldTypeParameter.get(pkg.name()),
-                configuration.getText("doclet.ClassUse_FieldTypeParameter", classLink,
+                configuration.getResource("doclet.ClassUse_FieldTypeParameter", classLink,
                 pkgLink), fieldUseTableSummary, contentTree);
         methodSubWriter.addUseInfo(pkgToMethodAnnotations.get(pkg.name()),
-                configuration.getText("doclet.ClassUse_MethodAnnotations", classLink,
+                configuration.getResource("doclet.ClassUse_MethodAnnotations", classLink,
                 pkgLink), methodUseTableSummary, contentTree);
         methodSubWriter.addUseInfo(pkgToMethodParameterAnnotations.get(pkg.name()),
-                configuration.getText("doclet.ClassUse_MethodParameterAnnotations", classLink,
+                configuration.getResource("doclet.ClassUse_MethodParameterAnnotations", classLink,
                 pkgLink), methodUseTableSummary, contentTree);
         methodSubWriter.addUseInfo(pkgToMethodTypeParameter.get(pkg.name()),
-                configuration.getText("doclet.ClassUse_MethodTypeParameter", classLink,
+                configuration.getResource("doclet.ClassUse_MethodTypeParameter", classLink,
                 pkgLink), methodUseTableSummary, contentTree);
         methodSubWriter.addUseInfo(pkgToMethodReturn.get(pkg.name()),
-                configuration.getText("doclet.ClassUse_MethodReturn", classLink,
+                configuration.getResource("doclet.ClassUse_MethodReturn", classLink,
                 pkgLink), methodUseTableSummary, contentTree);
         methodSubWriter.addUseInfo(pkgToMethodReturnTypeParameter.get(pkg.name()),
-                configuration.getText("doclet.ClassUse_MethodReturnTypeParameter", classLink,
+                configuration.getResource("doclet.ClassUse_MethodReturnTypeParameter", classLink,
                 pkgLink), methodUseTableSummary, contentTree);
         methodSubWriter.addUseInfo(pkgToMethodArgs.get(pkg.name()),
-                configuration.getText("doclet.ClassUse_MethodArgs", classLink,
+                configuration.getResource("doclet.ClassUse_MethodArgs", classLink,
                 pkgLink), methodUseTableSummary, contentTree);
         methodSubWriter.addUseInfo(pkgToMethodArgTypeParameter.get(pkg.name()),
-                configuration.getText("doclet.ClassUse_MethodArgsTypeParameters", classLink,
+                configuration.getResource("doclet.ClassUse_MethodArgsTypeParameters", classLink,
                 pkgLink), methodUseTableSummary, contentTree);
         methodSubWriter.addUseInfo(pkgToMethodThrows.get(pkg.name()),
-                configuration.getText("doclet.ClassUse_MethodThrows", classLink,
+                configuration.getResource("doclet.ClassUse_MethodThrows", classLink,
                 pkgLink), methodUseTableSummary, contentTree);
         constrSubWriter.addUseInfo(pkgToConstructorAnnotations.get(pkg.name()),
-                configuration.getText("doclet.ClassUse_ConstructorAnnotations", classLink,
+                configuration.getResource("doclet.ClassUse_ConstructorAnnotations", classLink,
                 pkgLink), constructorUseTableSummary, contentTree);
         constrSubWriter.addUseInfo(pkgToConstructorParameterAnnotations.get(pkg.name()),
-                configuration.getText("doclet.ClassUse_ConstructorParameterAnnotations", classLink,
+                configuration.getResource("doclet.ClassUse_ConstructorParameterAnnotations", classLink,
                 pkgLink), constructorUseTableSummary, contentTree);
         constrSubWriter.addUseInfo(pkgToConstructorArgs.get(pkg.name()),
-                configuration.getText("doclet.ClassUse_ConstructorArgs", classLink,
+                configuration.getResource("doclet.ClassUse_ConstructorArgs", classLink,
                 pkgLink), constructorUseTableSummary, contentTree);
         constrSubWriter.addUseInfo(pkgToConstructorArgTypeParameter.get(pkg.name()),
-                configuration.getText("doclet.ClassUse_ConstructorArgsTypeParameters", classLink,
+                configuration.getResource("doclet.ClassUse_ConstructorArgsTypeParameters", classLink,
                 pkgLink), constructorUseTableSummary, contentTree);
         constrSubWriter.addUseInfo(pkgToConstructorThrows.get(pkg.name()),
-                configuration.getText("doclet.ClassUse_ConstructorThrows", classLink,
+                configuration.getResource("doclet.ClassUse_ConstructorThrows", classLink,
                 pkgLink), constructorUseTableSummary, contentTree);
     }
 
@@ -450,7 +449,10 @@
         Content bodyTree = getBody(true, getWindowTitle(title));
         addTop(bodyTree);
         addNavLinks(true, bodyTree);
-        Content headContent = getResource("doclet.ClassUse_Title", cltype, clname);
+        ContentBuilder headContent = new ContentBuilder();
+        headContent.addContent(getResource("doclet.ClassUse_Title", cltype));
+        headContent.addContent(new HtmlTree(HtmlTag.BR));
+        headContent.addContent(clname);
         Content heading = HtmlTree.HEADING(HtmlConstants.CLASS_PAGE_HEADING,
                 true, HtmlStyle.title, headContent);
         Content div = HtmlTree.DIV(HtmlStyle.header, heading);
@@ -476,9 +478,9 @@
      * @return a content tree for the class page link
      */
     protected Content getNavLinkClass() {
-        Content linkContent = new RawHtml(getLink(new LinkInfoImpl(
-                configuration, LinkInfoImpl.CONTEXT_CLASS_USE_HEADER, classdoc,
-                "", configuration.getText("doclet.Class"), false)));
+        Content linkContent = getLink(new LinkInfoImpl(
+                configuration, LinkInfoImpl.Kind.CLASS_USE_HEADER, classdoc)
+                .label(configuration.getText("doclet.Class")));
         Content li = HtmlTree.LI(linkContent);
         return li;
     }
--- a/src/share/classes/com/sun/tools/doclets/formats/html/ClassWriterImpl.java	Thu May 16 12:16:07 2013 -0700
+++ b/src/share/classes/com/sun/tools/doclets/formats/html/ClassWriterImpl.java	Fri May 17 10:13:34 2013 -0700
@@ -124,9 +124,9 @@
     public Content getNavLinkPrevious() {
         Content li;
         if (prev != null) {
-            Content prevLink = new RawHtml(getLink(new LinkInfoImpl(configuration,
-                    LinkInfoImpl.CONTEXT_CLASS, prev, "",
-                    configuration.getText("doclet.Prev_Class"), true)));
+            Content prevLink = getLink(new LinkInfoImpl(configuration,
+                    LinkInfoImpl.Kind.CLASS, prev)
+                    .label(configuration.getText("doclet.Prev_Class")).strong(true));
             li = HtmlTree.LI(prevLink);
         }
         else
@@ -142,9 +142,9 @@
     public Content getNavLinkNext() {
         Content li;
         if (next != null) {
-            Content nextLink = new RawHtml(getLink(new LinkInfoImpl(configuration,
-                    LinkInfoImpl.CONTEXT_CLASS, next, "",
-                    configuration.getText("doclet.Next_Class"), true)));
+            Content nextLink = getLink(new LinkInfoImpl(configuration,
+                    LinkInfoImpl.Kind.CLASS, next)
+                    .label(configuration.getText("doclet.Next_Class")).strong(true));
             li = HtmlTree.LI(nextLink);
         }
         else
@@ -185,13 +185,13 @@
             div.addContent(pkgNameDiv);
         }
         LinkInfoImpl linkInfo = new LinkInfoImpl(configuration,
-                LinkInfoImpl.CONTEXT_CLASS_HEADER, classDoc, false);
+                LinkInfoImpl.Kind.CLASS_HEADER, classDoc);
         //Let's not link to ourselves in the header.
         linkInfo.linkToSelf = false;
         Content headerContent = new StringContent(header);
         Content heading = HtmlTree.HEADING(HtmlConstants.CLASS_PAGE_HEADING, true,
                 HtmlStyle.title, headerContent);
-        heading.addContent(new RawHtml(getTypeParameterLinks(linkInfo)));
+        heading.addContent(getTypeParameterLinks(linkInfo));
         div.addContent(heading);
         bodyTree.addContent(div);
         return bodyTree;
@@ -245,11 +245,11 @@
         addAnnotationInfo(classDoc, pre);
         pre.addContent(modifiers);
         LinkInfoImpl linkInfo = new LinkInfoImpl(configuration,
-                LinkInfoImpl.CONTEXT_CLASS_SIGNATURE, classDoc, false);
+                LinkInfoImpl.Kind.CLASS_SIGNATURE, classDoc);
         //Let's not link to ourselves in the signature.
         linkInfo.linkToSelf = false;
         Content className = new StringContent(classDoc.name());
-        Content parameterLinks = new RawHtml(getTypeParameterLinks(linkInfo));
+        Content parameterLinks = getTypeParameterLinks(linkInfo);
         if (configuration.linksource) {
             addSrcLink(classDoc, className, pre);
             pre.addContent(parameterLinks);
@@ -264,9 +264,9 @@
             if (superclass != null) {
                 pre.addContent(DocletConstants.NL);
                 pre.addContent("extends ");
-                Content link = new RawHtml(getLink(new LinkInfoImpl(configuration,
-                        LinkInfoImpl.CONTEXT_CLASS_SIGNATURE_PARENT_NAME,
-                        superclass)));
+                Content link = getLink(new LinkInfoImpl(configuration,
+                        LinkInfoImpl.Kind.CLASS_SIGNATURE_PARENT_NAME,
+                        superclass));
                 pre.addContent(link);
             }
         }
@@ -285,9 +285,9 @@
                 } else {
                     pre.addContent(", ");
                 }
-                Content link = new RawHtml(getLink(new LinkInfoImpl(configuration,
-                        LinkInfoImpl.CONTEXT_CLASS_SIGNATURE_PARENT_NAME,
-                        implIntfacs[i])));
+                Content link = getLink(new LinkInfoImpl(configuration,
+                        LinkInfoImpl.Kind.CLASS_SIGNATURE_PARENT_NAME,
+                        implIntfacs[i]));
                 pre.addContent(link);
                 counter++;
             }
@@ -360,22 +360,21 @@
     private Content getTreeForClassHelper(Type type) {
         Content li = new HtmlTree(HtmlTag.LI);
         if (type.equals(classDoc)) {
-            String typeParameters = getTypeParameterLinks(
-                    new LinkInfoImpl(configuration, LinkInfoImpl.CONTEXT_TREE,
-                    classDoc, false));
+            Content typeParameters = getTypeParameterLinks(
+                    new LinkInfoImpl(configuration, LinkInfoImpl.Kind.TREE,
+                    classDoc));
             if (configuration.shouldExcludeQualifier(
                     classDoc.containingPackage().name())) {
                 li.addContent(type.asClassDoc().name());
-                li.addContent(new RawHtml(typeParameters));
+                li.addContent(typeParameters);
             } else {
                 li.addContent(type.asClassDoc().qualifiedName());
-                li.addContent(new RawHtml(typeParameters));
+                li.addContent(typeParameters);
             }
         } else {
-            Content link = new RawHtml(getLink(new LinkInfoImpl(configuration,
-                    LinkInfoImpl.CONTEXT_CLASS_TREE_PARENT,
-                    type instanceof ClassDoc ? (ClassDoc) type : type,
-                    configuration.getClassName(type.asClassDoc()), false)));
+            Content link = getLink(new LinkInfoImpl(configuration,
+                    LinkInfoImpl.Kind.CLASS_TREE_PARENT, type)
+                    .label(configuration.getClassName(type.asClassDoc())));
             li.addContent(link);
         }
         return li;
@@ -396,9 +395,8 @@
      */
     public void addTypeParamInfo(Content classInfoTree) {
         if (classDoc.typeParamTags().length > 0) {
-            TagletOutput output = (new ParamTaglet()).getTagletOutput(classDoc,
+            Content typeParam = (new ParamTaglet()).getTagletOutput(classDoc,
                     getTagletWriterInstance(false));
-            Content typeParam = new RawHtml(output.toString());
             Content dl = HtmlTree.DL(typeParam);
             classInfoTree.addContent(dl);
         }
@@ -419,7 +417,7 @@
                         "doclet.Subclasses");
                 Content dt = HtmlTree.DT(label);
                 Content dl = HtmlTree.DL(dt);
-                dl.addContent(getClassLinks(LinkInfoImpl.CONTEXT_SUBCLASSES,
+                dl.addContent(getClassLinks(LinkInfoImpl.Kind.SUBCLASSES,
                         subclasses));
                 classInfoTree.addContent(dl);
             }
@@ -437,7 +435,7 @@
                         "doclet.Subinterfaces");
                 Content dt = HtmlTree.DT(label);
                 Content dl = HtmlTree.DL(dt);
-                dl.addContent(getClassLinks(LinkInfoImpl.CONTEXT_SUBINTERFACES,
+                dl.addContent(getClassLinks(LinkInfoImpl.Kind.SUBINTERFACES,
                         subInterfaces));
                 classInfoTree.addContent(dl);
             }
@@ -461,7 +459,7 @@
                     "doclet.Implementing_Classes");
             Content dt = HtmlTree.DT(label);
             Content dl = HtmlTree.DL(dt);
-            dl.addContent(getClassLinks(LinkInfoImpl.CONTEXT_IMPLEMENTED_CLASSES,
+            dl.addContent(getClassLinks(LinkInfoImpl.Kind.IMPLEMENTED_CLASSES,
                     implcl));
             classInfoTree.addContent(dl);
         }
@@ -479,7 +477,7 @@
                     "doclet.All_Implemented_Interfaces");
             Content dt = HtmlTree.DT(label);
             Content dl = HtmlTree.DL(dt);
-            dl.addContent(getClassLinks(LinkInfoImpl.CONTEXT_IMPLEMENTED_INTERFACES,
+            dl.addContent(getClassLinks(LinkInfoImpl.Kind.IMPLEMENTED_INTERFACES,
                     interfaceArray));
             classInfoTree.addContent(dl);
         }
@@ -497,7 +495,7 @@
                     "doclet.All_Superinterfaces");
             Content dt = HtmlTree.DT(label);
             Content dl = HtmlTree.DL(dt);
-            dl.addContent(getClassLinks(LinkInfoImpl.CONTEXT_SUPER_INTERFACES,
+            dl.addContent(getClassLinks(LinkInfoImpl.Kind.SUPER_INTERFACES,
                     interfaceArray));
             classInfoTree.addContent(dl);
         }
@@ -520,8 +518,8 @@
             Content dt = HtmlTree.DT(label);
             Content dl = HtmlTree.DL(dt);
             Content dd = new HtmlTree(HtmlTag.DD);
-            dd.addContent(new RawHtml(getLink(new LinkInfoImpl(configuration,
-                    LinkInfoImpl.CONTEXT_CLASS, outerClass, false))));
+            dd.addContent(getLink(new LinkInfoImpl(configuration,
+                    LinkInfoImpl.Kind.CLASS, outerClass)));
             dl.addContent(dd);
             classInfoTree.addContent(dl);
         }
@@ -569,7 +567,7 @@
      * @param list the list of classes
      * @return a content tree for the class list
      */
-    private Content getClassLinks(int context, List<?> list) {
+    private Content getClassLinks(LinkInfoImpl.Kind context, List<?> list) {
         Object[] typeList = list.toArray();
         Content dd = new HtmlTree(HtmlTag.DD);
         for (int i = 0; i < list.size(); i++) {
@@ -578,12 +576,12 @@
                 dd.addContent(separator);
             }
             if (typeList[i] instanceof ClassDoc) {
-                Content link = new RawHtml(getLink(
-                        new LinkInfoImpl(configuration, context, (ClassDoc)(typeList[i]))));
+                Content link = getLink(
+                        new LinkInfoImpl(configuration, context, (ClassDoc)(typeList[i])));
                 dd.addContent(link);
             } else {
-                Content link = new RawHtml(getLink(
-                        new LinkInfoImpl(configuration, context, (Type)(typeList[i]))));
+                Content link = getLink(
+                        new LinkInfoImpl(configuration, context, (Type)(typeList[i])));
                 dd.addContent(link);
             }
         }
--- a/src/share/classes/com/sun/tools/doclets/formats/html/ConfigurationImpl.java	Thu May 16 12:16:07 2013 -0700
+++ b/src/share/classes/com/sun/tools/doclets/formats/html/ConfigurationImpl.java	Fri May 17 10:13:34 2013 -0700
@@ -31,6 +31,7 @@
 import javax.tools.JavaFileManager;
 
 import com.sun.javadoc.*;
+import com.sun.tools.doclets.formats.html.markup.ContentBuilder;
 import com.sun.tools.doclets.internal.toolkit.*;
 import com.sun.tools.doclets.internal.toolkit.util.*;
 import com.sun.tools.doclint.DocLint;
@@ -562,4 +563,9 @@
         }
         return true;
     }
+
+    @Override
+    public Content newContent() {
+        return new ContentBuilder();
+    }
 }
--- a/src/share/classes/com/sun/tools/doclets/formats/html/ConstantsSummaryWriterImpl.java	Thu May 16 12:16:07 2013 -0700
+++ b/src/share/classes/com/sun/tools/doclets/formats/html/ConstantsSummaryWriterImpl.java	Fri May 17 10:13:34 2013 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 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
@@ -184,13 +184,17 @@
      */
     public Content getConstantMembersHeader(ClassDoc cd) {
         //generate links backward only to public classes.
-        String classlink = (cd.isPublic() || cd.isProtected()) ?
+        Content classlink = (cd.isPublic() || cd.isProtected()) ?
             getLink(new LinkInfoImpl(configuration,
-                    LinkInfoImpl.CONTEXT_CONSTANT_SUMMARY, cd, false)) :
-            cd.qualifiedName();
+                    LinkInfoImpl.Kind.CONSTANT_SUMMARY, cd)) :
+            new StringContent(cd.qualifiedName());
         String name = cd.containingPackage().name();
         if (name.length() > 0) {
-            return getClassName(name + "." + classlink);
+            Content cb = new ContentBuilder();
+            cb.addContent(name);
+            cb.addContent(".");
+            cb.addContent(classlink);
+            return getClassName(cb);
         } else {
             return getClassName(classlink);
         }
@@ -202,7 +206,7 @@
      * @param classStr the class name to print.
      * @return the table caption and header
      */
-    protected Content getClassName(String classStr) {
+    protected Content getClassName(Content classStr) {
         Content table = HtmlTree.TABLE(0, 3, 0, constantsTableSummary,
                 getTableCaption(classStr));
         table.addContent(getSummaryTableHeader(constantsTableHeader, "col"));
@@ -260,8 +264,8 @@
             code.addContent(modifier);
             code.addContent(getSpace());
         }
-        Content type = new RawHtml(getLink(new LinkInfoImpl(configuration,
-                LinkInfoImpl.CONTEXT_CONSTANT_SUMMARY, member.type())));
+        Content type = getLink(new LinkInfoImpl(configuration,
+                LinkInfoImpl.Kind.CONSTANT_SUMMARY, member.type()));
         code.addContent(type);
         tdType.addContent(code);
         return tdType;
@@ -274,8 +278,8 @@
      * @return the name column of the constant table row
      */
     private Content getNameColumn(FieldDoc member) {
-        Content nameContent = new RawHtml(getDocLink(
-                LinkInfoImpl.CONTEXT_CONSTANT_SUMMARY, member, member.name(), false));
+        Content nameContent = getDocLink(
+                LinkInfoImpl.Kind.CONSTANT_SUMMARY, member, member.name(), false);
         Content code = HtmlTree.CODE(nameContent);
         return HtmlTree.TD(code);
     }
--- a/src/share/classes/com/sun/tools/doclets/formats/html/ConstructorWriterImpl.java	Thu May 16 12:16:07 2013 -0700
+++ b/src/share/classes/com/sun/tools/doclets/formats/html/ConstructorWriterImpl.java	Fri May 17 10:13:34 2013 -0700
@@ -126,7 +126,6 @@
      * {@inheritDoc}
      */
     public Content getSignature(ConstructorDoc constructor) {
-        writer.displayLength = 0;
         Content pre = new HtmlTree(HtmlTag.PRE);
         writer.addAnnotationInfo(constructor, pre);
         addModifiers(constructor, pre);
@@ -136,8 +135,9 @@
         } else {
             addName(constructor.name(), pre);
         }
-        addParameters(constructor, pre);
-        addExceptions(constructor, pre);
+        int indent = pre.charCount();
+        addParameters(constructor, pre, indent);
+        addExceptions(constructor, pre, indent);
         return pre;
     }
 
@@ -225,8 +225,8 @@
     /**
      * {@inheritDoc}
      */
-    public String getCaption() {
-        return configuration.getText("doclet.Constructors");
+    public Content getCaption() {
+        return configuration.getResource("doclet.Constructors");
     }
 
     /**
--- a/src/share/classes/com/sun/tools/doclets/formats/html/EnumConstantWriterImpl.java	Thu May 16 12:16:07 2013 -0700
+++ b/src/share/classes/com/sun/tools/doclets/formats/html/EnumConstantWriterImpl.java	Fri May 17 10:13:34 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
@@ -101,8 +101,8 @@
         Content pre = new HtmlTree(HtmlTag.PRE);
         writer.addAnnotationInfo(enumConstant, pre);
         addModifiers(enumConstant, pre);
-        Content enumConstantLink = new RawHtml(writer.getLink(new LinkInfoImpl(
-                configuration, LinkInfoImpl.CONTEXT_MEMBER, enumConstant.type())));
+        Content enumConstantLink = writer.getLink(new LinkInfoImpl(
+                configuration, LinkInfoImpl.Kind.MEMBER, enumConstant.type()));
         pre.addContent(enumConstantLink);
         pre.addContent(" ");
         if (configuration.linksource) {
@@ -182,8 +182,8 @@
     /**
      * {@inheritDoc}
      */
-    public String getCaption() {
-        return configuration.getText("doclet.Enum_Constants");
+    public Content getCaption() {
+        return configuration.getResource("doclet.Enum_Constants");
     }
 
     /**
@@ -220,10 +220,10 @@
     /**
      * {@inheritDoc}
      */
-    protected void addSummaryLink(int context, ClassDoc cd, ProgramElementDoc member,
+    protected void addSummaryLink(LinkInfoImpl.Kind context, ClassDoc cd, ProgramElementDoc member,
             Content tdSummary) {
-        Content strong = HtmlTree.STRONG(new RawHtml(
-                writer.getDocLink(context, (MemberDoc) member, member.name(), false)));
+        Content strong = HtmlTree.STRONG(
+                writer.getDocLink(context, (MemberDoc) member, member.name(), false));
         Content code = HtmlTree.CODE(strong);
         tdSummary.addContent(code);
     }
@@ -254,7 +254,7 @@
      * {@inheritDoc}
      */
     protected Content getDeprecatedLink(ProgramElementDoc member) {
-        return writer.getDocLink(LinkInfoImpl.CONTEXT_MEMBER,
+        return writer.getDocLink(LinkInfoImpl.Kind.MEMBER,
                 (MemberDoc) member, ((FieldDoc)member).qualifiedName());
     }
 
--- a/src/share/classes/com/sun/tools/doclets/formats/html/FieldWriterImpl.java	Thu May 16 12:16:07 2013 -0700
+++ b/src/share/classes/com/sun/tools/doclets/formats/html/FieldWriterImpl.java	Fri May 17 10:13:34 2013 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 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
@@ -102,8 +102,8 @@
         Content pre = new HtmlTree(HtmlTag.PRE);
         writer.addAnnotationInfo(field, pre);
         addModifiers(field, pre);
-        Content fieldlink = new RawHtml(writer.getLink(new LinkInfoImpl(
-                configuration, LinkInfoImpl.CONTEXT_MEMBER, field.type())));
+        Content fieldlink = writer.getLink(new LinkInfoImpl(
+                configuration, LinkInfoImpl.Kind.MEMBER, field.type()));
         pre.addContent(fieldlink);
         pre.addContent(" ");
         if (configuration.linksource) {
@@ -132,12 +132,12 @@
                     (! (holder.isPublic() || Util.isLinkable(holder, configuration)))) {
                 writer.addInlineComment(field, fieldDocTree);
             } else {
-                Content link = new RawHtml(
-                        writer.getDocLink(LinkInfoImpl.CONTEXT_FIELD_DOC_COPY,
+                Content link =
+                        writer.getDocLink(LinkInfoImpl.Kind.FIELD_DOC_COPY,
                         holder, field,
                         holder.isIncluded() ?
                             holder.typeName() : holder.qualifiedTypeName(),
-                            false));
+                            false);
                 Content codeLink = HtmlTree.CODE(link);
                 Content strong = HtmlTree.STRONG(holder.isClass()?
                    writer.descfrmClassLabel : writer.descfrmInterfaceLabel);
@@ -203,8 +203,8 @@
     /**
      * {@inheritDoc}
      */
-    public String getCaption() {
-        return configuration.getText("doclet.Fields");
+    public Content getCaption() {
+        return configuration.getResource("doclet.Fields");
     }
 
     /**
@@ -239,8 +239,8 @@
      * {@inheritDoc}
      */
     public void addInheritedSummaryLabel(ClassDoc cd, Content inheritedTree) {
-        Content classLink = new RawHtml(writer.getPreQualifiedClassLink(
-                LinkInfoImpl.CONTEXT_MEMBER, cd, false));
+        Content classLink = writer.getPreQualifiedClassLink(
+                LinkInfoImpl.Kind.MEMBER, cd, false);
         Content label = new StringContent(cd.isClass() ?
             configuration.getText("doclet.Fields_Inherited_From_Class") :
             configuration.getText("doclet.Fields_Inherited_From_Interface"));
@@ -254,10 +254,10 @@
     /**
      * {@inheritDoc}
      */
-    protected void addSummaryLink(int context, ClassDoc cd, ProgramElementDoc member,
+    protected void addSummaryLink(LinkInfoImpl.Kind context, ClassDoc cd, ProgramElementDoc member,
             Content tdSummary) {
-        Content strong = HtmlTree.STRONG(new RawHtml(
-                writer.getDocLink(context, cd , (MemberDoc) member, member.name(), false)));
+        Content strong = HtmlTree.STRONG(
+                writer.getDocLink(context, cd , (MemberDoc) member, member.name(), false));
         Content code = HtmlTree.CODE(strong);
         tdSummary.addContent(code);
     }
@@ -267,9 +267,9 @@
      */
     protected void addInheritedSummaryLink(ClassDoc cd,
             ProgramElementDoc member, Content linksTree) {
-        linksTree.addContent(new RawHtml(
-                writer.getDocLink(LinkInfoImpl.CONTEXT_MEMBER, cd, (MemberDoc)member,
-                member.name(), false)));
+        linksTree.addContent(
+                writer.getDocLink(LinkInfoImpl.Kind.MEMBER, cd, (MemberDoc)member,
+                member.name(), false));
     }
 
     /**
@@ -284,7 +284,7 @@
      * {@inheritDoc}
      */
     protected Content getDeprecatedLink(ProgramElementDoc member) {
-        return writer.getDocLink(LinkInfoImpl.CONTEXT_MEMBER,
+        return writer.getDocLink(LinkInfoImpl.Kind.MEMBER,
                 (MemberDoc) member, ((FieldDoc)member).qualifiedName());
     }
 
--- a/src/share/classes/com/sun/tools/doclets/formats/html/FrameOutputWriter.java	Thu May 16 12:16:07 2013 -0700
+++ b/src/share/classes/com/sun/tools/doclets/formats/html/FrameOutputWriter.java	Fri May 17 10:13:34 2013 -0700
@@ -121,7 +121,7 @@
                 getResource("doclet.Frame_Alert"));
         noframes.addContent(noframesHead);
         Content p = HtmlTree.P(getResource("doclet.Frame_Warning_Message",
-                getHyperLinkString(configuration.topFile,
+                getHyperLink(configuration.topFile,
                 configuration.getText("doclet.Non_Frame_Version"))));
         noframes.addContent(p);
         contentTree.addContent(noframes);
--- a/src/share/classes/com/sun/tools/doclets/formats/html/HelpWriter.java	Thu May 16 12:16:07 2013 -0700
+++ b/src/share/classes/com/sun/tools/doclets/formats/html/HelpWriter.java	Fri May 17 10:13:34 2013 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 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
@@ -113,7 +113,7 @@
                 getResource("doclet.Overview"));
             Content liOverview = HtmlTree.LI(HtmlStyle.blockList, overviewHeading);
             Content line3 = getResource("doclet.Help_line_3",
-                    getHyperLinkString(DocPaths.OVERVIEW_SUMMARY,
+                    getHyperLink(DocPaths.OVERVIEW_SUMMARY,
                     configuration.getText("doclet.Overview")));
             Content overviewPara = HtmlTree.P(line3);
             liOverview.addContent(overviewPara);
@@ -234,8 +234,9 @@
                     getResource("doclet.Help_line_16"));
             Content liTree = HtmlTree.LI(HtmlStyle.blockList, treeHead);
             Content line17 = getResource("doclet.Help_line_17_with_tree_link",
-                    getHyperLinkString(DocPaths.OVERVIEW_TREE,
-                    configuration.getText("doclet.Class_Hierarchy")));
+                    getHyperLink(DocPaths.OVERVIEW_TREE,
+                    configuration.getText("doclet.Class_Hierarchy")),
+                    HtmlTree.CODE(new StringContent("java.lang.Object")));
             Content treePara = HtmlTree.P(line17);
             liTree.addContent(treePara);
             HtmlTree tul = new HtmlTree(HtmlTag.UL);
@@ -252,19 +253,19 @@
                     getResource("doclet.Deprecated_API"));
             Content liDeprecated = HtmlTree.LI(HtmlStyle.blockList, dHead);
             Content line20 = getResource("doclet.Help_line_20_with_deprecated_api_link",
-                    getHyperLinkString(DocPaths.DEPRECATED_LIST,
+                    getHyperLink(DocPaths.DEPRECATED_LIST,
                     configuration.getText("doclet.Deprecated_API")));
             Content dPara = HtmlTree.P(line20);
             liDeprecated.addContent(dPara);
             ul.addContent(liDeprecated);
         }
         if (configuration.createindex) {
-            String indexlink;
+            Content indexlink;
             if (configuration.splitindex) {
-                indexlink = getHyperLinkString(DocPaths.INDEX_FILES.resolve(DocPaths.indexN(1)),
+                indexlink = getHyperLink(DocPaths.INDEX_FILES.resolve(DocPaths.indexN(1)),
                         configuration.getText("doclet.Index"));
             } else {
-                indexlink = getHyperLinkString(DocPaths.INDEX_ALL,
+                indexlink = getHyperLink(DocPaths.INDEX_ALL,
                         configuration.getText("doclet.Index"));
             }
             Content indexHead = HtmlTree.HEADING(HtmlConstants.CONTENT_HEADING,
@@ -293,7 +294,7 @@
                 getResource("doclet.All_Classes"));
         Content liAllClasses = HtmlTree.LI(HtmlStyle.blockList, allclassesHead);
         Content line27 = getResource("doclet.Help_line_27",
-                getHyperLinkString(DocPaths.ALLCLASSES_NOFRAME,
+                getHyperLink(DocPaths.ALLCLASSES_NOFRAME,
                 configuration.getText("doclet.All_Classes")));
         Content allclassesPara = HtmlTree.P(line27);
         liAllClasses.addContent(allclassesPara);
@@ -309,7 +310,7 @@
                 getResource("doclet.Constants_Summary"));
         Content liConst = HtmlTree.LI(HtmlStyle.blockList, constHead);
         Content line29 = getResource("doclet.Help_line_29",
-                getHyperLinkString(DocPaths.CONSTANT_VALUES,
+                getHyperLink(DocPaths.CONSTANT_VALUES,
                 configuration.getText("doclet.Constants_Summary")));
         Content constPara = HtmlTree.P(line29);
         liConst.addContent(constPara);
--- a/src/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java	Thu May 16 12:16:07 2013 -0700
+++ b/src/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java	Fri May 17 10:13:34 2013 -0700
@@ -75,11 +75,6 @@
     public final DocPath filename;
 
     /**
-     * The display length used for indentation while generating the class page.
-     */
-    public int displayLength = 0;
-
-    /**
      * The global configuration information for this run.
      */
     public final ConfigurationImpl configuration;
@@ -251,15 +246,11 @@
         if (doc instanceof MethodDoc) {
             addMethodInfo((MethodDoc) doc, dl);
         }
-        TagletOutputImpl output = new TagletOutputImpl("");
+        Content output = new ContentBuilder();
         TagletWriter.genTagOuput(configuration.tagletManager, doc,
-            configuration.tagletManager.getCustomTags(doc),
+            configuration.tagletManager.getCustomTaglets(doc),
                 getTagletWriterInstance(false), output);
-        String outputString = output.toString().trim();
-        if (!outputString.isEmpty()) {
-            Content resultString = new RawHtml(outputString);
-            dl.addContent(resultString);
-        }
+        dl.addContent(output);
         htmltree.addContent(dl);
     }
 
@@ -271,11 +262,11 @@
      * @return true if there are tags to be printed else return false.
      */
     protected boolean hasSerializationOverviewTags(FieldDoc field) {
-        TagletOutputImpl output = new TagletOutputImpl("");
+        Content output = new ContentBuilder();
         TagletWriter.genTagOuput(configuration.tagletManager, field,
-            configuration.tagletManager.getCustomTags(field),
+            configuration.tagletManager.getCustomTaglets(field),
                 getTagletWriterInstance(false), output);
-        return (!output.toString().trim().isEmpty());
+        return !output.isEmpty();
     }
 
     /**
@@ -359,7 +350,7 @@
             int profileValue) {
         if(classes.length > 0) {
             Arrays.sort(classes);
-            Content caption = getTableCaption(label);
+            Content caption = getTableCaption(new RawHtml(label));
             Content table = HtmlTree.TABLE(HtmlStyle.packageSummary, 0, 3, 0,
                     tableSummary, caption);
             table.addContent(getSummaryTableHeader(tableHeader, "col"));
@@ -372,9 +363,8 @@
                     !configuration.isGeneratedDoc(classes[i])) {
                     continue;
                 }
-                Content classContent = new RawHtml(getLink(new LinkInfoImpl(
-                        configuration, LinkInfoImpl.CONTEXT_PACKAGE, classes[i],
-                        false)));
+                Content classContent = getLink(new LinkInfoImpl(
+                        configuration, LinkInfoImpl.Kind.PACKAGE, classes[i]));
                 Content tdClass = HtmlTree.TD(HtmlStyle.colFirst, classContent);
                 HtmlTree tr = HtmlTree.TR(tdClass);
                 if (i%2 == 0)
@@ -879,8 +869,7 @@
      * @param rawText the caption for the table which could be raw Html
      * @return a content tree for the caption
      */
-    public Content getTableCaption(String rawText) {
-        Content title = new RawHtml(rawText);
+    public Content getTableCaption(Content title) {
         Content captionSpan = HtmlTree.SPAN(title);
         Content space = getSpace();
         Content tabSpan = HtmlTree.SPAN(HtmlStyle.tabEnd, space);
@@ -948,7 +937,7 @@
             String tableSummary, String[] tableHeader, Content contentTree) {
         if (deprPkgs.size() > 0) {
             Content table = HtmlTree.TABLE(0, 3, 0, tableSummary,
-                    getTableCaption(configuration.getText(headingKey)));
+                    getTableCaption(configuration.getResource(headingKey)));
             table.addContent(getSummaryTableHeader(tableHeader, "col"));
             Content tbody = new HtmlTree(HtmlTag.TBODY);
             for (int i = 0; i < deprPkgs.size(); i++) {
@@ -1001,46 +990,10 @@
      *
      * @param pkg the package to link to.
      * @param label the label for the link.
-     * @param isStrong true if the label should be strong.
-     * @return the link to the given package.
+     * @return a content tree for the package link.
      */
-    public String getPackageLinkString(PackageDoc pkg, String label,
-                                 boolean isStrong) {
-        return getPackageLinkString(pkg, label, isStrong, "");
-    }
-
-    /**
-     * Return the link to the given package.
-     *
-     * @param pkg the package to link to.
-     * @param label the label for the link.
-     * @param isStrong true if the label should be strong.
-     * @param style  the font of the package link label.
-     * @return the link to the given package.
-     */
-    public String getPackageLinkString(PackageDoc pkg, String label, boolean isStrong,
-            String style) {
-        boolean included = pkg != null && pkg.isIncluded();
-        if (! included) {
-            PackageDoc[] packages = configuration.packages;
-            for (int i = 0; i < packages.length; i++) {
-                if (packages[i].equals(pkg)) {
-                    included = true;
-                    break;
-                }
-            }
-        }
-        if (included || pkg == null) {
-            return getHyperLinkString(pathString(pkg, DocPaths.PACKAGE_SUMMARY),
-                                label, isStrong, style);
-        } else {
-            DocLink crossPkgLink = getCrossPackageLink(Util.getPackageName(pkg));
-            if (crossPkgLink != null) {
-                return getHyperLinkString(crossPkgLink, label, isStrong, style);
-            } else {
-                return label;
-            }
-        }
+    public Content getPackageLink(PackageDoc pkg, String label) {
+        return getPackageLink(pkg, new StringContent(label));
     }
 
     /**
@@ -1074,9 +1027,9 @@
         }
     }
 
-    public String italicsClassName(ClassDoc cd, boolean qual) {
-        String name = (qual)? cd.qualifiedName(): cd.name();
-        return (cd.isInterface())?  italicsText(name): name;
+    public Content italicsClassName(ClassDoc cd, boolean qual) {
+        Content name = new StringContent((qual)? cd.qualifiedName(): cd.name());
+        return (cd.isInterface())?  HtmlTree.I(name): name;
     }
 
     /**
@@ -1109,11 +1062,9 @@
      *
      * @return the link for the given class.
      */
-    public String getLink(LinkInfoImpl linkInfo) {
+    public Content getLink(LinkInfoImpl linkInfo) {
         LinkFactoryImpl factory = new LinkFactoryImpl(this);
-        String link = factory.getLinkOutput(linkInfo).toString();
-        displayLength += linkInfo.displayLength;
-        return link;
+        return factory.getLink(linkInfo);
     }
 
     /**
@@ -1122,9 +1073,9 @@
      * @param linkInfo the information about the link.
      * @return the type for the given class.
      */
-    public String getTypeParameterLinks(LinkInfoImpl linkInfo) {
+    public Content getTypeParameterLinks(LinkInfoImpl linkInfo) {
         LinkFactoryImpl factory = new LinkFactoryImpl(this);
-        return factory.getTypeParameterLinks(linkInfo, false).toString();
+        return factory.getTypeParameterLinks(linkInfo, false);
     }
 
     /*************************************************************
@@ -1141,8 +1092,8 @@
      * @param style the style of the link.
      * @param code true if the label should be code font.
      */
-    public String getCrossClassLink(String qualifiedClassName, String refMemName,
-                                    String label, boolean strong, String style,
+    public Content getCrossClassLink(String qualifiedClassName, String refMemName,
+                                    Content label, boolean strong, String style,
                                     boolean code) {
         String className = "";
         String packageName = qualifiedClassName == null ? "" : qualifiedClassName;
@@ -1150,7 +1101,9 @@
         while ((periodIndex = packageName.lastIndexOf('.')) != -1) {
             className = packageName.substring(periodIndex + 1, packageName.length()) +
                 (className.length() > 0 ? "." + className : "");
-            String defaultLabel = code ? codeText(className) : className;
+            Content defaultLabel = new StringContent(className);
+            if (code)
+                defaultLabel = HtmlTree.CODE(defaultLabel);
             packageName = packageName.substring(0, periodIndex);
             if (getCrossPackageLink(packageName) != null) {
                 //The package exists in external documentation, so link to the external
@@ -1160,10 +1113,8 @@
                 //have to assume that it does.
                 DocLink link = configuration.extern.getExternalLink(packageName, pathToRoot,
                                 className + ".html", refMemName);
-                return getHyperLinkString(link,
-                    (label == null) || label.length() == 0 ? defaultLabel : label,
-
-
+                return getHyperLink(link,
+                    (label == null) || label.isEmpty() ? defaultLabel : label,
                     strong, style,
                     configuration.getText("doclet.Href_Class_Or_Interface_Title", packageName),
                     "");
@@ -1191,9 +1142,9 @@
      * @param cd the class doc to link to
      * @return a content tree for the link
      */
-    public Content getQualifiedClassLink(int context, ClassDoc cd) {
-        return new RawHtml(getLink(new LinkInfoImpl(configuration, context, cd,
-                configuration.getClassName(cd), "")));
+    public Content getQualifiedClassLink(LinkInfoImpl.Kind context, ClassDoc cd) {
+        return getLink(new LinkInfoImpl(configuration, context, cd)
+                .label(configuration.getClassName(cd)));
     }
 
     /**
@@ -1203,7 +1154,7 @@
      * @param cd the class doc to link to
      * @param contentTree the content tree to which the link will be added
      */
-    public void addPreQualifiedClassLink(int context, ClassDoc cd, Content contentTree) {
+    public void addPreQualifiedClassLink(LinkInfoImpl.Kind context, ClassDoc cd, Content contentTree) {
         addPreQualifiedClassLink(context, cd, false, contentTree);
     }
 
@@ -1216,15 +1167,15 @@
      * @param isStrong true if the link should be strong.
      * @return the link with the package portion of the label in plain text.
      */
-    public String getPreQualifiedClassLink(int context,
+    public Content getPreQualifiedClassLink(LinkInfoImpl.Kind context,
             ClassDoc cd, boolean isStrong) {
-        String classlink = "";
+        ContentBuilder classlink = new ContentBuilder();
         PackageDoc pd = cd.containingPackage();
-        if(pd != null && ! configuration.shouldExcludeQualifier(pd.name())) {
-            classlink = getPkgName(cd);
+        if (pd != null && ! configuration.shouldExcludeQualifier(pd.name())) {
+            classlink.addContent(getPkgName(cd));
         }
-        classlink += getLink(new LinkInfoImpl(configuration,
-                context, cd, cd.name(), isStrong));
+        classlink.addContent(getLink(new LinkInfoImpl(configuration,
+                context, cd).label(cd.name()).strong(isStrong)));
         return classlink;
     }
 
@@ -1238,14 +1189,14 @@
      * @param isStrong true if the link should be strong
      * @param contentTree the content tree to which the link with be added
      */
-    public void addPreQualifiedClassLink(int context,
+    public void addPreQualifiedClassLink(LinkInfoImpl.Kind context,
             ClassDoc cd, boolean isStrong, Content contentTree) {
         PackageDoc pd = cd.containingPackage();
         if(pd != null && ! configuration.shouldExcludeQualifier(pd.name())) {
             contentTree.addContent(getPkgName(cd));
         }
-        contentTree.addContent(new RawHtml(getLink(new LinkInfoImpl(configuration,
-                context, cd, cd.name(), isStrong))));
+        contentTree.addContent(getLink(new LinkInfoImpl(configuration,
+                context, cd).label(cd.name()).strong(isStrong)));
     }
 
     /**
@@ -1256,7 +1207,7 @@
      * @param cd the class to link to
      * @param contentTree the content tree to which the link with be added
      */
-    public void addPreQualifiedStrongClassLink(int context, ClassDoc cd, Content contentTree) {
+    public void addPreQualifiedStrongClassLink(LinkInfoImpl.Kind context, ClassDoc cd, Content contentTree) {
         addPreQualifiedClassLink(context, cd, true, contentTree);
     }
 
@@ -1268,8 +1219,9 @@
      * @param label the label for the link
      * @return a content tree for the doc link
      */
-    public Content getDocLink(int context, MemberDoc doc, String label) {
-        return getDocLink(context, doc.containingClass(), doc, label);
+    public Content getDocLink(LinkInfoImpl.Kind context, MemberDoc doc, String label) {
+        return getDocLink(context, doc.containingClass(), doc,
+                new StringContent(label));
     }
 
     /**
@@ -1281,8 +1233,8 @@
      * @param strong true if the link should be strong.
      * @return the link for the given member.
      */
-    public String getDocLink(int context, MemberDoc doc, String label,
-                boolean strong) {
+    public Content getDocLink(LinkInfoImpl.Kind context, MemberDoc doc, String label,
+            boolean strong) {
         return getDocLink(context, doc.containingClass(), doc, label, strong);
     }
 
@@ -1298,8 +1250,12 @@
      * @param strong true if the link should be strong.
      * @return the link for the given member.
      */
-    public String getDocLink(int context, ClassDoc classDoc, MemberDoc doc,
-        String label, boolean strong) {
+    public Content getDocLink(LinkInfoImpl.Kind context, ClassDoc classDoc, MemberDoc doc,
+            String label, boolean strong) {
+        return getDocLink(context, classDoc, doc, label, strong, false);
+    }
+    public Content getDocLink(LinkInfoImpl.Kind context, ClassDoc classDoc, MemberDoc doc,
+            Content label, boolean strong) {
         return getDocLink(context, classDoc, doc, label, strong, false);
     }
 
@@ -1316,18 +1272,28 @@
      * @param isProperty true if the doc parameter is a JavaFX property.
      * @return the link for the given member.
      */
-    public String getDocLink(int context, ClassDoc classDoc, MemberDoc doc,
-        String label, boolean strong, boolean isProperty) {
+    public Content getDocLink(LinkInfoImpl.Kind context, ClassDoc classDoc, MemberDoc doc,
+            String label, boolean strong, boolean isProperty) {
+        return getDocLink(context, classDoc, doc, new StringContent(check(label)), strong, isProperty);
+    }
+
+    String check(String s) {
+        if (s.matches(".*[&<>].*"))throw new IllegalArgumentException(s);
+        return s;
+    }
+
+    public Content getDocLink(LinkInfoImpl.Kind context, ClassDoc classDoc, MemberDoc doc,
+            Content label, boolean strong, boolean isProperty) {
         if (! (doc.isIncluded() ||
             Util.isLinkable(classDoc, configuration))) {
             return label;
         } else if (doc instanceof ExecutableMemberDoc) {
             ExecutableMemberDoc emd = (ExecutableMemberDoc)doc;
-            return getLink(new LinkInfoImpl(configuration, context, classDoc,
-                getAnchor(emd, isProperty), label, strong));
+            return getLink(new LinkInfoImpl(configuration, context, classDoc)
+                .label(label).where(getAnchor(emd, isProperty)).strong(strong));
         } else if (doc instanceof MemberDoc) {
-            return getLink(new LinkInfoImpl(configuration, context, classDoc,
-                doc.name(), label, strong));
+            return getLink(new LinkInfoImpl(configuration, context, classDoc)
+                .label(label).where(doc.name()).strong(strong));
         } else {
             return label;
         }
@@ -1344,20 +1310,20 @@
      * @param label the label for the link
      * @return the link for the given member
      */
-    public Content getDocLink(int context, ClassDoc classDoc, MemberDoc doc,
-        String label) {
+    public Content getDocLink(LinkInfoImpl.Kind context, ClassDoc classDoc, MemberDoc doc,
+            Content label) {
         if (! (doc.isIncluded() ||
             Util.isLinkable(classDoc, configuration))) {
-            return new StringContent(label);
+            return label;
         } else if (doc instanceof ExecutableMemberDoc) {
-            ExecutableMemberDoc emd = (ExecutableMemberDoc)doc;
-            return new RawHtml(getLink(new LinkInfoImpl(configuration, context, classDoc,
-                getAnchor(emd), label, false)));
+            ExecutableMemberDoc emd = (ExecutableMemberDoc) doc;
+            return getLink(new LinkInfoImpl(configuration, context, classDoc)
+                .label(label).where(getAnchor(emd)));
         } else if (doc instanceof MemberDoc) {
-            return new RawHtml(getLink(new LinkInfoImpl(configuration, context, classDoc,
-                doc.name(), label, false)));
+            return getLink(new LinkInfoImpl(configuration, context, classDoc)
+                .label(label).where(doc.name()));
         } else {
-            return new StringContent(label);
+            return label;
         }
     }
 
@@ -1385,24 +1351,24 @@
         return emd.name() + signatureParsed.toString();
     }
 
-    public String seeTagToString(SeeTag see) {
+    public Content seeTagToContent(SeeTag see) {
         String tagName = see.name();
         if (! (tagName.startsWith("@link") || tagName.equals("@see"))) {
-            return "";
+            return new ContentBuilder();
         }
 
         String seetext = replaceDocRootDir(see.text());
 
         //Check if @see is an href or "string"
         if (seetext.startsWith("<") || seetext.startsWith("\"")) {
-            return seetext;
+            return new RawHtml(seetext);
         }
 
         boolean plain = tagName.equalsIgnoreCase("@linkplain");
-        String label = plainOrCodeText(plain, see.label());
+        Content label = plainOrCode(plain, new RawHtml(see.label()));
 
         //The text from the @see tag.  We will output this text when a label is not specified.
-        String text = plainOrCodeText(plain, seetext);
+        Content text = plainOrCode(plain, new RawHtml(seetext));
 
         ClassDoc refClass = see.referencedClass();
         String refClassName = see.referencedClassName();
@@ -1415,16 +1381,16 @@
             if (refPackage != null && refPackage.isIncluded()) {
                 //@see is referencing an included package
                 if (label.isEmpty())
-                    label = plainOrCodeText(plain, refPackage.name());
-                return getPackageLinkString(refPackage, label, false);
+                    label = plainOrCode(plain, new StringContent(refPackage.name()));
+                return getPackageLink(refPackage, label);
             } else {
                 //@see is not referencing an included class or package.  Check for cross links.
-                String classCrossLink;
+                Content classCrossLink;
                 DocLink packageCrossLink = getCrossPackageLink(refClassName);
                 if (packageCrossLink != null) {
                     //Package cross link found
-                    return getHyperLinkString(packageCrossLink,
-                        (label.isEmpty() ? text : label), false);
+                    return getHyperLink(packageCrossLink,
+                        (label.isEmpty() ? text : label));
                 } else if ((classCrossLink = getCrossClassLink(refClassName,
                         refMemName, label, false, "", !plain)) != null) {
                     //Class cross link found (possibly to a member in the class)
@@ -1439,9 +1405,10 @@
         } else if (refMemName == null) {
             // Must be a class reference since refClass is not null and refMemName is null.
             if (label.isEmpty()) {
-                label = plainOrCodeText(plain, refClass.name());
+                label = plainOrCode(plain, new StringContent(refClass.name()));
             }
-            return getLink(new LinkInfoImpl(configuration, refClass, label));
+            return getLink(new LinkInfoImpl(configuration, LinkInfoImpl.Kind.DEFAULT, refClass)
+                    .label(label));
         } else if (refMem == null) {
             // Must be a member reference since refClass is not null and refMemName is not null.
             // However, refMem is null, so this referenced member does not exist.
@@ -1478,15 +1445,15 @@
                 }
             }
 
-            text = plainOrCodeText(plain, Util.escapeHtmlChars(refMemName));
+            text = plainOrCode(plain, new StringContent(refMemName));
 
-            return getDocLink(LinkInfoImpl.CONTEXT_SEE_TAG, containing,
+            return getDocLink(LinkInfoImpl.Kind.SEE_TAG, containing,
                 refMem, (label.isEmpty() ? text: label), false);
         }
     }
 
-    private String plainOrCodeText(boolean plain, String text) {
-        return (plain || text.isEmpty()) ? text : codeText(text);
+    private Content plainOrCode(boolean plain, Content body) {
+        return (plain || body.isEmpty()) ? body : HtmlTree.CODE(body);
     }
 
     /**
@@ -1497,7 +1464,7 @@
      * @param htmltree the content tree to which the comment will be added
      */
     public void addInlineComment(Doc doc, Tag tag, Content htmltree) {
-        addCommentTags(doc, tag.inlineTags(), false, false, htmltree);
+        addCommentTags(doc, tag, tag.inlineTags(), false, false, htmltree);
     }
 
     /**
@@ -1557,11 +1524,26 @@
      */
     private void addCommentTags(Doc doc, Tag[] tags, boolean depr,
             boolean first, Content htmltree) {
+        addCommentTags(doc, null, tags, depr, first, htmltree);
+    }
+
+    /**
+     * Adds the comment tags.
+     *
+     * @param doc the doc for which the comment tags will be generated
+     * @param holderTag the block tag context for the inline tags
+     * @param tags the first sentence tags for the doc
+     * @param depr true if it is deprecated
+     * @param first true if the first sentence tags should be added
+     * @param htmltree the documentation tree to which the comment tags will be added
+     */
+    private void addCommentTags(Doc doc, Tag holderTag, Tag[] tags, boolean depr,
+            boolean first, Content htmltree) {
         if(configuration.nocomment){
             return;
         }
         Content div;
-        Content result = new RawHtml(commentTagsToString(null, doc, tags, first));
+        Content result = commentTagsToContent(null, doc, tags, first);
         if (depr) {
             Content italic = HtmlTree.I(result);
             div = HtmlTree.DIV(HtmlStyle.block, italic);
@@ -1588,9 +1570,9 @@
      *               present in the text of interest for this doc
      * @param isFirstSentence  true if text is first sentence
      */
-    public String commentTagsToString(Tag holderTag, Doc doc, Tag[] tags,
+    public Content commentTagsToContent(Tag holderTag, Doc doc, Tag[] tags,
             boolean isFirstSentence) {
-        StringBuilder result = new StringBuilder();
+        Content result = new ContentBuilder();
         boolean textTagChange = false;
         // Array of all possible inline tags for this javadoc run
         configuration.tagletManager.checkTags(doc, tags, true);
@@ -1598,14 +1580,15 @@
             Tag tagelem = tags[i];
             String tagName = tagelem.name();
             if (tagelem instanceof SeeTag) {
-                result.append(seeTagToString((SeeTag)tagelem));
+                result.addContent(seeTagToContent((SeeTag) tagelem));
             } else if (! tagName.equals("Text")) {
-                int originalLength = result.length();
-                TagletOutput output = TagletWriter.getInlineTagOuput(
+                boolean wasEmpty = result.isEmpty();
+                Content output = TagletWriter.getInlineTagOuput(
                     configuration.tagletManager, holderTag,
                     tagelem, getTagletWriterInstance(isFirstSentence));
-                result.append(output == null ? "" : output.toString());
-                if (originalLength == 0 && isFirstSentence && tagelem.name().equals("@inheritDoc") && result.length() > 0) {
+                if (output != null)
+                    result.addContent(output);
+                if (wasEmpty && isFirstSentence && tagelem.name().equals("@inheritDoc") && !result.isEmpty()) {
                     break;
                 } else if (configuration.docrootparent.length() > 0 &&
                         tagelem.name().equals("@docRoot") &&
@@ -1637,17 +1620,11 @@
                 if (isFirstSentence) {
                     text = removeNonInlineHtmlTags(text);
                 }
-                StringTokenizer lines = new StringTokenizer(text, "\r\n", true);
-                StringBuilder textBuff = new StringBuilder();
-                while (lines.hasMoreTokens()) {
-                    StringBuilder line = new StringBuilder(lines.nextToken());
-                    Util.replaceTabs(configuration, line);
-                    textBuff.append(line.toString());
-                }
-                result.append(textBuff);
+                text = Util.replaceTabs(configuration, text);
+                result.addContent(new RawHtml(text));
             }
         }
-        return result.toString();
+        return result;
     }
 
     /**
@@ -1749,60 +1726,55 @@
         return text;
     }
 
-    public String removeNonInlineHtmlTags(String text) {
-        if (text.indexOf('<') < 0) {
+    static final Set<String> blockTags = new HashSet<String>();
+    static {
+        for (HtmlTag t: HtmlTag.values()) {
+            if (t.blockType == HtmlTag.BlockType.BLOCK)
+                blockTags.add(t.value);
+        }
+    }
+
+    public static String removeNonInlineHtmlTags(String text) {
+        final int len = text.length();
+
+        int startPos = 0;                     // start of text to copy
+        int lessThanPos = text.indexOf('<');  // position of latest '<'
+        if (lessThanPos < 0) {
             return text;
         }
-        String noninlinetags[] = { "<ul>", "</ul>", "<ol>", "</ol>",
-                "<dl>", "</dl>", "<table>", "</table>",
-                "<tr>", "</tr>", "<td>", "</td>",
-                "<th>", "</th>", "<p>", "</p>",
-                "<li>", "</li>", "<dd>", "</dd>",
-                "<dir>", "</dir>", "<dt>", "</dt>",
-                "<h1>", "</h1>", "<h2>", "</h2>",
-                "<h3>", "</h3>", "<h4>", "</h4>",
-                "<h5>", "</h5>", "<h6>", "</h6>",
-                "<pre>", "</pre>", "<menu>", "</menu>",
-                "<listing>", "</listing>", "<hr>",
-                "<blockquote>", "</blockquote>",
-                "<center>", "</center>",
-                "<UL>", "</UL>", "<OL>", "</OL>",
-                "<DL>", "</DL>", "<TABLE>", "</TABLE>",
-                "<TR>", "</TR>", "<TD>", "</TD>",
-                "<TH>", "</TH>", "<P>", "</P>",
-                "<LI>", "</LI>", "<DD>", "</DD>",
-                "<DIR>", "</DIR>", "<DT>", "</DT>",
-                "<H1>", "</H1>", "<H2>", "</H2>",
-                "<H3>", "</H3>", "<H4>", "</H4>",
-                "<H5>", "</H5>", "<H6>", "</H6>",
-                "<PRE>", "</PRE>", "<MENU>", "</MENU>",
-                "<LISTING>", "</LISTING>", "<HR>",
-                "<BLOCKQUOTE>", "</BLOCKQUOTE>",
-                "<CENTER>", "</CENTER>"
-        };
-        for (int i = 0; i < noninlinetags.length; i++) {
-            text = replace(text, noninlinetags[i], "");
+
+        StringBuilder result = new StringBuilder();
+    main: while (lessThanPos != -1) {
+            int currPos = lessThanPos + 1;
+            if (currPos == len)
+                break;
+            char ch = text.charAt(currPos);
+            if (ch == '/') {
+                if (++currPos == len)
+                    break;
+                ch = text.charAt(currPos);
+            }
+            int tagPos = currPos;
+            while (isHtmlTagLetterOrDigit(ch)) {
+                if (++currPos == len)
+                    break main;
+                ch = text.charAt(currPos);
+            }
+            if (ch == '>' && blockTags.contains(text.substring(tagPos, currPos).toLowerCase())) {
+                result.append(text, startPos, lessThanPos);
+                startPos = currPos + 1;
+            }
+            lessThanPos = text.indexOf('<', currPos);
         }
-        return text;
+        result.append(text.substring(startPos));
+
+        return result.toString();
     }
 
-    public String replace(String text, String tobe, String by) {
-        while (true) {
-            int startindex = text.indexOf(tobe);
-            if (startindex < 0) {
-                return text;
-            }
-            int endindex = startindex + tobe.length();
-            StringBuilder replaced = new StringBuilder();
-            if (startindex > 0) {
-                replaced.append(text.substring(0, startindex));
-            }
-            replaced.append(by);
-            if (text.length() > endindex) {
-                replaced.append(text.substring(endindex));
-            }
-            text = replaced.toString();
-        }
+    private static boolean isHtmlTagLetterOrDigit(char ch) {
+        return ('a' <= ch && ch <= 'z') ||
+                ('A' <= ch && ch <= 'Z') ||
+                ('1' <= ch && ch <= '6');
     }
 
     /**
@@ -1906,7 +1878,7 @@
     }
 
     /**
-     * Adds the annotatation types for the given doc.
+     * Adds the annotation types for the given doc.
      *
      * @param indent the number of extra spaces to indent the annotations.
      * @param doc the doc to write annotations for.
@@ -1916,16 +1888,14 @@
      */
     private boolean addAnnotationInfo(int indent, Doc doc,
             AnnotationDesc[] descList, boolean lineBreak, Content htmltree) {
-        List<String> annotations = getAnnotations(indent, descList, lineBreak);
+        List<Content> annotations = getAnnotations(indent, descList, lineBreak);
         String sep ="";
-        if (annotations.size() == 0) {
+        if (annotations.isEmpty()) {
             return false;
         }
-        Content annotationContent;
-        for (Iterator<String> iter = annotations.iterator(); iter.hasNext();) {
+        for (Content annotation: annotations) {
             htmltree.addContent(sep);
-            annotationContent = new RawHtml(iter.next());
-            htmltree.addContent(annotationContent);
+            htmltree.addContent(annotation);
             sep = " ";
         }
         return true;
@@ -1941,7 +1911,7 @@
      * @return an array of strings representing the annotations being
      *         documented.
      */
-    private List<String> getAnnotations(int indent, AnnotationDesc[] descList, boolean linkBreak) {
+    private List<Content> getAnnotations(int indent, AnnotationDesc[] descList, boolean linkBreak) {
         return getAnnotations(indent, descList, linkBreak, true);
     }
 
@@ -1960,10 +1930,10 @@
      * @return an array of strings representing the annotations being
      *         documented.
      */
-    public List<String> getAnnotations(int indent, AnnotationDesc[] descList, boolean linkBreak,
+    public List<Content> getAnnotations(int indent, AnnotationDesc[] descList, boolean linkBreak,
             boolean isJava5DeclarationLocation) {
-        List<String> results = new ArrayList<String>();
-        StringBuilder annotation;
+        List<Content> results = new ArrayList<Content>();
+        ContentBuilder annotation;
         for (int i = 0; i < descList.length; i++) {
             AnnotationTypeDoc annotationDoc = descList[i].annotationType();
             // If an annotation is not documented, do not add it to the list. If
@@ -1980,10 +1950,10 @@
             if  (Util.isDeclarationAnnotation(annotationDoc, isJava5DeclarationLocation)) {
                 continue;
             }*/
-            annotation = new StringBuilder();
+            annotation = new ContentBuilder();
             isAnnotationDocumented = false;
             LinkInfoImpl linkInfo = new LinkInfoImpl(configuration,
-                LinkInfoImpl.CONTEXT_ANNOTATION, annotationDoc);
+                LinkInfoImpl.Kind.ANNOTATION, annotationDoc);
             AnnotationDesc.ElementValuePair[] pairs = descList[i].elementValues();
             // If the annotation is synthesized, do not print the container.
             if (descList[i].isSynthesized()) {
@@ -1999,8 +1969,8 @@
                     }
                     String sep = "";
                     for (AnnotationValue av : annotationTypeValues) {
-                        annotation.append(sep);
-                        annotation.append(annotationValueToString(av));
+                        annotation.addContent(sep);
+                        annotation.addContent(annotationValueToContent(av));
                         sep = " ";
                     }
                 }
@@ -2016,8 +1986,8 @@
                     annotationTypeValues.addAll(Arrays.asList(annotationArray));
                     String sep = "";
                     for (AnnotationValue av : annotationTypeValues) {
-                        annotation.append(sep);
-                        annotation.append(annotationValueToString(av));
+                        annotation.addContent(sep);
+                        annotation.addContent(annotationValueToContent(av));
                         sep = " ";
                     }
                 }
@@ -2032,8 +2002,8 @@
                 addAnnotations(annotationDoc, linkInfo, annotation, pairs,
                         indent, linkBreak);
             }
-            annotation.append(linkBreak ? DocletConstants.NL : "");
-            results.add(annotation.toString());
+            annotation.addContent(linkBreak ? DocletConstants.NL : "");
+            results.add(annotation);
         }
         return results;
     }
@@ -2049,26 +2019,26 @@
      * @param linkBreak if true, add new line between each member value
      */
     private void addAnnotations(AnnotationTypeDoc annotationDoc, LinkInfoImpl linkInfo,
-            StringBuilder annotation, AnnotationDesc.ElementValuePair[] pairs,
+            ContentBuilder annotation, AnnotationDesc.ElementValuePair[] pairs,
             int indent, boolean linkBreak) {
-        linkInfo.label = "@" + annotationDoc.name();
-        annotation.append(getLink(linkInfo));
+        linkInfo.label = new StringContent("@" + annotationDoc.name());
+        annotation.addContent(getLink(linkInfo));
         if (pairs.length > 0) {
-            annotation.append('(');
+            annotation.addContent("(");
             for (int j = 0; j < pairs.length; j++) {
                 if (j > 0) {
-                    annotation.append(",");
+                    annotation.addContent(",");
                     if (linkBreak) {
-                        annotation.append(DocletConstants.NL);
+                        annotation.addContent(DocletConstants.NL);
                         int spaces = annotationDoc.name().length() + 2;
                         for (int k = 0; k < (spaces + indent); k++) {
-                            annotation.append(' ');
+                            annotation.addContent(" ");
                         }
                     }
                 }
-                annotation.append(getDocLink(LinkInfoImpl.CONTEXT_ANNOTATION,
+                annotation.addContent(getDocLink(LinkInfoImpl.Kind.ANNOTATION,
                         pairs[j].element(), pairs[j].element().name(), false));
-                annotation.append('=');
+                annotation.addContent("=");
                 AnnotationValue annotationValue = pairs[j].value();
                 List<AnnotationValue> annotationTypeValues = new ArrayList<AnnotationValue>();
                 if (annotationValue.value() instanceof AnnotationValue[]) {
@@ -2078,17 +2048,17 @@
                 } else {
                     annotationTypeValues.add(annotationValue);
                 }
-                annotation.append(annotationTypeValues.size() == 1 ? "" : "{");
+                annotation.addContent(annotationTypeValues.size() == 1 ? "" : "{");
                 String sep = "";
                 for (AnnotationValue av : annotationTypeValues) {
-                    annotation.append(sep);
-                    annotation.append(annotationValueToString(av));
+                    annotation.addContent(sep);
+                    annotation.addContent(annotationValueToContent(av));
                     sep = ",";
                 }
-                annotation.append(annotationTypeValues.size() == 1 ? "" : "}");
+                annotation.addContent(annotationTypeValues.size() == 1 ? "" : "}");
                 isContainerDocumented = false;
             }
-            annotation.append(")");
+            annotation.addContent(")");
         }
     }
 
@@ -2123,34 +2093,34 @@
         return false;
     }
 
-    private String annotationValueToString(AnnotationValue annotationValue) {
+    private Content annotationValueToContent(AnnotationValue annotationValue) {
         if (annotationValue.value() instanceof Type) {
             Type type = (Type) annotationValue.value();
             if (type.asClassDoc() != null) {
                 LinkInfoImpl linkInfo = new LinkInfoImpl(configuration,
-                    LinkInfoImpl.CONTEXT_ANNOTATION, type);
-                    linkInfo.label = (type.asClassDoc().isIncluded() ?
-                        type.typeName() :
-                        type.qualifiedTypeName()) + type.dimension() + ".class";
+                    LinkInfoImpl.Kind.ANNOTATION, type);
+                linkInfo.label = new StringContent((type.asClassDoc().isIncluded() ?
+                    type.typeName() :
+                    type.qualifiedTypeName()) + type.dimension() + ".class");
                 return getLink(linkInfo);
             } else {
-                return type.typeName() + type.dimension() + ".class";
+                return new StringContent(type.typeName() + type.dimension() + ".class");
             }
         } else if (annotationValue.value() instanceof AnnotationDesc) {
-            List<String> list = getAnnotations(0,
+            List<Content> list = getAnnotations(0,
                 new AnnotationDesc[]{(AnnotationDesc) annotationValue.value()},
                     false);
-            StringBuilder buf = new StringBuilder();
-            for (String s: list) {
-                buf.append(s);
+            ContentBuilder buf = new ContentBuilder();
+            for (Content c: list) {
+                buf.addContent(c);
             }
-            return buf.toString();
+            return buf;
         } else if (annotationValue.value() instanceof MemberDoc) {
-            return getDocLink(LinkInfoImpl.CONTEXT_ANNOTATION,
+            return getDocLink(LinkInfoImpl.Kind.ANNOTATION,
                 (MemberDoc) annotationValue.value(),
                 ((MemberDoc) annotationValue.value()).name(), false);
          } else {
-            return annotationValue.toString();
+            return new StringContent(annotationValue.toString());
          }
     }
 
--- a/src/share/classes/com/sun/tools/doclets/formats/html/HtmlSerialFieldWriter.java	Thu May 16 12:16:07 2013 -0700
+++ b/src/share/classes/com/sun/tools/doclets/formats/html/HtmlSerialFieldWriter.java	Fri May 17 10:13:34 2013 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 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
@@ -46,7 +46,7 @@
  * @author Bhavesh Patel (Modified)
  */
 public class HtmlSerialFieldWriter extends FieldWriterImpl
-    implements SerializedFormWriter.SerialFieldWriter {
+        implements SerializedFormWriter.SerialFieldWriter {
     ProgramElementDoc[] members = null;
 
     private boolean printedOverallAnchor = false;
@@ -129,8 +129,8 @@
         if (fieldType == null) {
             pre.addContent(fieldTypeStr);
         } else {
-            Content fieldContent = new RawHtml(writer.getLink(new LinkInfoImpl(
-                    configuration, LinkInfoImpl.CONTEXT_SERIAL_MEMBER, fieldType)));
+            Content fieldContent = writer.getLink(new LinkInfoImpl(
+                    configuration, LinkInfoImpl.Kind.SERIAL_MEMBER, fieldType));
             pre.addContent(fieldContent);
         }
         pre.addContent(fieldDimensions + " ");
@@ -186,17 +186,13 @@
      * @param contentTree the tree to which the member tags info will be added
      */
     public void addMemberTags(FieldDoc field, Content contentTree) {
-        TagletOutputImpl output = new TagletOutputImpl("");
+        Content tagContent = new ContentBuilder();
         TagletWriter.genTagOuput(configuration.tagletManager, field,
-                configuration.tagletManager.getCustomTags(field),
-                writer.getTagletWriterInstance(false), output);
-        String outputString = output.toString().trim();
+                configuration.tagletManager.getCustomTaglets(field),
+                writer.getTagletWriterInstance(false), tagContent);
         Content dlTags = new HtmlTree(HtmlTag.DL);
-        if (!outputString.isEmpty()) {
-            Content tagContent = new RawHtml(outputString);
-            dlTags.addContent(tagContent);
-        }
-        contentTree.addContent(dlTags);
+        dlTags.addContent(tagContent);
+        contentTree.addContent(dlTags);  // TODO: what if empty?
     }
 
     /**
--- a/src/share/classes/com/sun/tools/doclets/formats/html/HtmlSerialMethodWriter.java	Thu May 16 12:16:07 2013 -0700
+++ b/src/share/classes/com/sun/tools/doclets/formats/html/HtmlSerialMethodWriter.java	Fri May 17 10:13:34 2013 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 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
@@ -146,19 +146,15 @@
      * @param methodsContentTree the tree to which the member tags info will be added
      */
     public void addMemberTags(MethodDoc member, Content methodsContentTree) {
-        TagletOutputImpl output = new TagletOutputImpl("");
+        Content tagContent = new ContentBuilder();
         TagletManager tagletManager =
             configuration.tagletManager;
         TagletWriter.genTagOuput(tagletManager, member,
-            tagletManager.getSerializedFormTags(),
-            writer.getTagletWriterInstance(false), output);
-        String outputString = output.toString().trim();
+            tagletManager.getSerializedFormTaglets(),
+            writer.getTagletWriterInstance(false), tagContent);
         Content dlTags = new HtmlTree(HtmlTag.DL);
-        if (!outputString.isEmpty()) {
-            Content tagContent = new RawHtml(outputString);
-            dlTags.addContent(tagContent);
-        }
-        methodsContentTree.addContent(dlTags);
+        dlTags.addContent(tagContent);
+        methodsContentTree.addContent(dlTags);  // TODO: what if empty?
         MethodDoc method = member;
         if (method.name().compareTo("writeExternal") == 0
                 && method.tags("serialData").length == 0) {
--- a/src/share/classes/com/sun/tools/doclets/formats/html/LinkFactoryImpl.java	Thu May 16 12:16:07 2013 -0700
+++ b/src/share/classes/com/sun/tools/doclets/formats/html/LinkFactoryImpl.java	Fri May 17 10:13:34 2013 -0700
@@ -28,6 +28,9 @@
 import java.util.List;
 
 import com.sun.javadoc.*;
+import com.sun.tools.doclets.formats.html.markup.ContentBuilder;
+import com.sun.tools.doclets.formats.html.markup.RawHtml;
+import com.sun.tools.doclets.formats.html.markup.StringContent;
 import com.sun.tools.doclets.internal.toolkit.*;
 import com.sun.tools.doclets.internal.toolkit.util.*;
 import com.sun.tools.doclets.internal.toolkit.util.links.*;
@@ -54,16 +57,16 @@
     /**
      * {@inheritDoc}
      */
-    protected LinkOutput getOutputInstance() {
-        return new LinkOutputImpl();
+    protected Content newContent() {
+        return new ContentBuilder();
     }
 
     /**
      * {@inheritDoc}
      */
-    protected LinkOutput getClassLink(LinkInfo linkInfo) {
+    protected Content getClassLink(LinkInfo linkInfo) {
         LinkInfoImpl classLinkInfo = (LinkInfoImpl) linkInfo;
-        boolean noLabel = linkInfo.label == null || linkInfo.label.length() == 0;
+        boolean noLabel = linkInfo.label == null || linkInfo.label.isEmpty();
         ClassDoc classDoc = classLinkInfo.classDoc;
         //Create a tool tip if we are linking to a class or interface.  Don't
         //create one if we are linking to a member.
@@ -73,100 +76,94 @@
                     classLinkInfo.type != null &&
                     !classDoc.qualifiedTypeName().equals(classLinkInfo.type.qualifiedTypeName())) :
             "";
-        StringBuilder label = new StringBuilder(
-            classLinkInfo.getClassLinkLabel(m_writer.configuration));
-        classLinkInfo.displayLength += label.length();
+        Content label = classLinkInfo.getClassLinkLabel(m_writer.configuration);
         Configuration configuration = m_writer.configuration;
-        LinkOutputImpl linkOutput = new LinkOutputImpl();
+        Content link = new ContentBuilder();
         if (classDoc.isIncluded()) {
             if (configuration.isGeneratedDoc(classDoc)) {
                 DocPath filename = getPath(classLinkInfo);
                 if (linkInfo.linkToSelf ||
                                 !(DocPath.forName(classDoc)).equals(m_writer.filename)) {
-                        linkOutput.append(m_writer.getHyperLinkString(
+                        link.addContent(m_writer.getHyperLink(
                                 filename.fragment(classLinkInfo.where),
-                            label.toString(),
+                            label,
                             classLinkInfo.isStrong, classLinkInfo.styleName,
                             title, classLinkInfo.target));
                         if (noLabel && !classLinkInfo.excludeTypeParameterLinks) {
-                            linkOutput.append(getTypeParameterLinks(linkInfo).toString());
+                            link.addContent(getTypeParameterLinks(linkInfo));
                         }
-                        return linkOutput;
+                        return link;
                 }
             }
         } else {
-            String crossLink = m_writer.getCrossClassLink(
+            Content crossLink = m_writer.getCrossClassLink(
                 classDoc.qualifiedName(), classLinkInfo.where,
-                label.toString(), classLinkInfo.isStrong, classLinkInfo.styleName,
+                label, classLinkInfo.isStrong, classLinkInfo.styleName,
                 true);
             if (crossLink != null) {
-                linkOutput.append(crossLink);
+                link.addContent(crossLink);
                 if (noLabel && !classLinkInfo.excludeTypeParameterLinks) {
-                    linkOutput.append(getTypeParameterLinks(linkInfo).toString());
+                    link.addContent(getTypeParameterLinks(linkInfo));
                 }
-                return linkOutput;
+                return link;
             }
         }
         // Can't link so just write label.
-        linkOutput.append(label.toString());
+        link.addContent(label.toString());
         if (noLabel && !classLinkInfo.excludeTypeParameterLinks) {
-            linkOutput.append(getTypeParameterLinks(linkInfo).toString());
+            link.addContent(getTypeParameterLinks(linkInfo));
         }
-        return linkOutput;
+        return link;
     }
 
     /**
      * {@inheritDoc}
      */
-    protected LinkOutput getTypeParameterLink(LinkInfo linkInfo,
+    protected Content getTypeParameterLink(LinkInfo linkInfo,
         Type typeParam) {
         LinkInfoImpl typeLinkInfo = new LinkInfoImpl(m_writer.configuration,
-                linkInfo.getContext(), typeParam);
+                ((LinkInfoImpl) linkInfo).getContext(), typeParam);
         typeLinkInfo.excludeTypeBounds = linkInfo.excludeTypeBounds;
         typeLinkInfo.excludeTypeParameterLinks = linkInfo.excludeTypeParameterLinks;
         typeLinkInfo.linkToSelf = linkInfo.linkToSelf;
         typeLinkInfo.isJava5DeclarationLocation = false;
-        LinkOutput output = getLinkOutput(typeLinkInfo);
-        ((LinkInfoImpl) linkInfo).displayLength += typeLinkInfo.displayLength;
-        return output;
+        return getLink(typeLinkInfo);
     }
 
-    protected LinkOutput getTypeAnnotationLink(LinkInfo linkInfo,
+    protected Content getTypeAnnotationLink(LinkInfo linkInfo,
             AnnotationDesc annotation) {
         throw new RuntimeException("Not implemented yet!");
     }
 
-    public LinkOutput getTypeAnnotationLinks(LinkInfo linkInfo) {
-        LinkOutput output = getOutputInstance();
+    public Content getTypeAnnotationLinks(LinkInfo linkInfo) {
+        ContentBuilder links = new ContentBuilder();
         AnnotationDesc[] annotations;
         if (linkInfo.type instanceof AnnotatedType) {
             annotations = linkInfo.type.asAnnotatedType().annotations();
         } else if (linkInfo.type instanceof TypeVariable) {
             annotations = linkInfo.type.asTypeVariable().annotations();
         } else {
-            return output;
+            return links;
         }
 
         if (annotations.length == 0)
-            return output;
+            return links;
 
-        List<String> annos = m_writer.getAnnotations(0, annotations, false, linkInfo.isJava5DeclarationLocation);
+        List<Content> annos = m_writer.getAnnotations(0, annotations, false, linkInfo.isJava5DeclarationLocation);
 
         boolean isFirst = true;
-        for (String anno : annos) {
+        for (Content anno : annos) {
             if (!isFirst) {
-                linkInfo.displayLength += 1;
-                output.append(" ");
+                links.addContent(" ");
             }
-            output.append(anno);
+            links.addContent(anno);
             isFirst = false;
         }
         if (!annos.isEmpty()) {
-            linkInfo.displayLength += 1;
-            output.append(" ");
+            links.addContent(" ");
         }
 
-        return output;
+        return links;
     }
 
     /**
@@ -204,7 +201,7 @@
      * @param linkInfo the information about the link.
      */
     private DocPath getPath(LinkInfoImpl linkInfo) {
-        if (linkInfo.context == LinkInfoImpl.PACKAGE_FRAME) {
+        if (linkInfo.context == LinkInfoImpl.Kind.PACKAGE_FRAME) {
             //Not really necessary to do this but we want to be consistent
             //with 1.4.2 output.
             return DocPath.forName(linkInfo.classDoc);
--- a/src/share/classes/com/sun/tools/doclets/formats/html/LinkInfoImpl.java	Thu May 16 12:16:07 2013 -0700
+++ b/src/share/classes/com/sun/tools/doclets/formats/html/LinkInfoImpl.java	Fri May 17 10:13:34 2013 -0700
@@ -27,6 +27,9 @@
 package com.sun.tools.doclets.formats.html;
 
 import com.sun.javadoc.*;
+import com.sun.tools.doclets.formats.html.markup.ContentBuilder;
+import com.sun.tools.doclets.formats.html.markup.StringContent;
+import com.sun.tools.doclets.internal.toolkit.Content;
 import com.sun.tools.doclets.internal.toolkit.util.*;
 import com.sun.tools.doclets.internal.toolkit.util.links.*;
 
@@ -38,177 +41,181 @@
  */
 public class LinkInfoImpl extends LinkInfo {
 
-    /**
-     * Indicate that the link appears in a class list.
-     */
-    public static final int ALL_CLASSES_FRAME = 1;
+    public enum Kind {
+        DEFAULT,
 
-    /**
-     * Indicate that the link appears in a class documentation.
-     */
-    public static final int CONTEXT_CLASS = 2;
+        /**
+         * Indicate that the link appears in a class list.
+         */
+        ALL_CLASSES_FRAME,
 
-    /**
-     * Indicate that the link appears in member documentation.
-     */
-    public static final int CONTEXT_MEMBER = 3;
+        /**
+         * Indicate that the link appears in a class documentation.
+         */
+        CLASS,
 
-    /**
-     * Indicate that the link appears in class use documentation.
-     */
-    public static final int CONTEXT_CLASS_USE = 4;
+        /**
+         * Indicate that the link appears in member documentation.
+         */
+        MEMBER,
 
-    /**
-     * Indicate that the link appears in index documentation.
-     */
-    public static final int CONTEXT_INDEX = 5;
+        /**
+         * Indicate that the link appears in class use documentation.
+         */
+        CLASS_USE,
 
-    /**
-     * Indicate that the link appears in constant value summary.
-     */
-    public static final int CONTEXT_CONSTANT_SUMMARY = 6;
+        /**
+         * Indicate that the link appears in index documentation.
+         */
+        INDEX,
 
-    /**
-     * Indicate that the link appears in serialized form documentation.
-     */
-    public static final int CONTEXT_SERIALIZED_FORM = 7;
+        /**
+         * Indicate that the link appears in constant value summary.
+         */
+        CONSTANT_SUMMARY,
 
-    /**
-     * Indicate that the link appears in serial member documentation.
-     */
-    public static final int CONTEXT_SERIAL_MEMBER = 8;
+        /**
+         * Indicate that the link appears in serialized form documentation.
+         */
+        SERIALIZED_FORM,
 
-    /**
-     * Indicate that the link appears in package documentation.
-     */
-    public static final int CONTEXT_PACKAGE = 9;
+        /**
+         * Indicate that the link appears in serial member documentation.
+         */
+        SERIAL_MEMBER,
 
-    /**
-     * Indicate that the link appears in see tag documentation.
-     */
-    public static final int CONTEXT_SEE_TAG = 10;
+        /**
+         * Indicate that the link appears in package documentation.
+         */
+        PACKAGE,
 
-    /**
-     * Indicate that the link appears in value tag documentation.
-     */
-    public static final int CONTEXT_VALUE_TAG = 11;
+        /**
+         * Indicate that the link appears in see tag documentation.
+         */
+        SEE_TAG,
 
-    /**
-     * Indicate that the link appears in tree documentation.
-     */
-    public static final int CONTEXT_TREE = 12;
+        /**
+         * Indicate that the link appears in value tag documentation.
+         */
+        VALUE_TAG,
 
-    /**
-     * Indicate that the link appears in a class list.
-     */
-    public static final int PACKAGE_FRAME = 13;
+        /**
+         * Indicate that the link appears in tree documentation.
+         */
+        TREE,
 
-    /**
-     * The header in the class documentation.
-     */
-    public static final int CONTEXT_CLASS_HEADER = 14;
+        /**
+         * Indicate that the link appears in a class list.
+         */
+        PACKAGE_FRAME,
 
-    /**
-     * The signature in the class documentation.
-     */
-    public static final int CONTEXT_CLASS_SIGNATURE = 15;
+        /**
+         * The header in the class documentation.
+         */
+        CLASS_HEADER,
 
-    /**
-     * The return type of a method.
-     */
-    public static final int CONTEXT_RETURN_TYPE = 16;
+        /**
+         * The signature in the class documentation.
+         */
+        CLASS_SIGNATURE,
 
-    /**
-     * The return type of a method in a member summary.
-     */
-    public static final int CONTEXT_SUMMARY_RETURN_TYPE = 17;
+        /**
+         * The return type of a method.
+         */
+        RETURN_TYPE,
 
-    /**
-     * The type of a method/constructor parameter.
-     */
-    public static final int CONTEXT_EXECUTABLE_MEMBER_PARAM = 18;
+        /**
+         * The return type of a method in a member summary.
+         */
+        SUMMARY_RETURN_TYPE,
 
-    /**
-     * Super interface links.
-     */
-    public static final int CONTEXT_SUPER_INTERFACES = 19;
+        /**
+         * The type of a method/constructor parameter.
+         */
+        EXECUTABLE_MEMBER_PARAM,
 
-    /**
-     * Implemented interface links.
-     */
-    public static final int CONTEXT_IMPLEMENTED_INTERFACES = 20;
+        /**
+         * Super interface links.
+         */
+        SUPER_INTERFACES,
 
-    /**
-     * Implemented class links.
-     */
-    public static final int CONTEXT_IMPLEMENTED_CLASSES = 21;
+        /**
+         * Implemented interface links.
+         */
+        IMPLEMENTED_INTERFACES,
 
-    /**
-     * Subinterface links.
-     */
-    public static final int CONTEXT_SUBINTERFACES = 22;
+        /**
+         * Implemented class links.
+         */
+        IMPLEMENTED_CLASSES,
 
-    /**
-     * Subclasses links.
-     */
-    public static final int CONTEXT_SUBCLASSES = 23;
+        /**
+         * Subinterface links.
+         */
+        SUBINTERFACES,
 
-    /**
-     * The signature in the class documentation (implements/extends portion).
-     */
-    public static final int CONTEXT_CLASS_SIGNATURE_PARENT_NAME = 24;
+        /**
+         * Subclasses links.
+         */
+        SUBCLASSES,
 
-    /**
-     * The header for method documentation copied from parent.
-     */
-    public static final int CONTEXT_METHOD_DOC_COPY = 26;
+        /**
+         * The signature in the class documentation (implements/extends portion).
+         */
+        CLASS_SIGNATURE_PARENT_NAME,
 
-    /**
-     * Method "specified by" link.
-     */
-    public static final int CONTEXT_METHOD_SPECIFIED_BY = 27;
+        /**
+         * The header for method documentation copied from parent.
+         */
+        METHOD_DOC_COPY,
 
-    /**
-     * Method "overrides" link.
-     */
-    public static final int CONTEXT_METHOD_OVERRIDES = 28;
+        /**
+         * Method "specified by" link.
+         */
+        METHOD_SPECIFIED_BY,
 
-    /**
-     * Annotation link.
-     */
-    public static final int CONTEXT_ANNOTATION = 29;
+        /**
+         * Method "overrides" link.
+         */
+        METHOD_OVERRIDES,
 
-    /**
-     * The header for field documentation copied from parent.
-     */
-    public static final int CONTEXT_FIELD_DOC_COPY = 30;
+        /**
+         * Annotation link.
+         */
+        ANNOTATION,
 
-    /**
-     * The parent nodes int the class tree.
-     */
-    public static final int CONTEXT_CLASS_TREE_PARENT = 31;
+        /**
+         * The header for field documentation copied from parent.
+         */
+        FIELD_DOC_COPY,
 
-    /**
-     * The type parameters of a method or constructor.
-     */
-    public static final int CONTEXT_MEMBER_TYPE_PARAMS = 32;
+        /**
+         * The parent nodes in the class tree.
+         */
+        CLASS_TREE_PARENT,
 
-    /**
-     * Indicate that the link appears in class use documentation.
-     */
-    public static final int CONTEXT_CLASS_USE_HEADER = 33;
+        /**
+         * The type parameters of a method or constructor.
+         */
+        MEMBER_TYPE_PARAMS,
 
-    /**
-     * The header for property documentation copied from parent.
-     */
-    public static final int CONTEXT_PROPERTY_DOC_COPY = 34;
+        /**
+         * Indicate that the link appears in class use documentation.
+         */
+        CLASS_USE_HEADER,
+
+        /**
+         * The header for property documentation copied from parent.
+         */
+        PROPERTY_DOC_COPY
+    }
 
     public final ConfigurationImpl configuration;
 
     /**
-     * The integer indicating the location of the link.
+     * The location of the link.
      */
-    public int context;
+    public Kind context = Kind.DEFAULT;
 
     /**
      * The value of the marker #.
@@ -218,7 +225,7 @@
     /**
      * String style of text defined in style sheet.
      */
-    public String styleName ="";
+    public String styleName = "";
 
     /**
      * The value of the target.
@@ -230,108 +237,34 @@
      *
      * @param configuration the configuration data for the doclet
      * @param context    the context of the link.
-     * @param classDoc   the class to link to.
-     * @param label      the label for the link.
-     * @param target     the value of the target attribute.
+     * @param context               the context of the link.
+     * @param executableMemberDoc   the member to link to.
      */
     public LinkInfoImpl(ConfigurationImpl configuration,
-            int context, ClassDoc classDoc, String label, String target) {
+            Kind context, ExecutableMemberDoc executableMemberDoc) {
         this.configuration = configuration;
-        this.classDoc = classDoc;
-        this.label = label;
-        this.target = target;
+        this.executableMemberDoc = executableMemberDoc;
         setContext(context);
     }
 
     /**
+     * {@inherotDoc}
+     */
+    protected Content newContent() {
+        return new ContentBuilder();
+    }
+
+    /**
      * Construct a LinkInfo object.
      *
      * @param configuration the configuration data for the doclet
      * @param context    the context of the link.
      * @param classDoc   the class to link to.
-     * @param where      the value of the marker #.
-     * @param label      the label for the link.
-     * @param isStrong       true if the link should be strong.
-     * @param styleName  String style of text defined in style sheet.
      */
     public LinkInfoImpl(ConfigurationImpl configuration,
-            int context, ClassDoc classDoc, String where, String label,
-            boolean isStrong, String styleName) {
+            Kind context, ClassDoc classDoc) {
         this.configuration = configuration;
         this.classDoc = classDoc;
-        this.where = where;
-        this.label = label;
-        this.isStrong = isStrong;
-        this.styleName = styleName;
-        setContext(context);
-    }
-
-    /**
-     * Construct a LinkInfo object.
-     *
-     * @param configuration the configuration data for the doclet
-     * @param context    the context of the link.
-     * @param classDoc   the class to link to.
-     * @param where      the value of the marker #.
-     * @param label      the label for the link.
-     * @param isStrong       true if the link should be strong.
-     */
-    public LinkInfoImpl(ConfigurationImpl configuration,
-            int context, ClassDoc classDoc, String where, String label,
-            boolean isStrong) {
-        this.configuration = configuration;
-        this.classDoc = classDoc;
-        this.where = where;
-        this.label = label;
-        this.isStrong = isStrong;
-        setContext(context);
-    }
-
-    /**
-     * Construct a LinkInfo object.
-     *
-     * @param configuration the configuration data for the doclet
-     * @param classDoc   the class to link to.
-     * @param label      the label for the link.
-     */
-    public LinkInfoImpl(ConfigurationImpl configuration,
-            ClassDoc classDoc, String label) {
-        this.configuration = configuration;
-        this.classDoc = classDoc;
-        this.label = label;
-        setContext(context);
-    }
-
-    /**
-     * Construct a LinkInfo object.
-     *
-     * @param configuration the configuration data for the doclet
-     * @param context               the context of the link.
-     * @param executableMemberDoc   the member to link to.
-     * @param isStrong                true if the link should be strong.
-     */
-    public LinkInfoImpl(ConfigurationImpl configuration,
-            int context, ExecutableMemberDoc executableMemberDoc,
-            boolean isStrong) {
-        this.configuration = configuration;
-        this.executableMemberDoc = executableMemberDoc;
-        this.isStrong = isStrong;
-        setContext(context);
-    }
-
-    /**
-     * Construct a LinkInfo object.
-     *
-     * @param configuration the configuration data for the doclet
-     * @param context    the context of the link.
-     * @param classDoc   the class to link to.
-     * @param isStrong       true if the link should be strong.
-     */
-    public LinkInfoImpl(ConfigurationImpl configuration,
-            int context, ClassDoc classDoc,  boolean isStrong) {
-        this.configuration = configuration;
-        this.classDoc = classDoc;
-        this.isStrong = isStrong;
         setContext(context);
     }
 
@@ -343,70 +276,76 @@
      * @param type       the class to link to.
      */
     public LinkInfoImpl(ConfigurationImpl configuration,
-            int context, Type type) {
+            Kind context, Type type) {
         this.configuration = configuration;
         this.type = type;
         setContext(context);
     }
 
+
     /**
-     * Construct a LinkInfo object.
-     *
-     * @param configuration the configuration data for the doclet
-     * @param context    the context of the link.
-     * @param type       the class to link to.
-     * @param isVarArg   true if this is a link to a var arg.
+     * Set the label for the link.
+     * @param label plain-text label for the link
      */
-    public LinkInfoImpl(ConfigurationImpl configuration,
-            int context, Type type, boolean isVarArg) {
-        this.configuration = configuration;
-        this.type = type;
-        this.isVarArg = isVarArg;
-        setContext(context);
+    public LinkInfoImpl label(String label) {
+        this.label = new StringContent(label);
+        return this;
     }
 
     /**
-     * Construct a LinkInfo object.
-     *
-     * @param configuration the configuration data for the doclet
-     * @param context    the context of the link.
-     * @param type       the class to link to.
-     * @param label      the label for the link.
-     * @param isStrong     true if the link should be strong.
+     * Set the label for the link.
      */
-    public LinkInfoImpl(ConfigurationImpl configuration,
-            int context, Type type, String label,
-            boolean isStrong) {
-        this.configuration = configuration;
-        this.type = type;
+    public LinkInfoImpl label(Content label) {
         this.label = label;
-        this.isStrong = isStrong;
-        setContext(context);
+        return this;
     }
 
     /**
-     * Construct a LinkInfo object.
-     *
-     * @param configuration the configuration data for the doclet
-     * @param context    the context of the link.
-     * @param classDoc   the class to link to.
-     * @param label      the label for the link.
-     * @param isStrong       true if the link should be strong.
+     * Set whether or not the link should be strong.
      */
-    public LinkInfoImpl(ConfigurationImpl configuration,
-            int context, ClassDoc classDoc, String label,
-            boolean isStrong) {
-        this.configuration = configuration;
-        this.classDoc = classDoc;
-        this.label = label;
-        this.isStrong = isStrong;
-        setContext(context);
+    public LinkInfoImpl strong(boolean strong) {
+        this.isStrong = strong;
+        return this;
     }
 
     /**
+     * Set the style to be used for the link.
+     * @param styleName  String style of text defined in style sheet.
+     */
+    public LinkInfoImpl styleName(String styleName) {
+        this.styleName = styleName;
+        return this;
+    }
+
+    /**
+     * Set the target to be used for the link.
+     * @param styleName  String style of text defined in style sheet.
+     */
+    public LinkInfoImpl target(String target) {
+        this.target = target;
+        return this;
+    }
+
+    /**
+     * Set whether or not this is a link to a varargs parameter.
+     */
+    public LinkInfoImpl varargs(boolean varargs) {
+        this.isVarArg = varargs;
+        return this;
+    }
+
+    /**
+     * Set the fragment specifier for the link.
+     */
+    public LinkInfoImpl where(String where) {
+        this.where = where;
+        return this;
+     }
+
+    /**
      * {@inheritDoc}
      */
-    public int getContext() {
+    public Kind getContext() {
         return context;
     }
 
@@ -418,63 +357,63 @@
      *
      * @param c the context id to set.
      */
-    public void setContext(int c) {
+    public final void setContext(Kind c) {
         //NOTE:  Put context specific link code here.
         switch (c) {
             case ALL_CLASSES_FRAME:
             case PACKAGE_FRAME:
-            case CONTEXT_IMPLEMENTED_CLASSES:
-            case CONTEXT_SUBCLASSES:
-            case CONTEXT_METHOD_DOC_COPY:
-            case CONTEXT_FIELD_DOC_COPY:
-            case CONTEXT_PROPERTY_DOC_COPY:
-            case CONTEXT_CLASS_USE_HEADER:
+            case IMPLEMENTED_CLASSES:
+            case SUBCLASSES:
+            case METHOD_DOC_COPY:
+            case FIELD_DOC_COPY:
+            case PROPERTY_DOC_COPY:
+            case CLASS_USE_HEADER:
                 includeTypeInClassLinkLabel = false;
                 break;
 
-            case CONTEXT_ANNOTATION:
+            case ANNOTATION:
                 excludeTypeParameterLinks = true;
                 excludeTypeBounds = true;
                 break;
 
-            case CONTEXT_IMPLEMENTED_INTERFACES:
-            case CONTEXT_SUPER_INTERFACES:
-            case CONTEXT_SUBINTERFACES:
-            case CONTEXT_CLASS_TREE_PARENT:
-            case CONTEXT_TREE:
-            case CONTEXT_CLASS_SIGNATURE_PARENT_NAME:
+            case IMPLEMENTED_INTERFACES:
+            case SUPER_INTERFACES:
+            case SUBINTERFACES:
+            case CLASS_TREE_PARENT:
+            case TREE:
+            case CLASS_SIGNATURE_PARENT_NAME:
                 excludeTypeParameterLinks = true;
                 excludeTypeBounds = true;
                 includeTypeInClassLinkLabel = false;
                 includeTypeAsSepLink = true;
                 break;
 
-            case CONTEXT_PACKAGE:
-            case CONTEXT_CLASS_USE:
-            case CONTEXT_CLASS_HEADER:
-            case CONTEXT_CLASS_SIGNATURE:
+            case PACKAGE:
+            case CLASS_USE:
+            case CLASS_HEADER:
+            case CLASS_SIGNATURE:
                 excludeTypeParameterLinks = true;
                 includeTypeAsSepLink = true;
                 includeTypeInClassLinkLabel = false;
                 break;
 
-            case CONTEXT_MEMBER_TYPE_PARAMS:
+            case MEMBER_TYPE_PARAMS:
                 includeTypeAsSepLink = true;
                 includeTypeInClassLinkLabel = false;
                 break;
 
-            case CONTEXT_RETURN_TYPE:
-            case CONTEXT_SUMMARY_RETURN_TYPE:
+            case RETURN_TYPE:
+            case SUMMARY_RETURN_TYPE:
                 excludeTypeBounds = true;
                 break;
-            case CONTEXT_EXECUTABLE_MEMBER_PARAM:
+            case EXECUTABLE_MEMBER_PARAM:
                 excludeTypeBounds = true;
                 break;
         }
         context = c;
         if (type != null &&
             type.asTypeVariable()!= null &&
-            type.asTypeVariable().owner() instanceof ExecutableMemberDoc){
+            type.asTypeVariable().owner() instanceof ExecutableMemberDoc) {
             excludeTypeParameterLinks = true;
         }
     }
--- a/src/share/classes/com/sun/tools/doclets/formats/html/MethodWriterImpl.java	Thu May 16 12:16:07 2013 -0700
+++ b/src/share/classes/com/sun/tools/doclets/formats/html/MethodWriterImpl.java	Fri May 17 10:13:34 2013 -0700
@@ -117,7 +117,6 @@
      * @return a content object for the signature
      */
     public Content getSignature(MethodDoc method) {
-        writer.displayLength = 0;
         Content pre = new HtmlTree(HtmlTag.PRE);
         writer.addAnnotationInfo(method, pre);
         addModifiers(method, pre);
@@ -129,8 +128,9 @@
         } else {
             addName(method.name(), pre);
         }
-        addParameters(method, pre);
-        addExceptions(method, pre);
+        int indent = pre.charCount();
+        addParameters(method, pre, indent);
+        addExceptions(method, pre, indent);
         return pre;
     }
 
@@ -152,12 +152,12 @@
                     Util.isLinkable(holderClassDoc, configuration)))) {
                 writer.addInlineComment(method, methodDocTree);
             } else {
-                Content link = new RawHtml(
-                        writer.getDocLink(LinkInfoImpl.CONTEXT_METHOD_DOC_COPY,
+                Content link =
+                        writer.getDocLink(LinkInfoImpl.Kind.METHOD_DOC_COPY,
                         holder.asClassDoc(), method,
                         holder.asClassDoc().isIncluded() ?
                             holder.typeName() : holder.qualifiedTypeName(),
-                            false));
+                            false);
                 Content codelLink = HtmlTree.CODE(link);
                 Content strong = HtmlTree.STRONG(holder.asClassDoc().isClass()?
                     writer.descfrmClassLabel : writer.descfrmInterfaceLabel);
@@ -223,8 +223,8 @@
     /**
      * {@inheritDoc}
      */
-    public String getCaption() {
-        return configuration.getText("doclet.Methods");
+    public Content getCaption() {
+        return configuration.getResource("doclet.Methods");
     }
 
     /**
@@ -260,8 +260,8 @@
      * {@inheritDoc}
      */
     public void addInheritedSummaryLabel(ClassDoc cd, Content inheritedTree) {
-        Content classLink = new RawHtml(writer.getPreQualifiedClassLink(
-                LinkInfoImpl.CONTEXT_MEMBER, cd, false));
+        Content classLink = writer.getPreQualifiedClassLink(
+                LinkInfoImpl.Kind.MEMBER, cd, false);
         Content label = new StringContent(cd.isClass() ?
             configuration.getText("doclet.Methods_Inherited_From_Class") :
             configuration.getText("doclet.Methods_Inherited_From_Interface"));
@@ -300,25 +300,25 @@
             return;
         }
         Content label = writer.overridesLabel;
-        int context = LinkInfoImpl.CONTEXT_METHOD_OVERRIDES;
+        LinkInfoImpl.Kind context = LinkInfoImpl.Kind.METHOD_OVERRIDES;
 
         if (method != null) {
             if (overriddenType.asClassDoc().isAbstract() && method.isAbstract()){
                 //Abstract method is implemented from abstract class,
                 //not overridden
                 label = writer.specifiedByLabel;
-                context = LinkInfoImpl.CONTEXT_METHOD_SPECIFIED_BY;
+                context = LinkInfoImpl.Kind.METHOD_SPECIFIED_BY;
             }
             Content dt = HtmlTree.DT(HtmlTree.STRONG(label));
             dl.addContent(dt);
-            Content overriddenTypeLink = new RawHtml(
-                    writer.getLink(new LinkInfoImpl(writer.configuration, context, overriddenType)));
+            Content overriddenTypeLink =
+                    writer.getLink(new LinkInfoImpl(writer.configuration, context, overriddenType));
             Content codeOverridenTypeLink = HtmlTree.CODE(overriddenTypeLink);
             String name = method.name();
-            Content methlink = new RawHtml(writer.getLink(
-                    new LinkInfoImpl(writer.configuration, LinkInfoImpl.CONTEXT_MEMBER,
-                    overriddenType.asClassDoc(),
-                    writer.getAnchor(method), name, false)));
+            Content methlink = writer.getLink(
+                    new LinkInfoImpl(writer.configuration, LinkInfoImpl.Kind.MEMBER,
+                    overriddenType.asClassDoc())
+                    .where(writer.getAnchor(method)).label(name));
             Content codeMethLink = HtmlTree.CODE(methlink);
             Content dd = HtmlTree.DD(codeMethLink);
             dd.addContent(writer.getSpace());
@@ -361,14 +361,14 @@
         for (int i = 0; i < implementedMethods.length; i++) {
             MethodDoc implementedMeth = implementedMethods[i];
             Type intfac = implementedMethodsFinder.getMethodHolder(implementedMeth);
-            Content intfaclink = new RawHtml(writer.getLink(new LinkInfoImpl(
-                    writer.configuration, LinkInfoImpl.CONTEXT_METHOD_SPECIFIED_BY, intfac)));
+            Content intfaclink = writer.getLink(new LinkInfoImpl(
+                    writer.configuration, LinkInfoImpl.Kind.METHOD_SPECIFIED_BY, intfac));
             Content codeIntfacLink = HtmlTree.CODE(intfaclink);
             Content dt = HtmlTree.DT(HtmlTree.STRONG(writer.specifiedByLabel));
             dl.addContent(dt);
-            Content methlink = new RawHtml(writer.getDocLink(
-                    LinkInfoImpl.CONTEXT_MEMBER, implementedMeth,
-                    implementedMeth.name(), false));
+            Content methlink = writer.getDocLink(
+                    LinkInfoImpl.Kind.MEMBER, implementedMeth,
+                    implementedMeth.name(), false);
             Content codeMethLink = HtmlTree.CODE(methlink);
             Content dd = HtmlTree.DD(codeMethLink);
             dd.addContent(writer.getSpace());
@@ -388,8 +388,8 @@
     protected void addReturnType(MethodDoc method, Content htmltree) {
         Type type = method.returnType();
         if (type != null) {
-            Content linkContent = new RawHtml(writer.getLink(
-                    new LinkInfoImpl(configuration, LinkInfoImpl.CONTEXT_RETURN_TYPE, type)));
+            Content linkContent = writer.getLink(
+                    new LinkInfoImpl(configuration, LinkInfoImpl.Kind.RETURN_TYPE, type));
             htmltree.addContent(linkContent);
             htmltree.addContent(writer.getSpace());
         }
--- a/src/share/classes/com/sun/tools/doclets/formats/html/NestedClassWriterImpl.java	Thu May 16 12:16:07 2013 -0700
+++ b/src/share/classes/com/sun/tools/doclets/formats/html/NestedClassWriterImpl.java	Fri May 17 10:13:34 2013 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 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 @@
 package com.sun.tools.doclets.formats.html;
 
 import java.io.*;
-import java.util.*;
 
 import com.sun.javadoc.*;
 import com.sun.tools.doclets.formats.html.markup.*;
@@ -101,8 +100,8 @@
     /**
      * {@inheritDoc}
      */
-    public String getCaption() {
-        return configuration.getText("doclet.Nested_Classes");
+    public Content getCaption() {
+        return configuration.getResource("doclet.Nested_Classes");
     }
 
     /**
@@ -148,8 +147,8 @@
      * {@inheritDoc}
      */
     public void addInheritedSummaryLabel(ClassDoc cd, Content inheritedTree) {
-        Content classLink = new RawHtml(writer.getPreQualifiedClassLink(
-                LinkInfoImpl.CONTEXT_MEMBER, cd, false));
+        Content classLink = writer.getPreQualifiedClassLink(
+                LinkInfoImpl.Kind.MEMBER, cd, false);
         Content label = new StringContent(cd.isInterface() ?
             configuration.getText("doclet.Nested_Classes_Interface_Inherited_From_Interface") :
             configuration.getText("doclet.Nested_Classes_Interfaces_Inherited_From_Class"));
@@ -163,10 +162,10 @@
     /**
      * {@inheritDoc}
      */
-    protected void addSummaryLink(int context, ClassDoc cd, ProgramElementDoc member,
+    protected void addSummaryLink(LinkInfoImpl.Kind context, ClassDoc cd, ProgramElementDoc member,
             Content tdSummary) {
-        Content strong = HtmlTree.STRONG(new RawHtml(
-                writer.getLink(new LinkInfoImpl(configuration, context, (ClassDoc)member, false))));
+        Content strong = HtmlTree.STRONG(
+                writer.getLink(new LinkInfoImpl(configuration, context, (ClassDoc)member)));
         Content code = HtmlTree.CODE(strong);
         tdSummary.addContent(code);
     }
@@ -176,9 +175,9 @@
      */
     protected void addInheritedSummaryLink(ClassDoc cd,
             ProgramElementDoc member, Content linksTree) {
-        linksTree.addContent(new RawHtml(
-                writer.getLink(new LinkInfoImpl(configuration, LinkInfoImpl.CONTEXT_MEMBER,
-                (ClassDoc)member, false))));
+        linksTree.addContent(
+                writer.getLink(new LinkInfoImpl(configuration, LinkInfoImpl.Kind.MEMBER,
+                (ClassDoc)member)));
     }
 
     /**
@@ -194,7 +193,7 @@
      * {@inheritDoc}
      */
     protected Content getDeprecatedLink(ProgramElementDoc member) {
-        return writer.getQualifiedClassLink(LinkInfoImpl.CONTEXT_MEMBER,
+        return writer.getQualifiedClassLink(LinkInfoImpl.Kind.MEMBER,
                 (ClassDoc)member);
     }
 
--- a/src/share/classes/com/sun/tools/doclets/formats/html/PackageFrameWriter.java	Thu May 16 12:16:07 2013 -0700
+++ b/src/share/classes/com/sun/tools/doclets/formats/html/PackageFrameWriter.java	Fri May 17 10:13:34 2013 -0700
@@ -94,7 +94,7 @@
             packgen = new PackageFrameWriter(configuration, packageDoc);
             String pkgName = Util.getPackageName(packageDoc);
             Content body = packgen.getBody(false, packgen.getWindowTitle(pkgName));
-            Content pkgNameContent = new RawHtml(pkgName);
+            Content pkgNameContent = new StringContent(pkgName);
             Content heading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING, HtmlStyle.bar,
                     packgen.getTargetPackageLink(packageDoc, "classFrame", pkgNameContent));
             body.addContent(heading);
@@ -166,7 +166,7 @@
             Arrays.sort(arr);
             boolean printedHeader = false;
             HtmlTree ul = new HtmlTree(HtmlTag.UL);
-            ul.addAttr(HtmlAttr.TITLE, labelContent.toString());
+            ul.setTitle(labelContent);
             for (int i = 0; i < arr.length; i++) {
                 if (documentedClasses != null &&
                         !documentedClasses.contains(arr[i])) {
@@ -182,10 +182,10 @@
                     contentTree.addContent(heading);
                     printedHeader = true;
                 }
-                Content link = new RawHtml (getLink(new LinkInfoImpl(configuration,
-                        LinkInfoImpl.PACKAGE_FRAME, arr[i],
-                        (arr[i].isInterface() ? italicsText(arr[i].name()) :
-                            arr[i].name()),"classFrame")));
+                Content arr_i_name = new StringContent(arr[i].name());
+                if (arr[i].isInterface()) arr_i_name = HtmlTree.I(arr_i_name);
+                Content link = getLink(new LinkInfoImpl(configuration,
+                        LinkInfoImpl.Kind.PACKAGE_FRAME, arr[i]).label(arr_i_name).target("classFrame"));
                 Content li = HtmlTree.LI(link);
                 ul.addContent(li);
             }
--- a/src/share/classes/com/sun/tools/doclets/formats/html/PackageIndexFrameWriter.java	Thu May 16 12:16:07 2013 -0700
+++ b/src/share/classes/com/sun/tools/doclets/formats/html/PackageIndexFrameWriter.java	Fri May 17 10:13:34 2013 -0700
@@ -84,7 +84,7 @@
                 packagesLabel);
         Content div = HtmlTree.DIV(HtmlStyle.indexContainer, heading);
         HtmlTree ul = new HtmlTree(HtmlTag.UL);
-        ul.addAttr(HtmlAttr.TITLE, packagesLabel.toString());
+        ul.setTitle(packagesLabel);
         for(int i = 0; i < packages.length; i++) {
             // Do not list the package if -nodeprecated option is set and the
             // package is marked as deprecated.
@@ -112,7 +112,7 @@
                      DocPaths.PACKAGE_FRAME), packageLabel, "",
                     "packageFrame");
         } else {
-            packageLabel = new RawHtml("&lt;unnamed package&gt;");
+            packageLabel = new StringContent("<unnamed package>");
             packageLinkContent = getHyperLink(DocPaths.PACKAGE_FRAME,
                     packageLabel, "", "packageFrame");
         }
--- a/src/share/classes/com/sun/tools/doclets/formats/html/PackageIndexWriter.java	Thu May 16 12:16:07 2013 -0700
+++ b/src/share/classes/com/sun/tools/doclets/formats/html/PackageIndexWriter.java	Fri May 17 10:13:34 2013 -0700
@@ -123,7 +123,7 @@
     /**
      * {@inheritDoc}
      */
-    protected void addProfilesList(String profileSummary, String profilesTableSummary,
+    protected void addProfilesList(Content profileSummary, String profilesTableSummary,
             Content body) {
         Content table = HtmlTree.TABLE(HtmlStyle.overviewSummary, 0, 3, 0, profilesTableSummary,
                 getTableCaption(profileSummary));
@@ -141,7 +141,7 @@
     protected void addPackagesList(PackageDoc[] packages, String text,
             String tableSummary, Content body) {
         Content table = HtmlTree.TABLE(HtmlStyle.overviewSummary, 0, 3, 0, tableSummary,
-                getTableCaption(text));
+                getTableCaption(new RawHtml(text)));
         table.addContent(getSummaryTableHeader(packageTableHeader, "col"));
         Content tbody = new HtmlTree(HtmlTag.TBODY);
         addPackagesList(packages, tbody);
--- a/src/share/classes/com/sun/tools/doclets/formats/html/PackageTreeWriter.java	Thu May 16 12:16:07 2013 -0700
+++ b/src/share/classes/com/sun/tools/doclets/formats/html/PackageTreeWriter.java	Fri May 17 10:13:34 2013 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 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
--- a/src/share/classes/com/sun/tools/doclets/formats/html/PackageUseWriter.java	Thu May 16 12:16:07 2013 -0700
+++ b/src/share/classes/com/sun/tools/doclets/formats/html/PackageUseWriter.java	Fri May 17 10:13:34 2013 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 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
@@ -152,9 +152,9 @@
      */
     protected void addPackageList(Content contentTree) throws IOException {
         Content table = HtmlTree.TABLE(0, 3, 0, useTableSummary,
-                getTableCaption(configuration.getText(
+                getTableCaption(configuration.getResource(
                 "doclet.ClassUse_Packages.that.use.0",
-                getPackageLinkString(pkgdoc, Util.getPackageName(pkgdoc), false))));
+                getPackageLink(pkgdoc, Util.getPackageName(pkgdoc)))));
         table.addContent(getSummaryTableHeader(packageTableHeader, "col"));
         Content tbody = new HtmlTree(HtmlTag.TBODY);
         Iterator<String> it = usingPackageToUsedClasses.keySet().iterator();
@@ -197,10 +197,10 @@
             String tableSummary = configuration.getText("doclet.Use_Table_Summary",
                     configuration.getText("doclet.classes"));
             Content table = HtmlTree.TABLE(0, 3, 0, tableSummary,
-                    getTableCaption(configuration.getText(
+                    getTableCaption(configuration.getResource(
                     "doclet.ClassUse_Classes.in.0.used.by.1",
-                    getPackageLinkString(pkgdoc, Util.getPackageName(pkgdoc), false),
-                    getPackageLinkString(usingPackage,Util.getPackageName(usingPackage), false))));
+                    getPackageLink(pkgdoc, Util.getPackageName(pkgdoc)),
+                    getPackageLink(usingPackage, Util.getPackageName(usingPackage)))));
             table.addContent(getSummaryTableHeader(classTableHeader, "col"));
             Content tbody = new HtmlTree(HtmlTag.TBODY);
             Iterator<ClassDoc> itc =
@@ -247,7 +247,7 @@
     protected void addPackageUse(PackageDoc pkg, Content contentTree) throws IOException {
         Content tdFirst = HtmlTree.TD(HtmlStyle.colFirst,
                 getHyperLink(Util.getPackageName(pkg),
-                new RawHtml(Util.getPackageName(pkg))));
+                new StringContent(Util.getPackageName(pkg))));
         contentTree.addContent(tdFirst);
         HtmlTree tdLast = new HtmlTree(HtmlTag.TD);
         tdLast.addStyle(HtmlStyle.colLast);
@@ -272,7 +272,10 @@
         Content bodyTree = getBody(true, getWindowTitle(title));
         addTop(bodyTree);
         addNavLinks(true, bodyTree);
-        Content headContent = getResource("doclet.ClassUse_Title", packageText, name);
+        ContentBuilder headContent = new ContentBuilder();
+        headContent.addContent(getResource("doclet.ClassUse_Title", packageText));
+        headContent.addContent(new HtmlTree(HtmlTag.BR));
+        headContent.addContent(name);
         Content heading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING, true,
                 HtmlStyle.title, headContent);
         Content div = HtmlTree.DIV(HtmlStyle.header, heading);
--- a/src/share/classes/com/sun/tools/doclets/formats/html/PackageWriterImpl.java	Thu May 16 12:16:07 2013 -0700
+++ b/src/share/classes/com/sun/tools/doclets/formats/html/PackageWriterImpl.java	Fri May 17 10:13:34 2013 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 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
@@ -102,7 +102,7 @@
         Content tHeading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING, true,
                 HtmlStyle.title, packageLabel);
         tHeading.addContent(getSpace());
-        Content packageHead = new RawHtml(heading);
+        Content packageHead = new StringContent(heading);
         tHeading.addContent(packageHead);
         div.addContent(tHeading);
         addDeprecationInfo(div);
@@ -168,7 +168,7 @@
             String tableSummary, String[] tableHeader, Content summaryContentTree) {
         if(classes.length > 0) {
             Arrays.sort(classes);
-            Content caption = getTableCaption(label);
+            Content caption = getTableCaption(new RawHtml(label));
             Content table = HtmlTree.TABLE(HtmlStyle.packageSummary, 0, 3, 0,
                     tableSummary, caption);
             table.addContent(getSummaryTableHeader(tableHeader, "col"));
@@ -178,9 +178,8 @@
                     !configuration.isGeneratedDoc(classes[i])) {
                     continue;
                 }
-                Content classContent = new RawHtml(getLink(new LinkInfoImpl(
-                        configuration, LinkInfoImpl.CONTEXT_PACKAGE, classes[i],
-                        false)));
+                Content classContent = getLink(new LinkInfoImpl(
+                        configuration, LinkInfoImpl.Kind.PACKAGE, classes[i]));
                 Content tdClass = HtmlTree.TD(HtmlStyle.colFirst, classContent);
                 HtmlTree tr = HtmlTree.TR(tdClass);
                 if (i%2 == 0)
--- a/src/share/classes/com/sun/tools/doclets/formats/html/ProfileIndexFrameWriter.java	Thu May 16 12:16:07 2013 -0700
+++ b/src/share/classes/com/sun/tools/doclets/formats/html/ProfileIndexFrameWriter.java	Fri May 17 10:13:34 2013 -0700
@@ -87,7 +87,7 @@
                 profilesLabel);
         Content div = HtmlTree.DIV(HtmlStyle.indexContainer, heading);
         HtmlTree ul = new HtmlTree(HtmlTag.UL);
-        ul.addAttr(HtmlAttr.TITLE, profilesLabel.toString());
+        ul.setTitle(profilesLabel);
         for (int i = 1; i < profiles.getProfileCount(); i++) {
             ul.addContent(getProfile(i));
         }
--- a/src/share/classes/com/sun/tools/doclets/formats/html/ProfilePackageFrameWriter.java	Thu May 16 12:16:07 2013 -0700
+++ b/src/share/classes/com/sun/tools/doclets/formats/html/ProfilePackageFrameWriter.java	Fri May 17 10:13:34 2013 -0700
@@ -158,7 +158,7 @@
             Arrays.sort(arr);
             boolean printedHeader = false;
             HtmlTree ul = new HtmlTree(HtmlTag.UL);
-            ul.addAttr(HtmlAttr.TITLE, labelContent.toString());
+            ul.setTitle(labelContent);
             for (int i = 0; i < arr.length; i++) {
                 if (!isTypeInProfile(arr[i], profileValue)) {
                     continue;
@@ -173,10 +173,10 @@
                     contentTree.addContent(heading);
                     printedHeader = true;
                 }
-                Content link = new RawHtml (getLink(new LinkInfoImpl(configuration,
-                        LinkInfoImpl.PACKAGE_FRAME, arr[i],
-                        (arr[i].isInterface() ? italicsText(arr[i].name()) :
-                            arr[i].name()),"classFrame")));
+                Content arr_i_name = new StringContent(arr[i].name());
+                if (arr[i].isInterface()) arr_i_name = HtmlTree.I(arr_i_name);
+                Content link = getLink(new LinkInfoImpl(configuration,
+                        LinkInfoImpl.Kind.PACKAGE_FRAME, arr[i]).label(arr_i_name).target("classFrame"));
                 Content li = HtmlTree.LI(link);
                 ul.addContent(li);
             }
--- a/src/share/classes/com/sun/tools/doclets/formats/html/ProfilePackageIndexFrameWriter.java	Thu May 16 12:16:07 2013 -0700
+++ b/src/share/classes/com/sun/tools/doclets/formats/html/ProfilePackageIndexFrameWriter.java	Fri May 17 10:13:34 2013 -0700
@@ -91,7 +91,7 @@
         heading.addContent(packagesLabel);
         Content div = HtmlTree.DIV(HtmlStyle.indexContainer, heading);
         HtmlTree ul = new HtmlTree(HtmlTag.UL);
-        ul.addAttr(HtmlAttr.TITLE, packagesLabel.toString());
+        ul.setTitle(packagesLabel);
         PackageDoc[] packages = configuration.profilePackages.get(profileName);
         for (int i = 0; i < packages.length; i++) {
             if ((!(configuration.nodeprecated && Util.isDeprecated(packages[i])))) {
@@ -118,7 +118,7 @@
                      DocPaths.profilePackageFrame(profileName)), pkgLabel, "",
                     "packageFrame");
         } else {
-            pkgLabel = new RawHtml("&lt;unnamed package&gt;");
+            pkgLabel = new StringContent("<unnamed package>");
             packageLinkContent = getHyperLink(DocPaths.PACKAGE_FRAME,
                     pkgLabel, "", "packageFrame");
         }
--- a/src/share/classes/com/sun/tools/doclets/formats/html/PropertyWriterImpl.java	Thu May 16 12:16:07 2013 -0700
+++ b/src/share/classes/com/sun/tools/doclets/formats/html/PropertyWriterImpl.java	Fri May 17 10:13:34 2013 -0700
@@ -98,9 +98,9 @@
         Content pre = new HtmlTree(HtmlTag.PRE);
         writer.addAnnotationInfo(property, pre);
         addModifiers(property, pre);
-        Content propertylink = new RawHtml(writer.getLink(new LinkInfoImpl(
-                configuration, LinkInfoImpl.CONTEXT_MEMBER,
-                property.returnType())));
+        Content propertylink = writer.getLink(new LinkInfoImpl(
+                configuration, LinkInfoImpl.Kind.MEMBER,
+                property.returnType()));
         pre.addContent(propertylink);
         pre.addContent(" ");
         if (configuration.linksource) {
@@ -128,12 +128,12 @@
                     (! (holder.isPublic() || Util.isLinkable(holder, configuration)))) {
                 writer.addInlineComment(property, propertyDocTree);
             } else {
-                Content link = new RawHtml(
-                        writer.getDocLink(LinkInfoImpl.CONTEXT_PROPERTY_DOC_COPY,
+                Content link =
+                        writer.getDocLink(LinkInfoImpl.Kind.PROPERTY_DOC_COPY,
                         holder, property,
                         holder.isIncluded() ?
                             holder.typeName() : holder.qualifiedTypeName(),
-                            false));
+                            false);
                 Content codeLink = HtmlTree.CODE(link);
                 Content strong = HtmlTree.STRONG(holder.isClass()?
                    writer.descfrmClassLabel : writer.descfrmInterfaceLabel);
@@ -199,8 +199,8 @@
     /**
      * {@inheritDoc}
      */
-    public String getCaption() {
-        return configuration.getText("doclet.Properties");
+    public Content getCaption() {
+        return configuration.getResource("doclet.Properties");
     }
 
     /**
@@ -235,8 +235,8 @@
      * {@inheritDoc}
      */
     public void addInheritedSummaryLabel(ClassDoc cd, Content inheritedTree) {
-        Content classLink = new RawHtml(writer.getPreQualifiedClassLink(
-                LinkInfoImpl.CONTEXT_MEMBER, cd, false));
+        Content classLink = writer.getPreQualifiedClassLink(
+                LinkInfoImpl.Kind.MEMBER, cd, false);
         Content label = new StringContent(cd.isClass() ?
             configuration.getText("doclet.Properties_Inherited_From_Class") :
             configuration.getText("doclet.Properties_Inherited_From_Interface"));
@@ -250,15 +250,15 @@
     /**
      * {@inheritDoc}
      */
-    protected void addSummaryLink(int context, ClassDoc cd, ProgramElementDoc member,
+    protected void addSummaryLink(LinkInfoImpl.Kind context, ClassDoc cd, ProgramElementDoc member,
             Content tdSummary) {
-        Content strong = HtmlTree.STRONG(new RawHtml(
+        Content strong = HtmlTree.STRONG(
                 writer.getDocLink(context,
                         cd,
                         (MemberDoc) member,
                         member.name().substring(0, member.name().lastIndexOf("Property")),
                         false,
-                        true)));
+                        true));
 
         Content code = HtmlTree.CODE(strong);
         tdSummary.addContent(code);
@@ -269,12 +269,12 @@
      */
     protected void addInheritedSummaryLink(ClassDoc cd,
             ProgramElementDoc member, Content linksTree) {
-        linksTree.addContent(new RawHtml(
-                writer.getDocLink(LinkInfoImpl.CONTEXT_MEMBER, cd, (MemberDoc)member,
+        linksTree.addContent(
+                writer.getDocLink(LinkInfoImpl.Kind.MEMBER, cd, (MemberDoc)member,
                 ((member.name().lastIndexOf("Property") != -1) && configuration.javafx)
                         ? member.name().substring(0, member.name().length() - "Property".length())
                         : member.name(),
-                false, true)));
+                false, true));
     }
 
     /**
@@ -289,7 +289,7 @@
      * {@inheritDoc}
      */
     protected Content getDeprecatedLink(ProgramElementDoc member) {
-        return writer.getDocLink(LinkInfoImpl.CONTEXT_MEMBER,
+        return writer.getDocLink(LinkInfoImpl.Kind.MEMBER,
                 (MemberDoc) member, ((MethodDoc)member).qualifiedName());
     }
 
--- a/src/share/classes/com/sun/tools/doclets/formats/html/SerializedFormWriterImpl.java	Thu May 16 12:16:07 2013 -0700
+++ b/src/share/classes/com/sun/tools/doclets/formats/html/SerializedFormWriterImpl.java	Fri May 17 10:13:34 2013 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 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
@@ -127,29 +127,28 @@
      * @return a content tree for the class header
      */
     public Content getClassHeader(ClassDoc classDoc) {
-        String classLink = (classDoc.isPublic() || classDoc.isProtected())?
-            getLink(new LinkInfoImpl(configuration, classDoc,
-            configuration.getClassName(classDoc))):
-            classDoc.qualifiedName();
+        Content classLink = (classDoc.isPublic() || classDoc.isProtected()) ?
+            getLink(new LinkInfoImpl(configuration, LinkInfoImpl.Kind.DEFAULT, classDoc)
+            .label(configuration.getClassName(classDoc))) :
+            new StringContent(classDoc.qualifiedName());
         Content li = HtmlTree.LI(HtmlStyle.blockList, getMarkerAnchor(
                 classDoc.qualifiedName()));
-        String superClassLink =
+        Content superClassLink =
             classDoc.superclassType() != null ?
                 getLink(new LinkInfoImpl(configuration,
-                        LinkInfoImpl.CONTEXT_SERIALIZED_FORM,
+                        LinkInfoImpl.Kind.SERIALIZED_FORM,
                         classDoc.superclassType())) :
                 null;
 
         //Print the heading.
-        String className = superClassLink == null ?
-            configuration.getText(
+        Content className = superClassLink == null ?
+            configuration.getResource(
             "doclet.Class_0_implements_serializable", classLink) :
-            configuration.getText(
+            configuration.getResource(
             "doclet.Class_0_extends_implements_serializable", classLink,
             superClassLink);
-        Content classNameContent = new RawHtml(className);
         li.addContent(HtmlTree.HEADING(HtmlConstants.SERIALIZED_MEMBER_HEADING,
-                classNameContent));
+                className));
         return li;
     }
 
--- a/src/share/classes/com/sun/tools/doclets/formats/html/SourceToHTMLConverter.java	Thu May 16 12:16:07 2013 -0700
+++ b/src/share/classes/com/sun/tools/doclets/formats/html/SourceToHTMLConverter.java	Fri May 17 10:13:34 2013 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 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
@@ -58,7 +58,7 @@
     /**
      * New line to be added to the documentation.
      */
-    private static final Content NEW_LINE = new RawHtml(DocletConstants.NL);
+    private static final String NEW_LINE = DocletConstants.NL;
 
     private final ConfigurationImpl configuration;
 
@@ -269,10 +269,7 @@
      */
     private void addLine(Content pre, String line, int currentLineNo) {
         if (line != null) {
-            StringBuilder lineBuffer = new StringBuilder(line);
-            Util.replaceTabs(configuration, lineBuffer);
-            Util.escapeHtmlChars(lineBuffer);
-            pre.addContent(new RawHtml(lineBuffer.toString()));
+            pre.addContent(Util.replaceTabs(configuration, line));
             Content anchor = HtmlTree.A_NAME("line." + Integer.toString(currentLineNo));
             pre.addContent(anchor);
             pre.addContent(NEW_LINE);
--- a/src/share/classes/com/sun/tools/doclets/formats/html/SubWriterHolderWriter.java	Thu May 16 12:16:07 2013 -0700
+++ b/src/share/classes/com/sun/tools/doclets/formats/html/SubWriterHolderWriter.java	Fri May 17 10:13:34 2013 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 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
@@ -135,10 +135,8 @@
      * @return the content tree for the method type link
      */
     public Content getMethodTypeLinks(MethodTypes methodType) {
-        StringBuilder jsShow = new StringBuilder("javascript:show(");
-        jsShow.append(methodType.value()).append(");");
-        HtmlTree link = HtmlTree.A(jsShow.toString(),
-                new StringContent(methodType.text()));
+        String jsShow = "javascript:show(" + methodType.value() +");";
+        HtmlTree link = HtmlTree.A(jsShow, new StringContent(methodType.text()));
         return link;
     }
 
--- a/src/share/classes/com/sun/tools/doclets/formats/html/TagletOutputImpl.java	Thu May 16 12:16:07 2013 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,81 +0,0 @@
-/*
- * Copyright (c) 2003, 2012, 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
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-package com.sun.tools.doclets.formats.html;
-
-import com.sun.tools.doclets.internal.toolkit.taglets.*;
-
-/**
- * The output for HTML taglets.
- *
- *  <p><b>This is NOT part of any supported API.
- *  If you write code that depends on this, you do so at your own risk.
- *  This code and its internal interfaces are subject to change or
- *  deletion without notice.</b>
- *
- * @since 1.5
- * @author Jamie Ho
- */
-
-public class TagletOutputImpl implements TagletOutput {
-
-    private StringBuilder output;
-
-    public TagletOutputImpl(String o) {
-        setOutput(o);
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public void setOutput (Object o) {
-        output = new StringBuilder(o == null ? "" : (String) o);
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public void appendOutput(TagletOutput o) {
-        output.append(o.toString());
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public boolean hasInheritDocTag() {
-        return output.indexOf(InheritDocTaglet.INHERIT_DOC_INLINE_TAG) != -1;
-    }
-
-    public String toString() {
-        return output.toString();
-    }
-
-    /**
-     * Check whether the taglet output is empty.
-     */
-    public boolean isEmpty() {
-        return (toString().trim().isEmpty());
-    }
-}
--- a/src/share/classes/com/sun/tools/doclets/formats/html/TagletWriterImpl.java	Thu May 16 12:16:07 2013 -0700
+++ b/src/share/classes/com/sun/tools/doclets/formats/html/TagletWriterImpl.java	Fri May 17 10:13:34 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,6 +26,11 @@
 package com.sun.tools.doclets.formats.html;
 
 import com.sun.javadoc.*;
+import com.sun.tools.doclets.formats.html.markup.ContentBuilder;
+import com.sun.tools.doclets.formats.html.markup.HtmlStyle;
+import com.sun.tools.doclets.formats.html.markup.HtmlTree;
+import com.sun.tools.doclets.formats.html.markup.RawHtml;
+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.*;
@@ -58,39 +63,48 @@
     /**
      * {@inheritDoc}
      */
-    public TagletOutput getOutputInstance() {
-        return new TagletOutputImpl("");
+    public Content getOutputInstance() {
+        return new ContentBuilder();
     }
 
     /**
      * {@inheritDoc}
      */
-    public TagletOutput getDocRootOutput() {
-        if (configuration.docrootparent.length() > 0)
-            return new TagletOutputImpl(configuration.docrootparent);
-        else if (htmlWriter.pathToRoot.isEmpty())
-            return new TagletOutputImpl(".");
-        else
-            return new TagletOutputImpl(htmlWriter.pathToRoot.getPath());
+    protected Content codeTagOutput(Tag tag) {
+        Content result = HtmlTree.CODE(new StringContent(tag.text()));
+        return result;
     }
 
     /**
      * {@inheritDoc}
      */
-    public TagletOutput deprecatedTagOutput(Doc doc) {
-        StringBuilder output = new StringBuilder();
+    public Content getDocRootOutput() {
+        String path;
+        if (configuration.docrootparent.length() > 0)
+            path = configuration.docrootparent;
+        else if (htmlWriter.pathToRoot.isEmpty())
+            path = ".";
+        else
+            path = htmlWriter.pathToRoot.getPath();
+        return new StringContent(path);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Content deprecatedTagOutput(Doc doc) {
+        ContentBuilder result = new ContentBuilder();
         Tag[] deprs = doc.tags("deprecated");
         if (doc instanceof ClassDoc) {
             if (Util.isDeprecated((ProgramElementDoc) doc)) {
-                output.append("<span class=\"strong\">" +
-                    configuration.
-                        getText("doclet.Deprecated") + "</span>&nbsp;");
+                result.addContent(HtmlTree.SPAN(HtmlStyle.strong,
+                        new StringContent(configuration.getText("doclet.Deprecated"))));
+                result.addContent(RawHtml.nbsp);
                 if (deprs.length > 0) {
                     Tag[] commentTags = deprs[0].inlineTags();
                     if (commentTags.length > 0) {
-
-                        output.append(commentTagsToOutput(null, doc,
-                            deprs[0].inlineTags(), false).toString()
+                        result.addContent(commentTagsToOutput(null, doc,
+                            deprs[0].inlineTags(), false)
                         );
                     }
                 }
@@ -98,24 +112,31 @@
         } else {
             MemberDoc member = (MemberDoc) doc;
             if (Util.isDeprecated((ProgramElementDoc) doc)) {
-                output.append("<span class=\"strong\">" +
-                    configuration.
-                            getText("doclet.Deprecated") + "</span>&nbsp;");
+                result.addContent(HtmlTree.SPAN(HtmlStyle.strong,
+                        new StringContent(configuration.getText("doclet.Deprecated"))));
+                result.addContent(RawHtml.nbsp);
                 if (deprs.length > 0) {
-                    output.append("<i>");
-                    output.append(commentTagsToOutput(null, doc,
-                        deprs[0].inlineTags(), false).toString());
-                    output.append("</i>");
+                    Content body = commentTagsToOutput(null, doc,
+                        deprs[0].inlineTags(), false);
+                    result.addContent(HtmlTree.I(body));
                 }
             } else {
                 if (Util.isDeprecated(member.containingClass())) {
-                    output.append("<span class=\"strong\">" +
-                    configuration.
-                            getText("doclet.Deprecated") + "</span>&nbsp;");
+                    result.addContent(HtmlTree.SPAN(HtmlStyle.strong,
+                            new StringContent(configuration.getText("doclet.Deprecated"))));
+                    result.addContent(RawHtml.nbsp);
                 }
             }
         }
-        return new TagletOutputImpl(output.toString());
+        return result;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    protected Content literalTagOutput(Tag tag) {
+        Content result = new StringContent(tag.text());
+        return result;
     }
 
     /**
@@ -128,177 +149,200 @@
     /**
      * {@inheritDoc}
      */
-    public TagletOutput getParamHeader(String header) {
-        StringBuilder result = new StringBuilder();
-        result.append("<dt>");
-        result.append("<span class=\"strong\">").append(header).append("</span></dt>");
-        return new TagletOutputImpl(result.toString());
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public TagletOutput paramTagOutput(ParamTag paramTag, String paramName) {
-        TagletOutput result = new TagletOutputImpl("<dd><code>" + paramName + "</code>"
-         + " - " + htmlWriter.commentTagsToString(paramTag, null, paramTag.inlineTags(), false) + "</dd>");
+    public Content getParamHeader(String header) {
+        HtmlTree result = HtmlTree.DT(HtmlTree.SPAN(HtmlStyle.strong,
+                new StringContent(header)));
         return result;
     }
 
     /**
      * {@inheritDoc}
      */
-    public TagletOutput returnTagOutput(Tag returnTag) {
-        TagletOutput result = new TagletOutputImpl(DocletConstants.NL + "<dt>" +
-            "<span class=\"strong\">" + configuration.getText("doclet.Returns") +
-            "</span>" + "</dt>" + "<dd>" +
-            htmlWriter.commentTagsToString(returnTag, null, returnTag.inlineTags(),
-            false) + "</dd>");
+    public Content paramTagOutput(ParamTag paramTag, String paramName) {
+        ContentBuilder body = new ContentBuilder();
+        body.addContent(HtmlTree.CODE(new RawHtml(paramName)));
+        body.addContent(" - ");
+        body.addContent(htmlWriter.commentTagsToContent(paramTag, null, paramTag.inlineTags(), false));
+        HtmlTree result = HtmlTree.DD(body);
         return result;
     }
 
     /**
      * {@inheritDoc}
      */
-    public TagletOutput seeTagOutput(Doc holder, SeeTag[] seeTags) {
-        String result = "";
+    public Content propertyTagOutput(Tag tag, String prefix) {
+        Content body = new ContentBuilder();
+        body.addContent(new RawHtml(prefix));
+        body.addContent(" ");
+        body.addContent(HtmlTree.CODE(new RawHtml(tag.text())));
+        body.addContent(".");
+        Content result = HtmlTree.P(body);
+        return result;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Content returnTagOutput(Tag returnTag) {
+        ContentBuilder result = new ContentBuilder();
+        result.addContent(HtmlTree.DT(HtmlTree.SPAN(HtmlStyle.strong,
+                new StringContent(configuration.getText("doclet.Returns")))));
+        result.addContent(HtmlTree.DD(htmlWriter.commentTagsToContent(
+                returnTag, null, returnTag.inlineTags(), false)));
+        return result;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Content seeTagOutput(Doc holder, SeeTag[] seeTags) {
+        ContentBuilder body = new ContentBuilder();
         if (seeTags.length > 0) {
-            result = addSeeHeader(result);
             for (int i = 0; i < seeTags.length; ++i) {
-                if (i > 0) {
-                    result += ", " + DocletConstants.NL;
-                }
-                result += htmlWriter.seeTagToString(seeTags[i]);
+                appendSeparatorIfNotEmpty(body);
+                body.addContent(htmlWriter.seeTagToContent(seeTags[i]));
             }
         }
         if (holder.isField() && ((FieldDoc)holder).constantValue() != null &&
                 htmlWriter instanceof ClassWriterImpl) {
             //Automatically add link to constant values page for constant fields.
-            result = addSeeHeader(result);
+            appendSeparatorIfNotEmpty(body);
             DocPath constantsPath =
                     htmlWriter.pathToRoot.resolve(DocPaths.CONSTANT_VALUES);
             String whichConstant =
                     ((ClassWriterImpl) htmlWriter).getClassDoc().qualifiedName() + "." + ((FieldDoc) holder).name();
             DocLink link = constantsPath.fragment(whichConstant);
-            result += htmlWriter.getHyperLinkString(link,
-                    configuration.getText("doclet.Constants_Summary"),
-                    false);
+            body.addContent(htmlWriter.getHyperLink(link,
+                    new StringContent(configuration.getText("doclet.Constants_Summary"))));
         }
         if (holder.isClass() && ((ClassDoc)holder).isSerializable()) {
             //Automatically add link to serialized form page for serializable classes.
             if ((SerializedFormBuilder.serialInclude(holder) &&
                       SerializedFormBuilder.serialInclude(((ClassDoc)holder).containingPackage()))) {
-                result = addSeeHeader(result);
+                appendSeparatorIfNotEmpty(body);
                 DocPath serialPath = htmlWriter.pathToRoot.resolve(DocPaths.SERIALIZED_FORM);
                 DocLink link = serialPath.fragment(((ClassDoc)holder).qualifiedName());
-                result += htmlWriter.getHyperLinkString(link,
-                        configuration.getText("doclet.Serialized_Form"), false);
+                body.addContent(htmlWriter.getHyperLink(link,
+                        new StringContent(configuration.getText("doclet.Serialized_Form"))));
             }
         }
-        return result.equals("") ? null : new TagletOutputImpl(result + "</dd>");
+        if (body.isEmpty())
+            return body;
+
+        ContentBuilder result = new ContentBuilder();
+        result.addContent(HtmlTree.DT(HtmlTree.SPAN(HtmlStyle.strong,
+                new StringContent(configuration.getText("doclet.See_Also")))));
+        result.addContent(HtmlTree.DD(body));
+        return result;
+
     }
 
-    private String addSeeHeader(String result) {
-        if (result != null && result.length() > 0) {
-            return result + ", " + DocletConstants.NL;
-        } else {
-            return "<dt><span class=\"strong\">" +
-                    configuration.getText("doclet.See_Also") + "</span></dt><dd>";
+    private void appendSeparatorIfNotEmpty(ContentBuilder body) {
+        if (!body.isEmpty()) {
+            body.addContent(", ");
+            body.addContent(DocletConstants.NL);
         }
-     }
-
-    /**
-     * {@inheritDoc}
-     */
-    public TagletOutput simpleTagOutput(Tag[] simpleTags, String header) {
-        String result = "<dt><span class=\"strong\">" + header + "</span></dt>" + DocletConstants.NL +
-            "  <dd>";
-        for (int i = 0; i < simpleTags.length; i++) {
-            if (i > 0) {
-                result += ", ";
-            }
-            result += htmlWriter.commentTagsToString(simpleTags[i], null, simpleTags[i].inlineTags(), false);
-        }
-        result += "</dd>" + DocletConstants.NL;
-        return new TagletOutputImpl(result);
     }
 
     /**
      * {@inheritDoc}
      */
-    public TagletOutput simpleTagOutput(Tag simpleTag, String header) {
-        return new TagletOutputImpl("<dt><span class=\"strong\">" + header + "</span></dt>" + "  <dd>"
-            + htmlWriter.commentTagsToString(simpleTag, null, simpleTag.inlineTags(), false)
-            + "</dd>" + DocletConstants.NL);
+    public Content simpleTagOutput(Tag[] simpleTags, String header) {
+        ContentBuilder result = new ContentBuilder();
+        result.addContent(HtmlTree.DT(HtmlTree.SPAN(HtmlStyle.strong, new RawHtml(header))));
+        ContentBuilder body = new ContentBuilder();
+        for (int i = 0; i < simpleTags.length; i++) {
+            if (i > 0) {
+                body.addContent(", ");
+            }
+            body.addContent(htmlWriter.commentTagsToContent(
+                    simpleTags[i], null, simpleTags[i].inlineTags(), false));
+        }
+        result.addContent(HtmlTree.DD(body));
+        return result;
     }
 
     /**
      * {@inheritDoc}
      */
-    public TagletOutput getThrowsHeader() {
-        return new TagletOutputImpl(DocletConstants.NL + "<dt>" + "<span class=\"strong\">" +
-            configuration.getText("doclet.Throws") + "</span></dt>");
+    public Content simpleTagOutput(Tag simpleTag, String header) {
+        ContentBuilder result = new ContentBuilder();
+        result.addContent(HtmlTree.DT(HtmlTree.SPAN(HtmlStyle.strong, new RawHtml(header))));
+        Content body = htmlWriter.commentTagsToContent(
+                simpleTag, null, simpleTag.inlineTags(), false);
+        result.addContent(HtmlTree.DD(body));
+        return result;
     }
 
     /**
      * {@inheritDoc}
      */
-    public TagletOutput throwsTagOutput(ThrowsTag throwsTag) {
-        String result = DocletConstants.NL + "<dd>";
-        result += throwsTag.exceptionType() == null ?
-            htmlWriter.codeText(throwsTag.exceptionName()) :
-            htmlWriter.codeText(
-                htmlWriter.getLink(new LinkInfoImpl(configuration, LinkInfoImpl.CONTEXT_MEMBER,
-                throwsTag.exceptionType())));
-        TagletOutput text = new TagletOutputImpl(
-            htmlWriter.commentTagsToString(throwsTag, null,
-            throwsTag.inlineTags(), false));
-        if (text != null && text.toString().length() > 0) {
-            result += " - " + text;
-        }
-        result += "</dd>";
-        return new TagletOutputImpl(result);
+    public Content getThrowsHeader() {
+        HtmlTree result = HtmlTree.DT(HtmlTree.SPAN(HtmlStyle.strong,
+                new StringContent(configuration.getText("doclet.Throws"))));
+        return result;
     }
 
     /**
      * {@inheritDoc}
      */
-    public TagletOutput throwsTagOutput(Type throwsType) {
-        return new TagletOutputImpl(DocletConstants.NL + "<dd>" +
-            htmlWriter.codeText(htmlWriter.getLink(
-                new LinkInfoImpl(configuration, LinkInfoImpl.CONTEXT_MEMBER, throwsType))) + "</dd>");
+    public Content throwsTagOutput(ThrowsTag throwsTag) {
+        ContentBuilder body = new ContentBuilder();
+        Content excName = (throwsTag.exceptionType() == null) ?
+                new RawHtml(throwsTag.exceptionName()) :
+                htmlWriter.getLink(new LinkInfoImpl(configuration, LinkInfoImpl.Kind.MEMBER,
+                throwsTag.exceptionType()));
+        body.addContent(HtmlTree.CODE(excName));
+        Content desc = htmlWriter.commentTagsToContent(throwsTag, null,
+            throwsTag.inlineTags(), false);
+        if (desc != null && !desc.isEmpty()) {
+            body.addContent(" - ");
+            body.addContent(desc);
+        }
+        HtmlTree result = HtmlTree.DD(body);
+        return result;
     }
 
     /**
      * {@inheritDoc}
      */
-    public TagletOutput valueTagOutput(FieldDoc field, String constantVal,
-            boolean includeLink) {
-        return new TagletOutputImpl(includeLink ?
-            htmlWriter.getDocLink(LinkInfoImpl.CONTEXT_VALUE_TAG, field,
-                constantVal, false) : constantVal);
+    public Content throwsTagOutput(Type throwsType) {
+        HtmlTree result = HtmlTree.DD(HtmlTree.CODE(htmlWriter.getLink(
+                new LinkInfoImpl(configuration, LinkInfoImpl.Kind.MEMBER, throwsType))));
+        return result;
     }
 
     /**
      * {@inheritDoc}
      */
-    public TagletOutput commentTagsToOutput(Tag holderTag, Tag[] tags) {
+    public Content valueTagOutput(FieldDoc field, String constantVal,
+            boolean includeLink) {
+        return includeLink ?
+            htmlWriter.getDocLink(LinkInfoImpl.Kind.VALUE_TAG, field,
+                constantVal, false) : new RawHtml(constantVal);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Content commentTagsToOutput(Tag holderTag, Tag[] tags) {
         return commentTagsToOutput(holderTag, null, tags, false);
     }
 
     /**
      * {@inheritDoc}
      */
-    public TagletOutput commentTagsToOutput(Doc holderDoc, Tag[] tags) {
+    public Content commentTagsToOutput(Doc holderDoc, Tag[] tags) {
         return commentTagsToOutput(null, holderDoc, tags, false);
     }
 
     /**
      * {@inheritDoc}
      */
-    public TagletOutput commentTagsToOutput(Tag holderTag,
+    public Content commentTagsToOutput(Tag holderTag,
         Doc holderDoc, Tag[] tags, boolean isFirstSentence) {
-        return new TagletOutputImpl(htmlWriter.commentTagsToString(
-            holderTag, holderDoc, tags, isFirstSentence));
+        return htmlWriter.commentTagsToContent(
+            holderTag, holderDoc, tags, isFirstSentence);
     }
 
     /**
@@ -307,13 +351,4 @@
     public Configuration configuration() {
         return configuration;
     }
-
-    /**
-     * Return an instance of a TagletWriter that knows how to write HTML.
-     *
-     * @return an instance of a TagletWriter that knows how to write HTML.
-     */
-    public TagletOutput getTagletOutputInstance() {
-        return new TagletOutputImpl("");
-    }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/share/classes/com/sun/tools/doclets/formats/html/markup/ContentBuilder.java	Fri May 17 10:13:34 2013 -0700
@@ -0,0 +1,97 @@
+/*
+ * 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.sun.tools.doclets.formats.html.markup;
+
+import java.io.IOException;
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import com.sun.tools.doclets.internal.toolkit.Content;
+
+/**
+ * A sequence of Content nodes.
+ */
+public class ContentBuilder extends Content {
+    protected List<Content> contents = Collections.<Content>emptyList();
+
+    @Override
+    public void addContent(Content content) {
+        nullCheck(content);
+        if ((content instanceof ContentBuilder) && content.isEmpty())
+            return;
+        ensureMutableContents();
+        if (content instanceof ContentBuilder) {
+            contents.addAll(((ContentBuilder) content).contents);
+        } else
+            contents.add(content);
+    }
+
+    @Override
+    public void addContent(String text) {
+        if (text.isEmpty())
+            return;
+        ensureMutableContents();
+        Content c = contents.isEmpty() ? null : contents.get(contents.size() - 1);
+        StringContent sc;
+        if (c != null && c instanceof StringContent) {
+            sc = (StringContent) c;
+        } else {
+            contents.add(sc = new StringContent());
+        }
+        sc.addContent(text);
+    }
+
+    @Override
+    public boolean write(Writer writer, boolean atNewline) throws IOException {
+        for (Content content: contents) {
+            atNewline = content.write(writer, atNewline);
+        }
+        return atNewline;
+    }
+
+    @Override
+    public boolean isEmpty() {
+        for (Content content: contents) {
+            if (!content.isEmpty())
+                return false;
+        }
+        return true;
+    }
+
+    @Override
+    public int charCount() {
+        int n = 0;
+        for (Content c : contents)
+            n += c.charCount();
+        return n;
+    }
+
+    private void ensureMutableContents() {
+        if (contents.isEmpty())
+            contents = new ArrayList<Content>();
+    }
+}
--- a/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlDocWriter.java	Thu May 16 12:16:07 2013 -0700
+++ b/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlDocWriter.java	Fri May 17 10:13:34 2013 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 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
@@ -34,7 +34,6 @@
 import com.sun.tools.doclets.internal.toolkit.util.DocFile;
 import com.sun.tools.doclets.internal.toolkit.util.DocLink;
 import com.sun.tools.doclets.internal.toolkit.util.DocPath;
-import com.sun.tools.doclets.internal.toolkit.util.DocPaths;
 
 
 /**
@@ -72,43 +71,8 @@
      */
     public abstract Configuration configuration();
 
-    /**
-     * Return Html Hyper Link string.
-     *
-     * @param link       String name of the file.
-     * @param label      Tag for the link.
-     * @param strong       Boolean that sets label to strong.
-     * @return String    Hyper Link.
-     */
-    public String getHyperLinkString(DocPath link,
-                               String label, boolean strong) {
-        return getHyperLinkString(link, label, strong, "", "", "");
-    }
-
-    public String getHyperLinkString(DocLink link,
-                               String label, boolean strong) {
-        return getHyperLinkString(link, label, strong, "", "", "");
-    }
-
-    /**
-     * Get Html Hyper Link string.
-     *
-     * @param link       String name of the file.
-     * @param label      Tag for the link.
-     * @param strong       Boolean that sets label to strong.
-     * @param stylename  String style of text defined in style sheet.
-     * @return String    Hyper Link.
-     */
-    public String getHyperLinkString(DocPath link,
-                               String label, boolean strong,
-                               String stylename) {
-        return getHyperLinkString(link, label, strong, stylename, "", "");
-    }
-
-    public String getHyperLinkString(DocLink link,
-                               String label, boolean strong,
-                               String stylename) {
-        return getHyperLinkString(link, label, strong, stylename, "", "");
+    public Content getHyperLink(DocPath link, String label) {
+        return getHyperLink(link, new StringContent(label), false, "", "", "");
     }
 
     /**
@@ -125,69 +89,47 @@
     }
 
     /**
-     * Get Html Hyper Link string.
+     * Get Html hyperlink.
      *
-     * @param link       String name of the file.
+     * @param link       path of the file.
      * @param label      Tag for the link.
      * @return a content tree for the hyper link
      */
-    public Content getHyperLink(DocPath link,
-                               Content label) {
+    public Content getHyperLink(DocPath link, Content label) {
         return getHyperLink(link, label, "", "");
     }
 
-    public Content getHyperLink(DocLink link,
-                               Content label) {
+    public Content getHyperLink(DocLink link, Content label) {
         return getHyperLink(link, label, "", "");
     }
 
-    /**
-     * Get Html Hyper Link string.
-     *
-     * @param link       String name of the file.
-     * @param label      Tag for the link.
-     * @param strong       Boolean that sets label to strong.
-     * @param stylename  String style of text defined in style sheet.
-     * @param title      String that describes the links content for accessibility.
-     * @param target     Target frame.
-     * @return String    Hyper Link.
-     */
-    public String getHyperLinkString(DocPath link,
-                               String label, boolean strong,
+    public Content getHyperLink(DocPath link,
+                               Content label, boolean strong,
                                String stylename, String title, String target) {
-        return getHyperLinkString(new DocLink(link), label, strong,
+        return getHyperLink(new DocLink(link), label, strong,
                 stylename, title, target);
     }
 
-    public String getHyperLinkString(DocLink link,
-                               String label, boolean strong,
+    public Content getHyperLink(DocLink link,
+                               Content label, boolean strong,
                                String stylename, String title, String target) {
-        StringBuilder retlink = new StringBuilder();
-        retlink.append("<a href=\"").append(link).append('"');
+        Content body = label;
+        if (strong) {
+            body = HtmlTree.SPAN(HtmlStyle.strong, body);
+        }
+        if (stylename != null && stylename.length() != 0) {
+            HtmlTree t = new HtmlTree(HtmlTag.FONT, body);
+            t.addAttr(HtmlAttr.CLASS, stylename);
+            body = t;
+        }
+        HtmlTree l = HtmlTree.A(link.toString(), body);
         if (title != null && title.length() != 0) {
-            retlink.append(" title=\"").append(title).append('"');
+            l.addAttr(HtmlAttr.TITLE, title);
         }
         if (target != null && target.length() != 0) {
-            retlink.append(" target=\"").append(target).append('"');
+            l.addAttr(HtmlAttr.TARGET, target);
         }
-        retlink.append(">");
-        if (stylename != null && stylename.length() != 0) {
-            retlink.append("<FONT CLASS=\"");
-            retlink.append(stylename);
-            retlink.append("\">");
-        }
-        if (strong) {
-            retlink.append("<span class=\"strong\">");
-        }
-        retlink.append(label);
-        if (strong) {
-            retlink.append("</span>");
-        }
-        if (stylename != null && stylename.length() != 0) {
-            retlink.append("</FONT>");
-        }
-        retlink.append("</a>");
-        return retlink.toString();
+        return l;
     }
 
     /**
@@ -217,17 +159,6 @@
     }
 
     /**
-     * Get link string without positioning in the file.
-     *
-     * @param link       String name of the file.
-     * @param label      Tag for the link.
-     * @return Strign    Hyper link.
-     */
-    public String getHyperLinkString(DocPath link, String label) {
-        return getHyperLinkString(link, label, false);
-    }
-
-    /**
      * Get the name of the package, this class is in.
      *
      * @param cd    ClassDoc.
@@ -277,20 +208,6 @@
         write(htmlDocument);
     }
 
-    /**
-     * Print the appropriate spaces to format the class tree in the class page.
-     *
-     * @param len   Number of spaces.
-     */
-    public String spaces(int len) {
-        String space = "";
-
-        for (int i = 0; i < len; i++) {
-            space += " ";
-        }
-        return space;
-    }
-
     protected String getGeneratedByString() {
         Calendar calendar = new GregorianCalendar(TimeZone.getDefault());
         Date today = calendar.getTime();
--- a/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlTag.java	Thu May 16 12:16:07 2013 -0700
+++ b/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlTag.java	Fri May 17 10:13:34 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
@@ -44,6 +44,7 @@
     CENTER,
     CODE(BlockType.INLINE, EndTag.END),
     DD,
+    DIR,
     DIV,
     DL,
     DT,
@@ -63,6 +64,7 @@
     I(BlockType.INLINE, EndTag.END),
     IMG(BlockType.INLINE, EndTag.NOEND),
     LI,
+    LISTING,
     LINK(BlockType.OTHER, EndTag.NOEND),
     MENU,
     META(BlockType.OTHER, EndTag.NOEND),
@@ -75,6 +77,7 @@
     SMALL(BlockType.INLINE, EndTag.END),
     SPAN(BlockType.INLINE, EndTag.END),
     STRONG(BlockType.INLINE, EndTag.END),
+    SUB(BlockType.INLINE, EndTag.END),
     TABLE,
     TBODY,
     TD,
@@ -84,14 +87,14 @@
     TT(BlockType.INLINE, EndTag.END),
     UL;
 
-    protected final BlockType blockType;
-    protected final EndTag endTag;
-    private final String value;
+    public final BlockType blockType;
+    public final EndTag endTag;
+    public final String value;
 
     /**
      * Enum representing the type of HTML element.
      */
-    protected static enum BlockType {
+    public static enum BlockType {
         BLOCK,
         INLINE,
         OTHER;
@@ -100,7 +103,7 @@
     /**
      * Enum representing HTML end tag requirement.
      */
-    protected static enum EndTag {
+    public static enum EndTag {
         END,
         NOEND;
     }
--- a/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlTree.java	Thu May 16 12:16:07 2013 -0700
+++ b/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlTree.java	Fri May 17 10:13:34 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
@@ -78,8 +78,12 @@
      */
     public void addAttr(HtmlAttr attrName, String attrValue) {
         if (attrs.isEmpty())
-            attrs = new LinkedHashMap<HtmlAttr,String>();
-        attrs.put(nullCheck(attrName), nullCheck(attrValue));
+            attrs = new LinkedHashMap<HtmlAttr,String>(3);
+        attrs.put(nullCheck(attrName), escapeHtmlChars(attrValue));
+    }
+
+    public void setTitle(Content body) {
+        addAttr(HtmlAttr.TITLE, stripHtml(body));
     }
 
     /**
@@ -123,6 +127,42 @@
             addContent(new StringContent(stringContent));
     }
 
+    public int charCount() {
+        int n = 0;
+        for (Content c : content)
+            n += c.charCount();
+        return n;
+    }
+
+    /**
+     * Given a string, escape all special html characters and
+     * return the result.
+     *
+     * @param s The string to check.
+     * @return the original string with all of the HTML characters escaped.
+     */
+    private static String escapeHtmlChars(String s) {
+        for (int i = 0; i < s.length(); i++) {
+            char ch = s.charAt(i);
+            switch (ch) {
+                // only start building a new string if we need to
+                case '<': case '>': case '&':
+                    StringBuilder sb = new StringBuilder(s.substring(0, i));
+                    for ( ; i < s.length(); i++) {
+                        ch = s.charAt(i);
+                        switch (ch) {
+                            case '<': sb.append("&lt;");  break;
+                            case '>': sb.append("&gt;");  break;
+                            case '&': sb.append("&amp;"); break;
+                            default:  sb.append(ch);      break;
+                        }
+                    }
+                    return sb.toString();
+            }
+        }
+        return s;
+    }
+
     /**
      * Generates an HTML anchor tag.
      *
@@ -132,7 +172,7 @@
      */
     public static HtmlTree A(String ref, Content body) {
         HtmlTree htmltree = new HtmlTree(HtmlTag.A, nullCheck(body));
-        htmltree.addAttr(HtmlAttr.HREF, nullCheck(ref));
+        htmltree.addAttr(HtmlAttr.HREF, ref);
         return htmltree;
     }
 
@@ -317,7 +357,7 @@
             HtmlStyle styleClass, Content body) {
         HtmlTree htmltree = new HtmlTree(headingTag, nullCheck(body));
         if (printTitle)
-            htmltree.addAttr(HtmlAttr.TITLE, Util.stripHtml(body.toString()));
+            htmltree.setTitle(body);
         if (styleClass != null)
             htmltree.addStyle(styleClass);
         return htmltree;
@@ -802,7 +842,7 @@
         out.write(tagString);
         Iterator<HtmlAttr> iterator = attrs.keySet().iterator();
         HtmlAttr key;
-        String value = "";
+        String value;
         while (iterator.hasNext()) {
             key = iterator.next();
             value = attrs.get(key);
@@ -830,4 +870,22 @@
             return false;
         }
     }
+
+    /**
+     * Given a Content node, strips all html characters and
+     * return the result.
+     *
+     * @param body The content node to check.
+     * @return the plain text from the content node
+     *
+     */
+    private static String stripHtml(Content body) {
+        String rawString = body.toString();
+        // remove HTML tags
+        rawString = rawString.replaceAll("\\<.*?>", " ");
+        // consolidate multiple spaces between a word to a single space
+        rawString = rawString.replaceAll("\\b\\s{2,}\\b", " ");
+        // remove extra whitespaces
+        return rawString.trim();
+    }
 }
--- a/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlWriter.java	Thu May 16 12:16:07 2013 -0700
+++ b/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlWriter.java	Fri May 17 10:13:34 2013 -0700
@@ -27,6 +27,8 @@
 
 import java.io.*;
 import java.util.*;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 import com.sun.tools.doclets.internal.toolkit.*;
 import com.sun.tools.doclets.internal.toolkit.util.*;
@@ -195,8 +197,7 @@
                 configuration.getText("doclet.Modifier"),
                 configuration.getText("doclet.Type"));
         overviewLabel = getResource("doclet.Overview");
-        defaultPackageLabel = new RawHtml(
-                DocletConstants.DEFAULT_PACKAGE_NAME);
+        defaultPackageLabel = new StringContent(DocletConstants.DEFAULT_PACKAGE_NAME);
         packageLabel = getResource("doclet.Package");
         profileLabel = getResource("doclet.Profile");
         useLabel = getResource("doclet.navClassUse");
@@ -252,30 +253,30 @@
      * @return a content tree for the text
      */
     public Content getResource(String key) {
-        return new StringContent(configuration.getText(key));
+        return configuration.getResource(key);
     }
 
     /**
      * Get the configuration string as a content.
      *
      * @param key the key to look for in the configuration file
-     * @param a1 string argument added to configuration text
+     * @param o   string or content argument added to configuration text
      * @return a content tree for the text
      */
-    public Content getResource(String key, String a1) {
-        return new RawHtml(configuration.getText(key, a1));
+    public Content getResource(String key, Object o) {
+        return configuration.getResource(key, o);
     }
 
     /**
      * Get the configuration string as a content.
      *
      * @param key the key to look for in the configuration file
-     * @param a1 string argument added to configuration text
-     * @param a2 string argument added to configuration text
+     * @param o1  string or content argument added to configuration text
+     * @param o2  string or content argument added to configuration text
      * @return a content tree for the text
      */
-    public Content getResource(String key, String a1, String a2) {
-        return new RawHtml(configuration.getText(key, a1, a2));
+    public Content getResource(String key, Object o0, Object o1) {
+        return configuration.getResource(key, o0, o1);
     }
 
     /**
@@ -303,10 +304,11 @@
      *
      * @return a content for the SCRIPT tag
      */
-    protected Content getFramesetJavaScript(){
+    protected Content getFramesetJavaScript() {
         HtmlTree script = new HtmlTree(HtmlTag.SCRIPT);
         script.addAttr(HtmlAttr.TYPE, "text/javascript");
-        String scriptCode = DocletConstants.NL + "    targetPage = \"\" + window.location.search;" + DocletConstants.NL +
+        String scriptCode = DocletConstants.NL +
+                "    targetPage = \"\" + window.location.search;" + DocletConstants.NL +
                 "    if (targetPage != \"\" && targetPage != \"undefined\")" + DocletConstants.NL +
                 "        targetPage = targetPage.substring(1);" + DocletConstants.NL +
                 "    if (targetPage.indexOf(\":\") != -1)" + DocletConstants.NL +
@@ -400,16 +402,6 @@
         return title;
     }
 
-    /**
-     * Return, text passed, with Italics &lt;i&gt; and &lt;/i&gt; tags, surrounding it.
-     * So if the text passed is "Hi", then string returned will be "&lt;i&gt;Hi&lt;/i&gt;".
-     *
-     * @param text String to be printed in between &lt;I&gt; and &lt;/I&gt; tags.
-     */
-    public String italicsText(String text) {
-        return "<i>" + text + "</i>";
-    }
-
     public String codeText(String text) {
         return "<code>" + text + "</code>";
     }
--- a/src/share/classes/com/sun/tools/doclets/formats/html/markup/RawHtml.java	Thu May 16 12:16:07 2013 -0700
+++ b/src/share/classes/com/sun/tools/doclets/formats/html/markup/RawHtml.java	Fri May 17 10:13:34 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
@@ -41,7 +41,7 @@
  *
  * @author Bhavesh Patel
  */
-public class RawHtml extends Content{
+public class RawHtml extends Content {
 
     private String rawHtmlContent;
 
@@ -90,10 +90,65 @@
     /**
      * {@inheritDoc}
      */
+    @Override
     public String toString() {
         return rawHtmlContent;
     }
 
+    private enum State { TEXT, ENTITY, TAG, STRING };
+
+    @Override
+    public int charCount() {
+        return charCount(rawHtmlContent);
+    }
+
+    static int charCount(String htmlText) {
+        State state = State.TEXT;
+        int count = 0;
+        for (int i = 0; i < htmlText.length(); i++) {
+            char c = htmlText.charAt(i);
+            switch (state) {
+                case TEXT:
+                    switch (c) {
+                        case '<':
+                            state = State.TAG;
+                            break;
+                        case '&':
+                            state = State.ENTITY;
+                            count++;
+                            break;
+                        default:
+                            count++;
+                    }
+                    break;
+
+                case ENTITY:
+                    if (!Character.isLetterOrDigit(c))
+                        state = State.TEXT;
+                    break;
+
+                case TAG:
+                    switch (c) {
+                        case '"':
+                            state = State.STRING;
+                            break;
+                        case '>':
+                            state = State.TEXT;
+                            break;
+                    }
+                    break;
+
+                case STRING:
+                    switch (c) {
+                        case '"':
+                            state = State.TAG;
+                            break;
+                    }
+            }
+        }
+        return count;
+    }
+
     /**
      * {@inheritDoc}
      */
--- a/src/share/classes/com/sun/tools/doclets/formats/html/markup/StringContent.java	Thu May 16 12:16:07 2013 -0700
+++ b/src/share/classes/com/sun/tools/doclets/formats/html/markup/StringContent.java	Fri May 17 10:13:34 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
@@ -41,7 +41,7 @@
  *
  * @author Bhavesh Patel
  */
-public class StringContent extends Content{
+public class StringContent extends Content {
 
     private StringBuilder stringContent;
 
@@ -58,8 +58,8 @@
      * @param initialContent initial content for the object
      */
     public StringContent(String initialContent) {
-        stringContent = new StringBuilder(
-                Util.escapeHtmlChars(nullCheck(initialContent)));
+        stringContent = new StringBuilder();
+        appendChars(initialContent);
     }
 
     /**
@@ -81,7 +81,7 @@
      * @param strContent string content to be added
      */
     public void addContent(String strContent) {
-        stringContent.append(Util.escapeHtmlChars(nullCheck(strContent)));
+        appendChars(strContent);
     }
 
     /**
@@ -91,6 +91,10 @@
         return (stringContent.length() == 0);
     }
 
+    public int charCount() {
+        return RawHtml.charCount(stringContent.toString());
+    }
+
     /**
      * {@inheritDoc}
      */
@@ -107,4 +111,16 @@
         out.write(s);
         return s.endsWith(DocletConstants.NL);
     }
+
+    private void appendChars(String s) {
+        for (int i = 0; i < s.length(); i++) {
+            char ch = s.charAt(i);
+            switch (ch) {
+                case '<': stringContent.append("&lt;");  break;
+                case '>': stringContent.append("&gt;");  break;
+                case '&': stringContent.append("&amp;"); break;
+                default:  stringContent.append(ch);      break;
+            }
+        }
+    }
 }
--- a/src/share/classes/com/sun/tools/doclets/formats/html/resources/standard.properties	Thu May 16 12:16:07 2013 -0700
+++ b/src/share/classes/com/sun/tools/doclets/formats/html/resources/standard.properties	Fri May 17 10:13:34 2013 -0700
@@ -132,7 +132,7 @@
 doclet.Help_line_14=Use
 doclet.Help_line_15=Each documented package, class and interface has its own Use page.  This page describes what packages, classes, methods, constructors and fields use any part of the given class or package. Given a class or interface A, its Use page includes subclasses of A, fields declared as A, methods that return A, and methods and constructors with parameters of type A.  You can access this page by first going to the package, class or interface, then clicking on the "Use" link in the navigation bar.
 doclet.Help_line_16=Tree (Class Hierarchy)
-doclet.Help_line_17_with_tree_link=There is a {0} page for all packages, plus a hierarchy for each package. Each hierarchy page contains a list of classes and a list of interfaces. The classes are organized by inheritance structure starting with <code>java.lang.Object</code>. The interfaces do not inherit from <code>java.lang.Object</code>.
+doclet.Help_line_17_with_tree_link=There is a {0} page for all packages, plus a hierarchy for each package. Each hierarchy page contains a list of classes and a list of interfaces. The classes are organized by inheritance structure starting with {1}. The interfaces do not inherit from {1}.
 doclet.Help_line_18=When viewing the Overview page, clicking on "Tree" displays the hierarchy for all packages.
 doclet.Help_line_19=When viewing a particular package, class or interface page, clicking "Tree" displays the hierarchy for only that package.
 doclet.Help_line_20_with_deprecated_api_link=The {0} page lists all of the API that have been deprecated. A deprecated API is not recommended for use, generally due to improvements, and a replacement API is usually given. Deprecated APIs may be removed in future implementations.
@@ -179,7 +179,7 @@
 doclet.ClassUse_ConstructorThrows=Constructors in {1} that throw {0}
 doclet.ClassUse_No.usage.of.0=No usage of {0}
 doclet.Window_ClassUse_Header=Uses of {0} {1}
-doclet.ClassUse_Title=Uses of {0}<br>{1}
+doclet.ClassUse_Title=Uses of {0}
 doclet.navClassUse=Use
 doclet.Error_in_packagelist=Error in using -group option: {0} {1}
 doclet.Groupname_already_used=In -group option, groupname already used: {0}
--- a/src/share/classes/com/sun/tools/doclets/internal/toolkit/Configuration.java	Thu May 16 12:16:07 2013 -0700
+++ b/src/share/classes/com/sun/tools/doclets/internal/toolkit/Configuration.java	Fri May 17 10:13:34 2013 -0700
@@ -27,6 +27,8 @@
 
 import java.io.*;
 import java.util.*;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 import com.sun.javadoc.*;
 import com.sun.tools.javac.sym.Profiles;
@@ -825,6 +827,82 @@
         }
     }
 
+    public abstract Content newContent();
+
+    /**
+     * Get the configuration string as a content.
+     *
+     * @param key the key to look for in the configuration file
+     * @return a content tree for the text
+     */
+    public Content getResource(String key) {
+        Content c = newContent();
+        c.addContent(getText(key));
+        return c;
+    }
+
+    /**
+     * Get the configuration string as a content.
+     *
+     * @param key the key to look for in the configuration file
+     * @param o   string or content argument added to configuration text
+     * @return a content tree for the text
+     */
+    public Content getResource(String key, Object o) {
+        return getResource(key, o, null, null);
+    }
+
+    /**
+     * Get the configuration string as a content.
+     *
+     * @param key the key to look for in the configuration file
+     * @param o   string or content argument added to configuration text
+     * @return a content tree for the text
+     */
+    public Content getResource(String key, Object o1, Object o2) {
+        return getResource(key, o1, o2, null);
+    }
+
+    /**
+     * Get the configuration string as a content.
+     *
+     * @param key the key to look for in the configuration file
+     * @param o1  string or content argument added to configuration text
+     * @param o2  string or content argument added to configuration text
+     * @return a content tree for the text
+     */
+    public Content getResource(String key, Object o0, Object o1, Object o2) {
+        Content c = newContent();
+        Pattern p = Pattern.compile("\\{([012])\\}");
+        String text = getText(key);
+        Matcher m = p.matcher(text);
+        int start = 0;
+        while (m.find(start)) {
+            c.addContent(text.substring(start, m.start()));
+
+            Object o = null;
+            switch (m.group(1).charAt(0)) {
+                case '0': o = o0; break;
+                case '1': o = o1; break;
+                case '2': o = o2; break;
+            }
+
+            if (o == null) {
+                c.addContent("{" + m.group(1) + "}");
+            } else if (o instanceof String) {
+                c.addContent((String) o);
+            } else if (o instanceof Content) {
+                c.addContent((Content) o);
+            }
+
+            start = m.end();
+        }
+
+        c.addContent(text.substring(start));
+        return c;
+    }
+
+
     /**
      * Return true if the ClassDoc element is getting documented, depending upon
      * -nodeprecated option and the deprecation information. Return true if
--- a/src/share/classes/com/sun/tools/doclets/internal/toolkit/Content.java	Thu May 16 12:16:07 2013 -0700
+++ b/src/share/classes/com/sun/tools/doclets/internal/toolkit/Content.java	Fri May 17 10:13:34 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
@@ -97,6 +97,15 @@
     }
 
     /**
+     * Return the number of characters of plain text content in this object
+     * (optional operation.)
+     * @return the number of characters of plain text content in this
+     */
+    public int charCount() {
+        return 0;
+    }
+
+    /**
      * Checks for null values.
      *
      * @param t reference type to check for null values
@@ -106,32 +115,4 @@
         t.getClass();
         return t;
     }
-
-    /**
-     * Returns true if the content ends with a newline character. Empty content
-     * is considered as ending with new line.
-     *
-     * @param contentBuilder content to test for newline character at the end
-     * @return true if the content ends with newline.
-     */
-    protected boolean endsWithNewLine(StringBuilder contentBuilder) {
-        int contentLength = contentBuilder.length();
-        if (contentLength == 0) {
-            return true;
-        }
-        int nlLength = DocletConstants.NL.length();
-        if (contentLength < nlLength) {
-            return false;
-        }
-        int contentIndex = contentLength - 1;
-        int nlIndex = nlLength - 1;
-        while (nlIndex >= 0) {
-            if (contentBuilder.charAt(contentIndex) != DocletConstants.NL.charAt(nlIndex)) {
-                return false;
-            }
-            contentIndex--;
-            nlIndex--;
-        }
-        return true;
-    }
 }
--- a/src/share/classes/com/sun/tools/doclets/internal/toolkit/builders/PackageSummaryBuilder.java	Thu May 16 12:16:07 2013 -0700
+++ b/src/share/classes/com/sun/tools/doclets/internal/toolkit/builders/PackageSummaryBuilder.java	Fri May 17 10:13:34 2013 -0700
@@ -120,8 +120,7 @@
      * @param contentTree the content tree to which the documentation will be added
      */
     public void buildPackageDoc(XMLNode node, Content contentTree) throws Exception {
-        contentTree = packageWriter.getPackageHeader(
-                Util.getPackageName(packageDoc));
+        contentTree = packageWriter.getPackageHeader(Util.getPackageName(packageDoc));
         buildChildren(node, contentTree);
         packageWriter.addPackageFooter(contentTree);
         packageWriter.printDocument(contentTree);
--- a/src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/BasePropertyTaglet.java	Thu May 16 12:16:07 2013 -0700
+++ b/src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/BasePropertyTaglet.java	Fri May 17 10:13:34 2013 -0700
@@ -26,6 +26,7 @@
 package com.sun.tools.doclets.internal.toolkit.taglets;
 
 import com.sun.javadoc.Tag;
+import com.sun.tools.doclets.internal.toolkit.Content;
 
 /**
  * An abstract class that implements the {@link Taglet} interface and
@@ -59,15 +60,8 @@
      * @param tagletWriter the taglet writer for output.
      * @return the TagletOutput representation of this <code>Tag</code>.
      */
-    public TagletOutput getTagletOutput(Tag tag, TagletWriter tagletWriter) {
-        TagletOutput tagletOutput = tagletWriter.getOutputInstance();
-        StringBuilder output = new StringBuilder("<P>");
-        output.append(getText(tagletWriter));
-        output.append(" <CODE>");
-        output.append(tag.text());
-        output.append("</CODE>.</P>");
-        tagletOutput.setOutput(output.toString());
-        return tagletOutput;
+    public Content getTagletOutput(Tag tag, TagletWriter tagletWriter) {
+        return tagletWriter.propertyTagOutput(tag, getText(tagletWriter));
     }
 
     /**
--- a/src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/BaseTaglet.java	Thu May 16 12:16:07 2013 -0700
+++ b/src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/BaseTaglet.java	Fri May 17 10:13:34 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,6 +26,7 @@
 package com.sun.tools.doclets.internal.toolkit.taglets;
 
 import com.sun.javadoc.*;
+import com.sun.tools.doclets.internal.toolkit.Content;
 
 /**
  * An abstract class for that implements the {@link Taglet} interface.
@@ -130,7 +131,7 @@
      * {@inheritDoc}
      * @throws IllegalArgumentException thrown when the method is not supported by the taglet.
      */
-    public TagletOutput getTagletOutput(Tag tag, TagletWriter writer) {
+    public Content getTagletOutput(Tag tag, TagletWriter writer) {
         throw new IllegalArgumentException("Method not supported in taglet " + getName() + ".");
     }
 
@@ -138,7 +139,7 @@
      * {@inheritDoc}
      * @throws IllegalArgumentException thrown when the method is not supported by the taglet.
      */
-    public TagletOutput getTagletOutput(Doc holder, TagletWriter writer) {
+    public Content getTagletOutput(Doc holder, TagletWriter writer) {
         throw new IllegalArgumentException("Method not supported in taglet " + getName() + ".");
     }
 }
--- a/src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/CodeTaglet.java	Thu May 16 12:16:07 2013 -0700
+++ b/src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/CodeTaglet.java	Fri May 17 10:13:34 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,7 @@
 
 import java.util.Map;
 import com.sun.javadoc.Tag;
-import com.sun.tools.doclets.Taglet;
+import com.sun.tools.doclets.internal.toolkit.Content;
 
 /**
  * An inline Taglet used to denote literal code fragments.
@@ -49,23 +49,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 Content getTagletOutput(Tag tag, TagletWriter writer) {
+        return writer.codeTagOutput(tag);
+    }
 }
--- a/src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/DeprecatedTaglet.java	Thu May 16 12:16:07 2013 -0700
+++ b/src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/DeprecatedTaglet.java	Fri May 17 10:13:34 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,6 +26,7 @@
 package com.sun.tools.doclets.internal.toolkit.taglets;
 
 import com.sun.javadoc.*;
+import com.sun.tools.doclets.internal.toolkit.Content;
 
 /**
  * A taglet that represents the @deprecated tag.
@@ -48,7 +49,7 @@
     /**
      * {@inheritDoc}
      */
-    public TagletOutput getTagletOutput(Doc holder, TagletWriter writer) {
+    public Content getTagletOutput(Doc holder, TagletWriter writer) {
         return writer.deprecatedTagOutput(holder);
     }
 }
--- a/src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/DocRootTaglet.java	Thu May 16 12:16:07 2013 -0700
+++ b/src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/DocRootTaglet.java	Fri May 17 10:13:34 2013 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 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,6 +26,7 @@
 package com.sun.tools.doclets.internal.toolkit.taglets;
 
 import com.sun.javadoc.*;
+import com.sun.tools.doclets.internal.toolkit.Content;
 
 /**
  * An inline Taglet representing {&#064;docRoot}.  This taglet is
@@ -60,7 +61,7 @@
      * @param writer a {@link TagletWriter} Taglet writer.
      * @return the string representation of this <code>Tag</code>.
      */
-    public TagletOutput getTagletOutput(Tag tag, TagletWriter writer) {
+    public Content getTagletOutput(Tag tag, TagletWriter writer) {
         return writer.getDocRootOutput();
     }
 }
--- a/src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/ExpertTaglet.java	Thu May 16 12:16:07 2013 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,106 +0,0 @@
-/*
- * 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
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-package com.sun.tools.doclets.internal.toolkit.taglets;
-
-import java.util.Map;
-
-import com.sun.tools.doclets.Taglet;
-import com.sun.javadoc.Tag;
-
-/**
- * An inline Taglet used to denote information for experts.
- *
- *  <p><b>This is NOT part of any supported API.
- *  If you write code that depends on this, you do so at your own risk.
- *  This code and its internal interfaces are subject to change or
- *  deletion without notice.</b>
- *
- */
-public class ExpertTaglet implements Taglet {
-
-    private static final String NAME = "expert";
-    private static final String START_TAG = "<sub id=\"expert\">";
-    private static final String END_TAG = "</sub>";
-
-    /**
-     * {@inheritDoc}
-     */
-    public boolean inField() {
-        return true;
-    }
-
-    public boolean inConstructor() {
-        return true;
-    }
-
-    public boolean inMethod() {
-        return true;
-    }
-
-    public boolean inOverview() {
-        return true;
-    }
-
-    public boolean inPackage() {
-        return true;
-    }
-
-    public boolean inType() {
-        return true;
-    }
-
-    public boolean isInlineTag() {
-        return false;
-    }
-
-    public String getName() {
-        return NAME;
-    }
-
-    public static void register(Map<String, Taglet> map) {
-        map.remove(NAME);
-        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;
-    }
-
-
-    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/src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/InheritDocTaglet.java	Thu May 16 12:16:07 2013 -0700
+++ b/src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/InheritDocTaglet.java	Fri May 17 10:13:34 2013 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 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
@@ -27,6 +27,7 @@
 
 import com.sun.javadoc.*;
 import com.sun.tools.doclets.internal.toolkit.Configuration;
+import com.sun.tools.doclets.internal.toolkit.Content;
 import com.sun.tools.doclets.internal.toolkit.util.*;
 
 /**
@@ -60,8 +61,8 @@
 
     /**
      * Will return false because this inline tag may
-     * only appear in Methods.
-     * @return false since this is not a method.
+     * not appear in Fields.
+     * @return false
      */
     public boolean inField() {
         return false;
@@ -69,8 +70,8 @@
 
     /**
      * Will return false because this inline tag may
-     * only appear in Methods.
-     * @return false since this is not a method.
+     * not appear in Constructors.
+     * @return false
      */
     public boolean inConstructor() {
         return false;
@@ -78,8 +79,8 @@
 
     /**
      * Will return false because this inline tag may
-     * only appear in Methods.
-     * @return false since this is not a method.
+     * not appear in Overview.
+     * @return false
      */
     public boolean inOverview() {
         return false;
@@ -87,20 +88,20 @@
 
     /**
      * Will return false because this inline tag may
-     * only appear in Methods.
-     * @return false since this is not a method.
+     * not appear in Packages.
+     * @return false
      */
     public boolean inPackage() {
         return false;
     }
 
     /**
-     * Will return false because this inline tag may
-     * only appear in Methods.
-     * @return false since this is not a method.
+     * Will return true because this inline tag may
+     * appear in Type (Class).
+     * @return true
      */
     public boolean inType() {
-        return false;
+        return true;
     }
 
     /**
@@ -109,33 +110,44 @@
      * of @inheritDoc with documentation from it's superclass or superinterface.
      *
      * @param writer the writer that is writing the output.
-     * @param md the {@link MethodDoc} that we are documenting.
-     * @param holderTag the tag that holds the inheritDoc tag.
+     * @param ped the {@link ProgramElementDoc} that we are documenting.
+     * @param holderTag the tag that holds the inheritDoc tag or null for type
+     * (class) docs.
      * @param isFirstSentence true if we only want to inherit the first sentence.
      */
-    private TagletOutput retrieveInheritedDocumentation(TagletWriter writer,
-            MethodDoc md, Tag holderTag, boolean isFirstSentence) {
-        TagletOutput replacement = writer.getTagletOutputInstance();
+    private Content retrieveInheritedDocumentation(TagletWriter writer,
+            ProgramElementDoc ped, Tag holderTag, boolean isFirstSentence) {
+        Content replacement = writer.getOutputInstance();
 
         Configuration configuration = writer.configuration();
         Taglet inheritableTaglet = holderTag == null ?
             null : configuration.tagletManager.getTaglet(holderTag.name());
         if (inheritableTaglet != null &&
             !(inheritableTaglet instanceof InheritableTaglet)) {
+                String message = ped.name() +
+                    ((ped instanceof ExecutableMemberDoc)
+                        ? ((ExecutableMemberDoc)ped).flatSignature()
+                        : "");
                 //This tag does not support inheritence.
-                configuration.message.warning(md.position(),
-                "doclet.noInheritedDoc", md.name() + md.flatSignature());
+                configuration.message.warning(ped.position(),
+                "doclet.noInheritedDoc", message);
          }
         DocFinder.Output inheritedDoc =
-            DocFinder.search(new DocFinder.Input(md,
+            DocFinder.search(new DocFinder.Input(ped,
                 (InheritableTaglet) inheritableTaglet, holderTag,
                 isFirstSentence, true));
-        if (inheritedDoc.isValidInheritDocTag == false) {
-            configuration.message.warning(md.position(),
-                "doclet.noInheritedDoc", md.name() + md.flatSignature());
-        } else if (inheritedDoc.inlineTags.length > 0) {
-            replacement = writer.commentTagsToOutput(inheritedDoc.holderTag,
-                inheritedDoc.holder, inheritedDoc.inlineTags, isFirstSentence);
+        if (inheritedDoc.isValidInheritDocTag) {
+            if (inheritedDoc.inlineTags.length > 0) {
+                replacement = writer.commentTagsToOutput(inheritedDoc.holderTag,
+                    inheritedDoc.holder, inheritedDoc.inlineTags, isFirstSentence);
+            }
+        } else {
+            String message = ped.name() +
+                    ((ped instanceof ExecutableMemberDoc)
+                        ? ((ExecutableMemberDoc)ped).flatSignature()
+                        : "");
+            configuration.message.warning(ped.position(),
+                "doclet.noInheritedDoc", message);
         }
         return replacement;
     }
@@ -146,14 +158,14 @@
      * to the generated page.
      * @param tag the <code>Tag</code> representation of this custom tag.
      * @param tagletWriter the taglet writer for output.
-     * @return the TagletOutput representation of this <code>Tag</code>.
+     * @return the Content representation of this <code>Tag</code>.
      */
-    public TagletOutput getTagletOutput(Tag tag, TagletWriter tagletWriter) {
-        if (! (tag.holder() instanceof MethodDoc)) {
+    public Content getTagletOutput(Tag tag, TagletWriter tagletWriter) {
+        if (! (tag.holder() instanceof ProgramElementDoc)) {
             return tagletWriter.getOutputInstance();
         }
         return tag.name().equals("@inheritDoc") ?
-                retrieveInheritedDocumentation(tagletWriter, (MethodDoc) tag.holder(), null, tagletWriter.isFirstSentence) :
-                retrieveInheritedDocumentation(tagletWriter, (MethodDoc) tag.holder(), tag, tagletWriter.isFirstSentence);
+                retrieveInheritedDocumentation(tagletWriter, (ProgramElementDoc) tag.holder(), null, tagletWriter.isFirstSentence) :
+                retrieveInheritedDocumentation(tagletWriter, (ProgramElementDoc) tag.holder(), tag, tagletWriter.isFirstSentence);
     }
 }
--- a/src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/LegacyTaglet.java	Thu May 16 12:16:07 2013 -0700
+++ b/src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/LegacyTaglet.java	Fri May 17 10:13:34 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,6 +26,8 @@
 package com.sun.tools.doclets.internal.toolkit.taglets;
 
 import com.sun.javadoc.*;
+import com.sun.tools.doclets.formats.html.markup.RawHtml;
+import com.sun.tools.doclets.internal.toolkit.Content;
 
 /**
  * This taglet acts as a wrapper to enable
@@ -115,20 +117,20 @@
     /**
      * {@inheritDoc}
      */
-    public TagletOutput getTagletOutput(Tag tag, TagletWriter writer)
+    public Content getTagletOutput(Tag tag, TagletWriter writer)
             throws IllegalArgumentException {
-        TagletOutput output = writer.getOutputInstance();
-        output.setOutput(legacyTaglet.toString(tag));
+        Content output = writer.getOutputInstance();
+        output.addContent(new RawHtml(legacyTaglet.toString(tag)));
         return output;
     }
 
     /**
      * {@inheritDoc}
      */
-    public TagletOutput getTagletOutput(Doc holder, TagletWriter writer)
+    public Content getTagletOutput(Doc holder, TagletWriter writer)
             throws IllegalArgumentException {
-        TagletOutput output = writer.getOutputInstance();
-        output.setOutput(legacyTaglet.toString(holder.tags(getName())));
+        Content output = writer.getOutputInstance();
+        output.addContent(new RawHtml(legacyTaglet.toString(holder.tags(getName()))));
         return output;
     }
 }
--- a/src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/LiteralTaglet.java	Thu May 16 12:16:07 2013 -0700
+++ b/src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/LiteralTaglet.java	Fri May 17 10:13:34 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.Tag;
-import com.sun.tools.doclets.Taglet;
+import com.sun.tools.doclets.internal.toolkit.Content;
 
 
 /**
@@ -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 Content getTagletOutput(Tag tag, TagletWriter writer) {
+        return writer.literalTagOutput(tag);
     }
 }
--- a/src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/ParamTaglet.java	Thu May 16 12:16:07 2013 -0700
+++ b/src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/ParamTaglet.java	Fri May 17 10:13:34 2013 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 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
@@ -28,6 +28,7 @@
 import java.util.*;
 
 import com.sun.javadoc.*;
+import com.sun.tools.doclets.internal.toolkit.Content;
 import com.sun.tools.doclets.internal.toolkit.util.*;
 
 /**
@@ -101,14 +102,14 @@
             }
         }
         ParamTag[] tags = input.isTypeVariableParamTag ?
-            input.method.typeParamTags() : input.method.paramTags();
+            ((MethodDoc)input.element).typeParamTags() : ((MethodDoc)input.element).paramTags();
         Map<String, String> rankMap = getRankMap(input.isTypeVariableParamTag ?
-            (Object[]) input.method.typeParameters() :
-            (Object[]) input.method.parameters());
+            (Object[]) ((MethodDoc)input.element).typeParameters() :
+            (Object[]) ((MethodDoc)input.element).parameters());
         for (int i = 0; i < tags.length; i++) {
             if (rankMap.containsKey(tags[i].parameterName()) &&
                     rankMap.get(tags[i].parameterName()).equals((input.tagId))) {
-                output.holder = input.method;
+                output.holder = input.element;
                 output.holderTag = tags[i];
                 output.inlineTags = input.isFirstSentence ?
                     tags[i].firstSentenceTags() : tags[i].inlineTags();
@@ -165,12 +166,12 @@
      * @param writer the TagletWriter that will write this tag.
      * @return the TagletOutput representation of these <code>ParamTag</code>s.
      */
-    public TagletOutput getTagletOutput(Doc holder, TagletWriter writer) {
+    public Content getTagletOutput(Doc holder, TagletWriter writer) {
         if (holder instanceof ExecutableMemberDoc) {
             ExecutableMemberDoc member = (ExecutableMemberDoc) holder;
-            TagletOutput output = getTagletOutput(false, member, writer,
+            Content output = getTagletOutput(false, member, writer,
                 member.typeParameters(), member.typeParamTags());
-            output.appendOutput(getTagletOutput(true, member, writer,
+            output.addContent(getTagletOutput(true, member, writer,
                 member.parameters(), member.paramTags()));
             return output;
         } else {
@@ -191,12 +192,12 @@
      *
      * @return the TagletOutput representation of these <code>ParamTag</code>s.
      */
-    private TagletOutput getTagletOutput(boolean isNonTypeParams, Doc holder,
+    private Content getTagletOutput(boolean isNonTypeParams, Doc holder,
             TagletWriter writer, Object[] formalParameters, ParamTag[] paramTags) {
-        TagletOutput result = writer.getOutputInstance();
+        Content result = writer.getOutputInstance();
         Set<String> alreadyDocumented = new HashSet<String>();
         if (paramTags.length > 0) {
-            result.appendOutput(
+            result.addContent(
                 processParamTags(isNonTypeParams, paramTags,
                 getRankMap(formalParameters), writer, alreadyDocumented)
             );
@@ -204,7 +205,7 @@
         if (alreadyDocumented.size() != formalParameters.length) {
             //Some parameters are missing corresponding @param tags.
             //Try to inherit them.
-            result.appendOutput(getInheritedTagletOutput (isNonTypeParams, holder,
+            result.addContent(getInheritedTagletOutput (isNonTypeParams, holder,
                 writer, formalParameters, alreadyDocumented));
         }
         return result;
@@ -214,10 +215,10 @@
      * Loop through each indivitual parameter.  It it does not have a
      * corresponding param tag, try to inherit it.
      */
-    private TagletOutput getInheritedTagletOutput(boolean isNonTypeParams, Doc holder,
+    private Content getInheritedTagletOutput(boolean isNonTypeParams, Doc holder,
             TagletWriter writer, Object[] formalParameters,
             Set<String> alreadyDocumented) {
-        TagletOutput result = writer.getOutputInstance();
+        Content result = writer.getOutputInstance();
         if ((! alreadyDocumented.contains(null)) &&
                 holder instanceof MethodDoc) {
             for (int i = 0; i < formalParameters.length; i++) {
@@ -231,7 +232,7 @@
                         String.valueOf(i), ! isNonTypeParams));
                 if (inheritedDoc.inlineTags != null &&
                         inheritedDoc.inlineTags.length > 0) {
-                    result.appendOutput(
+                    result.addContent(
                         processParamTag(isNonTypeParams, writer,
                             (ParamTag) inheritedDoc.holderTag,
                             isNonTypeParams ?
@@ -261,12 +262,12 @@
      *                of a rank of a parameter to its name.  This is
      *                used to ensure that the right name is used
      *                when parameter documentation is inherited.
-     * @return the TagletOutput representation of this <code>Tag</code>.
+     * @return the Content representation of this <code>Tag</code>.
      */
-    private TagletOutput processParamTags(boolean isNonTypeParams,
+    private Content processParamTags(boolean isNonTypeParams,
             ParamTag[] paramTags, Map<String, String> rankMap, TagletWriter writer,
             Set<String> alreadyDocumented) {
-        TagletOutput result = writer.getOutputInstance();
+        Content result = writer.getOutputInstance();
         if (paramTags.length > 0) {
             for (int i = 0; i < paramTags.length; ++i) {
                 ParamTag pt = paramTags[i];
@@ -287,7 +288,7 @@
                            "doclet.Type_Parameters_dup_warn",
                        paramName);
                 }
-                result.appendOutput(processParamTag(isNonTypeParams, writer, pt,
+                result.addContent(processParamTag(isNonTypeParams, writer, pt,
                      pt.parameterName(), alreadyDocumented.size() == 0));
                 alreadyDocumented.add(rank);
             }
@@ -295,7 +296,7 @@
         return result;
     }
     /**
-     * Convert the individual ParamTag into TagletOutput.
+     * Convert the individual ParamTag into Content.
      *
      * @param isNonTypeParams true if this is just a regular param tag.  False
      *                        if this is a type param tag.
@@ -307,16 +308,16 @@
      * @param isFirstParam    true if this is the first param tag being printed.
      *
      */
-    private TagletOutput processParamTag(boolean isNonTypeParams,
+    private Content processParamTag(boolean isNonTypeParams,
             TagletWriter writer, ParamTag paramTag, String name,
             boolean isFirstParam) {
-        TagletOutput result = writer.getOutputInstance();
+        Content result = writer.getOutputInstance();
         String header = writer.configuration().getText(
             isNonTypeParams ? "doclet.Parameters" : "doclet.TypeParameters");
         if (isFirstParam) {
-            result.appendOutput(writer.getParamHeader(header));
+            result.addContent(writer.getParamHeader(header));
         }
-        result.appendOutput(writer.paramTagOutput(paramTag,
+        result.addContent(writer.paramTagOutput(paramTag,
             name));
         return result;
     }
--- a/src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/ReturnTaglet.java	Thu May 16 12:16:07 2013 -0700
+++ b/src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/ReturnTaglet.java	Fri May 17 10:13:34 2013 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 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,6 +26,7 @@
 package com.sun.tools.doclets.internal.toolkit.taglets;
 
 import com.sun.javadoc.*;
+import com.sun.tools.doclets.internal.toolkit.Content;
 import com.sun.tools.doclets.internal.toolkit.util.*;
 
 /**
@@ -50,9 +51,9 @@
      * {@inheritDoc}
      */
     public void inherit(DocFinder.Input input, DocFinder.Output output) {
-       Tag[] tags = input.method.tags("return");
+       Tag[] tags = input.element.tags("return");
         if (tags.length > 0) {
-            output.holder = input.method;
+            output.holder = input.element;
             output.holderTag = tags[0];
             output.inlineTags = input.isFirstSentence ?
                 tags[0].firstSentenceTags() : tags[0].inlineTags();
@@ -73,7 +74,7 @@
     /**
      * {@inheritDoc}
      */
-    public TagletOutput getTagletOutput(Doc holder, TagletWriter writer) {
+    public Content getTagletOutput(Doc holder, TagletWriter writer) {
         Type returnType = ((MethodDoc) holder).returnType();
         Tag[] tags = holder.tags(name);
 
--- a/src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/SeeTaglet.java	Thu May 16 12:16:07 2013 -0700
+++ b/src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/SeeTaglet.java	Fri May 17 10:13:34 2013 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 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,6 +26,7 @@
 package com.sun.tools.doclets.internal.toolkit.taglets;
 
 import com.sun.javadoc.*;
+import com.sun.tools.doclets.internal.toolkit.Content;
 import com.sun.tools.doclets.internal.toolkit.util.*;
 
 /**
@@ -49,9 +50,9 @@
      * {@inheritDoc}
      */
     public void inherit(DocFinder.Input input, DocFinder.Output output) {
-        Tag[] tags = input.method.seeTags();
+        Tag[] tags = input.element.seeTags();
         if (tags.length > 0) {
-            output.holder = input.method;
+            output.holder = input.element;
             output.holderTag = tags[0];
             output.inlineTags = input.isFirstSentence ?
                 tags[0].firstSentenceTags() : tags[0].inlineTags();
@@ -61,7 +62,7 @@
     /**
      * {@inheritDoc}
      */
-    public TagletOutput getTagletOutput(Doc holder, TagletWriter writer) {
+    public Content getTagletOutput(Doc holder, TagletWriter writer) {
         SeeTag[] tags = holder.seeTags();
         if (tags.length == 0 && holder instanceof MethodDoc) {
             DocFinder.Output inheritedDoc =
--- a/src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/SimpleTaglet.java	Thu May 16 12:16:07 2013 -0700
+++ b/src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/SimpleTaglet.java	Fri May 17 10:13:34 2013 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 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,6 +26,8 @@
 package com.sun.tools.doclets.internal.toolkit.taglets;
 
 import com.sun.javadoc.*;
+import com.sun.tools.doclets.internal.toolkit.Content;
+import com.sun.tools.doclets.internal.toolkit.util.DocFinder;
 
 /**
  * A simple single argument custom tag.
@@ -38,7 +40,7 @@
  * @author Jamie Ho
  */
 
-public class SimpleTaglet extends BaseTaglet {
+public class SimpleTaglet extends BaseTaglet implements InheritableTaglet {
 
     /**
      * The marker in the location string for excluded tags.
@@ -199,17 +201,28 @@
         return false;
     }
 
+    @Override
+    public void inherit(DocFinder.Input input, DocFinder.Output output) {
+        Tag[] tags = input.element.tags(tagName);
+        if (tags.length > 0) {
+            output.holder = input.element;
+            output.holderTag = tags[0];
+            output.inlineTags = input.isFirstSentence
+                    ? tags[0].firstSentenceTags() : tags[0].inlineTags();
+        }
+    }
+
     /**
      * {@inheritDoc}
      */
-    public TagletOutput getTagletOutput(Tag tag, TagletWriter writer) {
+    public Content getTagletOutput(Tag tag, TagletWriter writer) {
         return header == null || tag == null ? null : writer.simpleTagOutput(tag, header);
     }
 
     /**
      * {@inheritDoc}
      */
-    public TagletOutput getTagletOutput(Doc holder, TagletWriter writer) {
+    public Content getTagletOutput(Doc holder, TagletWriter writer) {
         if (header == null || holder.tags(getName()).length == 0) {
             return null;
         }
--- a/src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/Taglet.java	Thu May 16 12:16:07 2013 -0700
+++ b/src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/Taglet.java	Fri May 17 10:13:34 2013 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 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,6 +26,7 @@
 package com.sun.tools.doclets.internal.toolkit.taglets;
 
 import com.sun.javadoc.*;
+import com.sun.tools.doclets.internal.toolkit.Content;
 
 /**
  * The interface for a custom tag used by Doclets. A custom
@@ -132,14 +133,14 @@
 
     /**
      * Given the <code>Tag</code> representation of this custom
-     * tag, return its TagletOutput representation, which is output
+     * tag, return its Content representation, which is output
      * to the generated page.
      * @param tag the <code>Tag</code> representation of this custom tag.
      * @param writer a {@link TagletWriter} Taglet writer.
      * @throws IllegalArgumentException thrown when the method is not supported by the taglet.
-     * @return the TagletOutput representation of this <code>Tag</code>.
+     * @return the Content representation of this <code>Tag</code>.
      */
-    public abstract TagletOutput getTagletOutput(Tag tag, TagletWriter writer) throws IllegalArgumentException;
+    public abstract Content getTagletOutput(Tag tag, TagletWriter writer) throws IllegalArgumentException;
 
     /**
      * Given a <code>Doc</code> object, check if it holds any tags of
@@ -150,6 +151,8 @@
      * @throws IllegalArgumentException thrown when the method is not supported by the taglet.
      * @return the TagletOutput representation of this <code>Tag</code>.
      */
-    public abstract TagletOutput getTagletOutput(Doc holder, TagletWriter writer) throws IllegalArgumentException;
+    public abstract Content getTagletOutput(Doc holder, TagletWriter writer) throws IllegalArgumentException;
 
+    @Override
+    public abstract String toString();
 }
--- a/src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/TagletManager.java	Thu May 16 12:16:07 2013 -0700
+++ b/src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/TagletManager.java	Fri May 17 10:13:34 2013 -0700
@@ -158,8 +158,7 @@
 
     /**
      * True if we want to use JavaFX-related tags (@propertyGetter,
-     * @propertySetter, @propertyDescription, @defaultValue, @treatAsPrivate,
-     * @expert).
+     * @propertySetter, @propertyDescription, @defaultValue, @treatAsPrivate).
      */
     private boolean javafx;
 
@@ -184,7 +183,7 @@
         this.showauthor = showauthor;
         this.javafx = javafx;
         this.message = message;
-        initStandardTags();
+        initStandardTaglets();
         initStandardTagsLowercase();
     }
 
@@ -454,9 +453,9 @@
      * @return the array of <code>Taglet</code>s that can
      * appear in packages.
      */
-    public Taglet[] getPackageCustomTags() {
+    public Taglet[] getPackageCustomTaglets() {
         if (packageTags == null) {
-            initCustomTagArrays();
+            initCustomTagletArrays();
         }
         return packageTags;
     }
@@ -467,9 +466,9 @@
      * @return the array of <code>Taglet</code>s that can
      * appear in classes or interfaces.
      */
-    public Taglet[] getTypeCustomTags() {
+    public Taglet[] getTypeCustomTaglets() {
         if (typeTags == null) {
-            initCustomTagArrays();
+            initCustomTagletArrays();
         }
         return typeTags;
     }
@@ -480,9 +479,9 @@
      * @return the array of <code>Taglet</code>s that can
      * appear in comments.
      */
-    public Taglet[] getInlineCustomTags() {
+    public Taglet[] getInlineCustomTaglets() {
         if (inlineTags == null) {
-            initCustomTagArrays();
+            initCustomTagletArrays();
         }
         return inlineTags;
     }
@@ -493,9 +492,9 @@
      * @return the array of <code>Taglet</code>s that can
      * appear in field.
      */
-    public Taglet[] getFieldCustomTags() {
+    public Taglet[] getFieldCustomTaglets() {
         if (fieldTags == null) {
-            initCustomTagArrays();
+            initCustomTagletArrays();
         }
         return fieldTags;
     }
@@ -506,9 +505,9 @@
      * @return the array of <code>Taglet</code>s that can
      * appear in the serialized form.
      */
-    public Taglet[] getSerializedFormTags() {
+    public Taglet[] getSerializedFormTaglets() {
         if (serializedFormTags == null) {
-            initCustomTagArrays();
+            initCustomTagletArrays();
         }
         return serializedFormTags;
     }
@@ -517,19 +516,19 @@
      * @return the array of <code>Taglet</code>s that can
      * appear in the given Doc.
      */
-    public Taglet[] getCustomTags(Doc doc) {
+    public Taglet[] getCustomTaglets(Doc doc) {
         if (doc instanceof ConstructorDoc) {
-            return getConstructorCustomTags();
+            return getConstructorCustomTaglets();
         } else if (doc instanceof MethodDoc) {
-            return getMethodCustomTags();
+            return getMethodCustomTaglets();
         } else if (doc instanceof FieldDoc) {
-            return getFieldCustomTags();
+            return getFieldCustomTaglets();
         } else if (doc instanceof ClassDoc) {
-            return getTypeCustomTags();
+            return getTypeCustomTaglets();
         } else if (doc instanceof PackageDoc) {
-            return getPackageCustomTags();
+            return getPackageCustomTaglets();
         } else if (doc instanceof RootDoc) {
-            return getOverviewCustomTags();
+            return getOverviewCustomTaglets();
         }
         return null;
     }
@@ -540,9 +539,9 @@
      * @return the array of <code>Taglet</code>s that can
      * appear in constructors.
      */
-    public Taglet[] getConstructorCustomTags() {
+    public Taglet[] getConstructorCustomTaglets() {
         if (constructorTags == null) {
-            initCustomTagArrays();
+            initCustomTagletArrays();
         }
         return constructorTags;
     }
@@ -553,9 +552,9 @@
      * @return the array of <code>Taglet</code>s that can
      * appear in methods.
      */
-    public Taglet[] getMethodCustomTags() {
+    public Taglet[] getMethodCustomTaglets() {
         if (methodTags == null) {
-            initCustomTagArrays();
+            initCustomTagletArrays();
         }
         return methodTags;
     }
@@ -566,9 +565,9 @@
      * @return the array of <code>Taglet</code>s that can
      * appear in overview.
      */
-    public Taglet[] getOverviewCustomTags() {
+    public Taglet[] getOverviewCustomTaglets() {
         if (overviewTags == null) {
-            initCustomTagArrays();
+            initCustomTagletArrays();
         }
         return overviewTags;
     }
@@ -576,7 +575,7 @@
     /**
      * Initialize the custom tag arrays.
      */
-    private void initCustomTagArrays() {
+    private void initCustomTagletArrays() {
         Iterator<Taglet> it = customTags.values().iterator();
         ArrayList<Taglet> pTags = new ArrayList<Taglet>(customTags.size());
         ArrayList<Taglet> tTags = new ArrayList<Taglet>(customTags.size());
@@ -631,88 +630,72 @@
     /**
      * Initialize standard Javadoc tags for ordering purposes.
      */
-    private void initStandardTags() {
+    private void initStandardTaglets() {
         Taglet temp;
-        customTags.put((temp = new ParamTaglet()).getName(), temp);
-        customTags.put((temp = new ReturnTaglet()).getName(), temp);
-        customTags.put((temp = new ThrowsTaglet()).getName(), temp);
-        customTags.put((temp = new SimpleTaglet("exception",
-            null, SimpleTaglet.METHOD + SimpleTaglet.CONSTRUCTOR)).getName(), temp);
-        if (!nosince) {
-            customTags.put((temp = new SimpleTaglet("since", message.getText("doclet.Since"),
-               SimpleTaglet.ALL)).getName(), temp);
-        }
-        if (showversion) {
-            customTags.put((temp = new SimpleTaglet("version", message.getText("doclet.Version"),
-                SimpleTaglet.PACKAGE + SimpleTaglet.TYPE + SimpleTaglet.OVERVIEW)).getName(), temp);
-        }
-        if (showauthor) {
-            customTags.put((temp = new SimpleTaglet("author", message.getText("doclet.Author"),
-                SimpleTaglet.PACKAGE + SimpleTaglet.TYPE + SimpleTaglet.OVERVIEW)).getName(), temp);
-        }
-        customTags.put((temp = new SimpleTaglet("serialData", message.getText("doclet.SerialData"),
-            SimpleTaglet.EXCLUDED)).getName(), temp);
+        addStandardTaglet(new ParamTaglet());
+        addStandardTaglet(new ReturnTaglet());
+        addStandardTaglet(new ThrowsTaglet());
+        addStandardTaglet(new SimpleTaglet("exception", null,
+                SimpleTaglet.METHOD + SimpleTaglet.CONSTRUCTOR));
+        addStandardTaglet(!nosince, new SimpleTaglet("since", message.getText("doclet.Since"),
+               SimpleTaglet.ALL));
+        addStandardTaglet(showversion, new SimpleTaglet("version", message.getText("doclet.Version"),
+                SimpleTaglet.PACKAGE + SimpleTaglet.TYPE + SimpleTaglet.OVERVIEW));
+        addStandardTaglet(showauthor, new SimpleTaglet("author", message.getText("doclet.Author"),
+                SimpleTaglet.PACKAGE + SimpleTaglet.TYPE + SimpleTaglet.OVERVIEW));
+        addStandardTaglet(new SimpleTaglet("serialData", message.getText("doclet.SerialData"),
+            SimpleTaglet.EXCLUDED));
         customTags.put((temp = new SimpleTaglet("factory", message.getText("doclet.Factory"),
             SimpleTaglet.METHOD)).getName(), temp);
-        customTags.put((temp = new SeeTaglet()).getName(), temp);
+        addStandardTaglet(new SeeTaglet());
         //Standard inline tags
-        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);
+        addStandardTaglet(new DocRootTaglet());
+        addStandardTaglet(new InheritDocTaglet());
+        addStandardTaglet(new ValueTaglet());
+        addStandardTaglet(new LiteralTaglet());
+        addStandardTaglet(new CodeTaglet());
 
-        //Keep track of the names of standard tags for error
-        //checking purposes.
-        standardTags.add("param");
-        standardTags.add("return");
-        standardTags.add("throws");
-        standardTags.add("exception");
-        standardTags.add("since");
-        standardTags.add("version");
-        standardTags.add("author");
-        standardTags.add("see");
+        // Keep track of the names of standard tags for error
+        // checking purposes. The following are not handled above.
+        // See, for example, com.sun.tools.javadoc.Comment
         standardTags.add("deprecated");
         standardTags.add("link");
         standardTags.add("linkplain");
-        standardTags.add("inheritDoc");
-        standardTags.add("docRoot");
-        standardTags.add("value");
         standardTags.add("serial");
-        standardTags.add("serialData");
         standardTags.add("serialField");
         standardTags.add("Text");
-        standardTags.add("literal");
-        standardTags.add("code");
 
         if (javafx) {
-            initJavaFXTags();
+            initJavaFXTaglets();
         }
     }
 
     /**
      * Initialize JavaFX-related tags.
      */
-    private void initJavaFXTags() {
-        Taglet temp;
-        customTags.put((temp = new PropertyGetterTaglet()).getName(), temp);
-        customTags.put((temp = new PropertySetterTaglet()).getName(), temp);
-        customTags.put((temp = new SimpleTaglet("propertyDescription", message.getText("doclet.PropertyDescription"),
-            SimpleTaglet.FIELD + SimpleTaglet.METHOD)).getName(), temp);
-        customTags.put((temp = new SimpleTaglet("defaultValue", message.getText("doclet.DefaultValue"),
-            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);
+    private void initJavaFXTaglets() {
+        addStandardTaglet(new PropertyGetterTaglet());
+        addStandardTaglet(new PropertySetterTaglet());
+        addStandardTaglet(new SimpleTaglet("propertyDescription",
+                message.getText("doclet.PropertyDescription"),
+                SimpleTaglet.FIELD + SimpleTaglet.METHOD));
+        addStandardTaglet(new SimpleTaglet("defaultValue", message.getText("doclet.DefaultValue"),
+            SimpleTaglet.FIELD + SimpleTaglet.METHOD));
+        addStandardTaglet(new SimpleTaglet("treatAsPrivate", null,
+                SimpleTaglet.FIELD + SimpleTaglet.METHOD + SimpleTaglet.TYPE));
+    }
 
-        standardTags.add("propertyGetter");
-        standardTags.add("propertySetter");
-        standardTags.add("propertyDescription");
-        standardTags.add("defaultValue");
-        standardTags.add("treatAsPrivate");
-        standardTags.add("expert");
+    void addStandardTaglet(Taglet taglet) {
+        String name = taglet.getName();
+        customTags.put(name, taglet);
+        standardTags.add(name);
+    }
+
+    void addStandardTaglet(boolean enable, Taglet taglet) {
+        String name = taglet.getName();
+        if (enable)
+            customTags.put(name, taglet);
+        standardTags.add(name);
     }
 
     /**
--- a/src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/TagletOutput.java	Thu May 16 12:16:07 2013 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,60 +0,0 @@
-/*
- * Copyright (c) 2003, 2012, 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
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-package com.sun.tools.doclets.internal.toolkit.taglets;
-
-/**
- * The interface for taglet output.  This interface is needed because
- * different doclets work with different formats of output.  A single taglet can
- * work with any doclet that provides an implementation of taglet output.
- *
- *  <p><b>This is NOT part of any supported API.
- *  If you write code that depends on this, you do so at your own risk.
- *  This code and its internal interfaces are subject to change or
- *  deletion without notice.</b>
- *
- * @author Jamie Ho
- * @since 1.5
- */
-public interface TagletOutput {
-
-    /**
-     * Set the output for the taglet.
-     * @param o an object representing the output.
-     */
-    public abstract void setOutput(Object o);
-
-    /**
-     * Append the given output to this output.
-     * @param o a TagletOutput representing the output.
-     */
-    public abstract void appendOutput(TagletOutput o);
-
-    /**
-     * Return true if this output has any occurances of @inheritDoc.
-     * @return true if inheritDoc tag is found.
-     */
-    public abstract boolean hasInheritDocTag();
-}
--- a/src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/TagletWriter.java	Thu May 16 12:16:07 2013 -0700
+++ b/src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/TagletWriter.java	Fri May 17 10:13:34 2013 -0700
@@ -53,15 +53,23 @@
     }
 
     /**
-     * @return an instance of the output object.
+     * @return an instance of an output object.
      */
-    public abstract TagletOutput getOutputInstance();
+    public abstract Content getOutputInstance();
+
+    /**
+     * Return the output for a {@code...} tag.
+     *
+     * @param tag the tag.
+     * @return the output of the taglet.
+     */
+    protected abstract Content codeTagOutput(Tag tag);
 
     /**
      * Returns the output for the DocRoot inline tag.
      * @return the output for the DocRoot inline tag.
      */
-    protected abstract TagletOutput getDocRootOutput();
+    protected abstract Content getDocRootOutput();
 
     /**
      * Return the deprecated tag output.
@@ -69,7 +77,15 @@
      * @param doc the doc to write deprecated documentation for.
      * @return the output of the deprecated tag.
      */
-    protected abstract TagletOutput deprecatedTagOutput(Doc doc);
+    protected abstract Content deprecatedTagOutput(Doc doc);
+
+    /**
+     * Return the output for a {@literal...} tag.
+     *
+     * @param tag the tag.
+     * @return the output of the taglet.
+     */
+    protected abstract Content literalTagOutput(Tag tag);
 
     /**
      * Returns {@link MessageRetriever} for output purposes.
@@ -84,7 +100,7 @@
      * @param header the header to display.
      * @return the header for the param tags.
      */
-    protected abstract TagletOutput getParamHeader(String header);
+    protected abstract Content getParamHeader(String header);
 
     /**
      * Return the output for param tags.
@@ -93,16 +109,25 @@
      * @param paramName the name of the parameter.
      * @return the output of the param tag.
      */
-    protected abstract TagletOutput paramTagOutput(ParamTag paramTag,
+    protected abstract Content paramTagOutput(ParamTag paramTag,
         String paramName);
 
     /**
+     * Return the output for property tags.
+     *
+     * @param propertyTag the parameter to document.
+     * @param prefix the text with which to prefix the property name.
+     * @return the output of the param tag.
+     */
+    protected abstract Content propertyTagOutput(Tag propertyTag, String prefix);
+
+    /**
      * Return the return tag output.
      *
      * @param returnTag the return tag to output.
      * @return the output of the return tag.
      */
-    protected abstract TagletOutput returnTagOutput(Tag returnTag);
+    protected abstract Content returnTagOutput(Tag returnTag);
 
     /**
      * Return the see tag output.
@@ -110,7 +135,7 @@
      * @param seeTags the array of See tags.
      * @return the output of the see tags.
      */
-    protected abstract TagletOutput seeTagOutput(Doc holder, SeeTag[] seeTags);
+    protected abstract Content seeTagOutput(Doc holder, SeeTag[] seeTags);
 
     /**
      * Return the output for a simple tag.
@@ -118,7 +143,7 @@
      * @param simpleTags the array of simple tags.
      * @return the output of the simple tags.
      */
-    protected abstract TagletOutput simpleTagOutput(Tag[] simpleTags,
+    protected abstract Content simpleTagOutput(Tag[] simpleTags,
         String header);
 
     /**
@@ -127,14 +152,14 @@
      * @param simpleTag the simple tag.
      * @return the output of the simple tag.
      */
-    protected abstract TagletOutput simpleTagOutput(Tag simpleTag, String header);
+    protected abstract Content simpleTagOutput(Tag simpleTag, String header);
 
     /**
      * Return the header for the throws tag.
      *
      * @return the header for the throws tag.
      */
-    protected abstract TagletOutput getThrowsHeader();
+    protected abstract Content getThrowsHeader();
 
     /**
      * Return the header for the throws tag.
@@ -142,7 +167,7 @@
      * @param throwsTag the throws tag.
      * @return the output of the throws tag.
      */
-    protected abstract TagletOutput throwsTagOutput(ThrowsTag throwsTag);
+    protected abstract Content throwsTagOutput(ThrowsTag throwsTag);
 
     /**
      * Return the output for the throws tag.
@@ -150,7 +175,7 @@
      * @param throwsType the throws type.
      * @return the output of the throws type.
      */
-    protected abstract TagletOutput throwsTagOutput(Type throwsType);
+    protected abstract Content throwsTagOutput(Type throwsType);
 
     /**
      * Return the output for the value tag.
@@ -161,7 +186,7 @@
      *                    constant field itself.
      * @return the output of the value tag.
      */
-    protected abstract TagletOutput valueTagOutput(FieldDoc field,
+    protected abstract Content valueTagOutput(FieldDoc field,
         String constantVal, boolean includeLink);
 
     /**
@@ -175,10 +200,10 @@
      * @param output the output buffer to store the output in.
      */
     public static void genTagOuput(TagletManager tagletManager, Doc doc,
-            Taglet[] taglets, TagletWriter writer, TagletOutput output) {
+            Taglet[] taglets, TagletWriter writer, Content output) {
         tagletManager.checkTags(doc, doc.tags(), false);
         tagletManager.checkTags(doc, doc.inlineTags(), true);
-        TagletOutput currentOutput = null;
+        Content currentOutput = null;
         for (int i = 0; i < taglets.length; i++) {
             currentOutput = null;
             if (doc instanceof ClassDoc && taglets[i] instanceof ParamTaglet) {
@@ -203,7 +228,7 @@
             }
             if (currentOutput != null) {
                 tagletManager.seenCustomTag(taglets[i].getName());
-                output.appendOutput(currentOutput);
+                output.addContent(currentOutput);
             }
         }
     }
@@ -217,16 +242,16 @@
      * @param tagletWriter The taglet writer to write the output.
      * @return The output of the inline tag.
      */
-    public static TagletOutput getInlineTagOuput(TagletManager tagletManager,
+    public static Content getInlineTagOuput(TagletManager tagletManager,
             Tag holderTag, Tag inlineTag, TagletWriter tagletWriter) {
-        Taglet[] definedTags = tagletManager.getInlineCustomTags();
+        Taglet[] definedTags = tagletManager.getInlineCustomTaglets();
         //This is a custom inline tag.
         for (int j = 0; j < definedTags.length; j++) {
             if (("@"+definedTags[j].getName()).equals(inlineTag.name())) {
                 //Given a name of a seen custom tag, remove it from the
                 // set of unseen custom tags.
                 tagletManager.seenCustomTag(definedTags[j].getName());
-                TagletOutput output = definedTags[j].getTagletOutput(
+                Content output = definedTags[j].getTagletOutput(
                     holderTag != null &&
                         definedTags[j].getName().equals("inheritDoc") ?
                             holderTag : inlineTag, tagletWriter);
@@ -245,9 +270,9 @@
      * @param holderTag the tag that holds the documentation.
      * @param tags   array of text tags and inline tags (often alternating)
      *               present in the text of interest for this doc.
-     * @return the {@link TagletOutput} representing the comments.
+     * @return the {@link Content} representing the comments.
      */
-    public abstract TagletOutput commentTagsToOutput(Tag holderTag, Tag[] tags);
+    public abstract Content commentTagsToOutput(Tag holderTag, Tag[] tags);
 
     /**
      * Converts inline tags and text to TagOutput, expanding the
@@ -258,9 +283,9 @@
      * @param holderDoc specific doc where comment resides.
      * @param tags   array of text tags and inline tags (often alternating)
      *               present in the text of interest for this doc.
-     * @return the {@link TagletOutput} representing the comments.
+     * @return the {@link Content} representing the comments.
      */
-    public abstract TagletOutput commentTagsToOutput(Doc holderDoc, Tag[] tags);
+    public abstract Content commentTagsToOutput(Doc holderDoc, Tag[] tags);
 
     /**
      * Converts inline tags and text to TagOutput, expanding the
@@ -273,18 +298,13 @@
      * @param tags   array of text tags and inline tags (often alternating)
      *               present in the text of interest for this doc.
      * @param isFirstSentence true if this is the first sentence.
-     * @return the {@link TagletOutput} representing the comments.
+     * @return the {@link Content} representing the comments.
      */
-    public abstract TagletOutput commentTagsToOutput(Tag holderTag,
+    public abstract Content commentTagsToOutput(Tag holderTag,
         Doc holderDoc, Tag[] tags, boolean isFirstSentence);
 
     /**
      * @return an instance of the configuration used for this doclet.
      */
     public abstract Configuration configuration();
-
-    /**
-     * @return an instance of the taglet output object.
-     */
-    public abstract TagletOutput getTagletOutputInstance();
 }
--- a/src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/ThrowsTaglet.java	Thu May 16 12:16:07 2013 -0700
+++ b/src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/ThrowsTaglet.java	Fri May 17 10:13:34 2013 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 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
@@ -28,6 +28,7 @@
 import java.util.*;
 
 import com.sun.javadoc.*;
+import com.sun.tools.doclets.internal.toolkit.Content;
 import com.sun.tools.doclets.internal.toolkit.util.*;
 
 /**
@@ -60,15 +61,15 @@
                 throwsTag.exceptionName() :
                 throwsTag.exception().qualifiedName();
         } else {
-            exception = input.method.containingClass().findClass(input.tagId);
+            exception = input.element.containingClass().findClass(input.tagId);
         }
 
-        ThrowsTag[] tags = input.method.throwsTags();
+        ThrowsTag[] tags = ((MethodDoc)input.element).throwsTags();
         for (int i = 0; i < tags.length; i++) {
             if (input.tagId.equals(tags[i].exceptionName()) ||
                 (tags[i].exception() != null &&
                     (input.tagId.equals(tags[i].exception().qualifiedName())))) {
-                output.holder = input.method;
+                output.holder = input.element;
                 output.holderTag = tags[i];
                 output.inlineTags = input.isFirstSentence ?
                     tags[i].firstSentenceTags() : tags[i].inlineTags();
@@ -83,10 +84,10 @@
     /**
      * Add links for exceptions that are declared but not documented.
      */
-    private TagletOutput linkToUndocumentedDeclaredExceptions(
+    private Content linkToUndocumentedDeclaredExceptions(
             Type[] declaredExceptionTypes, Set<String> alreadyDocumented,
             TagletWriter writer) {
-        TagletOutput result = writer.getOutputInstance();
+        Content result = writer.getOutputInstance();
         //Add links to the exceptions declared but not documented.
         for (int i = 0; i < declaredExceptionTypes.length; i++) {
             if (declaredExceptionTypes[i].asClassDoc() != null &&
@@ -95,9 +96,9 @@
                 ! alreadyDocumented.contains(
                     declaredExceptionTypes[i].asClassDoc().qualifiedName())) {
                 if (alreadyDocumented.size() == 0) {
-                    result.appendOutput(writer.getThrowsHeader());
+                    result.addContent(writer.getThrowsHeader());
                 }
-                result.appendOutput(writer.throwsTagOutput(declaredExceptionTypes[i]));
+                result.addContent(writer.throwsTagOutput(declaredExceptionTypes[i]));
                 alreadyDocumented.add(declaredExceptionTypes[i].asClassDoc().name());
             }
         }
@@ -108,10 +109,10 @@
      * Inherit throws documentation for exceptions that were declared but not
      * documented.
      */
-    private TagletOutput inheritThrowsDocumentation(Doc holder,
+    private Content inheritThrowsDocumentation(Doc holder,
             Type[] declaredExceptionTypes, Set<String> alreadyDocumented,
             TagletWriter writer) {
-        TagletOutput result = writer.getOutputInstance();
+        Content result = writer.getOutputInstance();
         if (holder instanceof MethodDoc) {
             Set<Tag> declaredExceptionTags = new LinkedHashSet<Tag>();
             for (int j = 0; j < declaredExceptionTypes.length; j++) {
@@ -125,7 +126,7 @@
                 }
                 declaredExceptionTags.addAll(inheritedDoc.tagList);
             }
-            result.appendOutput(throwsTagsOutput(
+            result.addContent(throwsTagsOutput(
                 declaredExceptionTags.toArray(new ThrowsTag[] {}),
                 writer, alreadyDocumented, false));
         }
@@ -135,18 +136,18 @@
     /**
      * {@inheritDoc}
      */
-    public TagletOutput getTagletOutput(Doc holder, TagletWriter writer) {
+    public Content getTagletOutput(Doc holder, TagletWriter writer) {
         ExecutableMemberDoc execHolder = (ExecutableMemberDoc) holder;
         ThrowsTag[] tags = execHolder.throwsTags();
-        TagletOutput result = writer.getOutputInstance();
+        Content result = writer.getOutputInstance();
         HashSet<String> alreadyDocumented = new HashSet<String>();
         if (tags.length > 0) {
-            result.appendOutput(throwsTagsOutput(
+            result.addContent(throwsTagsOutput(
                 execHolder.throwsTags(), writer, alreadyDocumented, true));
         }
-        result.appendOutput(inheritThrowsDocumentation(holder,
+        result.addContent(inheritThrowsDocumentation(holder,
             execHolder.thrownExceptionTypes(), alreadyDocumented, writer));
-        result.appendOutput(linkToUndocumentedDeclaredExceptions(
+        result.addContent(linkToUndocumentedDeclaredExceptions(
             execHolder.thrownExceptionTypes(), alreadyDocumented, writer));
         return result;
     }
@@ -160,11 +161,11 @@
      * @param alreadyDocumented the set of exceptions that have already
      *        been documented.
      * @param allowDups True if we allow duplicate throws tags to be documented.
-     * @return the TagletOutput representation of this <code>Tag</code>.
+     * @return the Content representation of this <code>Tag</code>.
      */
-    protected TagletOutput throwsTagsOutput(ThrowsTag[] throwTags,
+    protected Content throwsTagsOutput(ThrowsTag[] throwTags,
         TagletWriter writer, Set<String> alreadyDocumented, boolean allowDups) {
-        TagletOutput result = writer.getOutputInstance();
+        Content result = writer.getOutputInstance();
         if (throwTags.length > 0) {
             for (int i = 0; i < throwTags.length; ++i) {
                 ThrowsTag tt = throwTags[i];
@@ -174,9 +175,9 @@
                     continue;
                 }
                 if (alreadyDocumented.size() == 0) {
-                    result.appendOutput(writer.getThrowsHeader());
+                    result.addContent(writer.getThrowsHeader());
                 }
-                result.appendOutput(writer.throwsTagOutput(tt));
+                result.addContent(writer.throwsTagOutput(tt));
                 alreadyDocumented.add(cd != null ?
                     cd.qualifiedName() : tt.exceptionName());
             }
--- a/src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/ValueTaglet.java	Thu May 16 12:16:07 2013 -0700
+++ b/src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/ValueTaglet.java	Fri May 17 10:13:34 2013 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 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
@@ -29,6 +29,7 @@
 
 import com.sun.javadoc.*;
 import com.sun.tools.doclets.internal.toolkit.Configuration;
+import com.sun.tools.doclets.internal.toolkit.Content;
 import com.sun.tools.doclets.internal.toolkit.util.*;
 
 /**
@@ -160,7 +161,7 @@
     /**
      * {@inheritDoc}
      */
-    public TagletOutput getTagletOutput(Tag tag, TagletWriter writer) {
+    public Content getTagletOutput(Tag tag, TagletWriter writer) {
         FieldDoc field = getFieldDoc(
             writer.configuration(), tag, tag.text());
         if (field == null) {
@@ -169,7 +170,7 @@
                 "doclet.value_tag_invalid_reference", tag.text());
         } else if (field.constantValue() != null) {
             return writer.valueTagOutput(field,
-                Util.escapeHtmlChars(field.constantValueExpression()),
+                field.constantValueExpression(),
                 ! field.equals(tag.holder()));
         } else {
             //Referenced field is not a constant.
--- a/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/DocFinder.java	Thu May 16 12:16:07 2013 -0700
+++ b/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/DocFinder.java	Fri May 17 10:13:34 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
@@ -48,9 +48,9 @@
      */
     public static class Input {
         /**
-         * The method to search documentation from.
+         * The element to search documentation from.
          */
-        public MethodDoc method = null;
+        public ProgramElementDoc element;
         /**
          * The taglet to search for documentation on behalf of. Null if we want
          * to search for overall documentation.
@@ -84,54 +84,55 @@
          */
         public boolean isTypeVariableParamTag = false;
 
-        public Input() {}
-
-        public Input(MethodDoc method, InheritableTaglet taglet, Tag tag,
+        public Input(ProgramElementDoc element, InheritableTaglet taglet, Tag tag,
                 boolean isFirstSentence, boolean isInheritDocTag) {
-            this.method = method;
+            this(element);
             this.taglet = taglet;
             this.tag = tag;
             this.isFirstSentence = isFirstSentence;
             this.isInheritDocTag = isInheritDocTag;
         }
 
-        public Input(MethodDoc method, InheritableTaglet taglet, String tagId) {
-            this.method = method;
+        public Input(ProgramElementDoc element, InheritableTaglet taglet, String tagId) {
+            this(element);
             this.taglet = taglet;
             this.tagId = tagId;
         }
 
-        public Input(MethodDoc method, InheritableTaglet taglet, String tagId,
+        public Input(ProgramElementDoc element, InheritableTaglet taglet, String tagId,
             boolean isTypeVariableParamTag) {
-            this.method = method;
+            this(element);
             this.taglet = taglet;
             this.tagId = tagId;
             this.isTypeVariableParamTag = isTypeVariableParamTag;
         }
 
-        public Input(MethodDoc method, InheritableTaglet taglet) {
-            this.method = method;
+        public Input(ProgramElementDoc element, InheritableTaglet taglet) {
+            this(element);
             this.taglet = taglet;
         }
 
-        public Input(MethodDoc method) {
-            this.method = method;
+        public Input(ProgramElementDoc element) {
+            if (element == null)
+                throw new NullPointerException();
+            this.element = element;
         }
 
-        public Input(MethodDoc method, boolean isFirstSentence) {
-            this.method = method;
+        public Input(ProgramElementDoc element, boolean isFirstSentence) {
+            this(element);
             this.isFirstSentence = isFirstSentence;
         }
 
         public Input copy() {
-            Input clone = new Input();
-            clone.method = this.method;
+            Input clone = new Input(this.element);
             clone.taglet = this.taglet;
             clone.tagId = this.tagId;
             clone.tag = this.tag;
             clone.isFirstSentence = this.isFirstSentence;
             clone.isInheritDocTag = this.isInheritDocTag;
             clone.isTypeVariableParamTag = this.isTypeVariableParamTag;
+            if (clone.element == null)
+                throw new NullPointerException();
             return clone;
 
         }
@@ -164,8 +165,8 @@
 
         /**
          * When automatically inheriting throws tags, you sometime must inherit
-         * more than one tag.  For example if the method declares that it throws
-         * IOException and the overidden method has throws tags for IOException and
+         * more than one tag.  For example if the element declares that it throws
+         * IOException and the overridden element has throws tags for IOException and
          * ZipException, both tags would be inherited because ZipException is a
          * subclass of IOException.  This subclass of DocFinder.Output allows
          * multiple tag inheritence.
@@ -174,9 +175,9 @@
     }
 
     /**
-     * Search for the requested comments in the given method.  If it does not
-     * have comments, return documentation from the overriden method if possible.
-     * If the overriden method does not exist or does not have documentation to
+     * Search for the requested comments in the given element.  If it does not
+     * have comments, return documentation from the overriden element if possible.
+     * If the overriden element does not exist or does not have documentation to
      * inherit, search for documentation to inherit from implemented methods.
      *
      * @param input the input object used to perform the search.
@@ -186,14 +187,14 @@
     public static Output search(Input input) {
         Output output = new Output();
         if (input.isInheritDocTag) {
-            //Do nothing because "method" does not have any documentation.
+            //Do nothing because "element" does not have any documentation.
             //All it has it {@inheritDoc}.
         } else if (input.taglet == null) {
             //We want overall documentation.
             output.inlineTags = input.isFirstSentence ?
-                input.method.firstSentenceTags() :
-                input.method.inlineTags();
-            output.holder = input.method;
+                input.element.firstSentenceTags() :
+                input.element.inlineTags();
+            output.holder = input.element;
         } else {
             input.taglet.inherit(input, output);
         }
@@ -204,25 +205,38 @@
         output.isValidInheritDocTag = false;
         Input inheritedSearchInput = input.copy();
         inheritedSearchInput.isInheritDocTag = false;
-        if (input.method.overriddenMethod() != null) {
-            inheritedSearchInput.method = input.method.overriddenMethod();
-            output = search(inheritedSearchInput);
-            output.isValidInheritDocTag = true;
-            if (output != null && output.inlineTags.length > 0) {
-                return output;
+        if (input.element instanceof MethodDoc) {
+            MethodDoc overriddenMethod = ((MethodDoc) input.element).overriddenMethod();
+            if (overriddenMethod != null) {
+                inheritedSearchInput.element = overriddenMethod;
+                output = search(inheritedSearchInput);
+                output.isValidInheritDocTag = true;
+                if (output.inlineTags.length > 0) {
+                    return output;
+                }
             }
-        }
-        //NOTE:  When we fix the bug where ClassDoc.interfaceTypes() does
-        //       not pass all implemented interfaces, we will use the
-        //       appropriate method here.
-        MethodDoc[] implementedMethods =
-            (new ImplementedMethods(input.method, null)).build(false);
-        for (int i = 0; i < implementedMethods.length; i++) {
-            inheritedSearchInput.method = implementedMethods[i];
-            output = search(inheritedSearchInput);
-            output.isValidInheritDocTag = true;
-            if (output != null && output.inlineTags.length > 0) {
-                return output;
+            //NOTE:  When we fix the bug where ClassDoc.interfaceTypes() does
+            //       not pass all implemented interfaces, we will use the
+            //       appropriate element here.
+            MethodDoc[] implementedMethods =
+                (new ImplementedMethods((MethodDoc) input.element, null)).build(false);
+            for (int i = 0; i < implementedMethods.length; i++) {
+                inheritedSearchInput.element = implementedMethods[i];
+                output = search(inheritedSearchInput);
+                output.isValidInheritDocTag = true;
+                if (output.inlineTags.length > 0) {
+                    return output;
+                }
+            }
+        } else if (input.element instanceof ClassDoc) {
+            ProgramElementDoc superclass = ((ClassDoc) input.element).superclass();
+            if (superclass != null) {
+                inheritedSearchInput.element = superclass;
+                output = search(inheritedSearchInput);
+                output.isValidInheritDocTag = true;
+                if (output.inlineTags.length > 0) {
+                    return output;
+                }
             }
         }
         return output;
--- a/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/DocletConstants.java	Thu May 16 12:16:07 2013 -0700
+++ b/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/DocletConstants.java	Fri May 17 10:13:34 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
@@ -52,7 +52,7 @@
     /**
      * The default package name.
      */
-    public static final String DEFAULT_PACKAGE_NAME = "&lt;Unnamed&gt;";
+    public static final String DEFAULT_PACKAGE_NAME = "<Unnamed>";
 
     /**
      * The default package file name.
--- a/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/Util.java	Thu May 16 12:16:07 2013 -0700
+++ b/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/Util.java	Fri May 17 10:13:34 2013 -0700
@@ -420,69 +420,6 @@
     }
 
     /**
-     * Given a string, escape all special html characters and
-     * return the result.
-     *
-     * @param s The string to check.
-     * @return the original string with all of the HTML characters escaped.
-     */
-    public static String escapeHtmlChars(String s) {
-        for (int i = 0; i < s.length(); i++) {
-            char ch = s.charAt(i);
-            switch (ch) {
-                // only start building a new string if we need to
-                case '<': case '>': case '&':
-                    StringBuilder sb = new StringBuilder(s.substring(0, i));
-                    for ( ; i < s.length(); i++) {
-                        ch = s.charAt(i);
-                        switch (ch) {
-                            case '<': sb.append("&lt;");  break;
-                            case '>': sb.append("&gt;");  break;
-                            case '&': sb.append("&amp;"); break;
-                            default:  sb.append(ch);      break;
-                        }
-                    }
-                    return sb.toString();
-            }
-        }
-        return s;
-    }
-
-    /**
-     * Escape all special html characters in a string buffer.
-     *
-     * @param sb The string buffer to update
-     */
-    public static void escapeHtmlChars(StringBuilder sb) {
-        // scan backwards, replacing characters as needed.
-        for (int i = sb.length() - 1; i >= 0; i--) {
-            switch (sb.charAt(i)) {
-                case '<': sb.replace(i, i+1, "&lt;"); break;
-                case '>': sb.replace(i, i+1, "&gt;"); break;
-                case '&': sb.replace(i, i+1, "&amp;"); break;
-            }
-        }
-    }
-
-    /**
-     * Given a string, strips all html characters and
-     * return the result.
-     *
-     * @param rawString The string to check.
-     * @return the original string with all of the HTML characters
-     * stripped.
-     *
-     */
-    public static String stripHtml(String rawString) {
-        // remove HTML tags
-        rawString = rawString.replaceAll("\\<.*?>", " ");
-        // consolidate multiple spaces between a word to a single space
-        rawString = rawString.replaceAll("\\b\\s{2,}\\b", " ");
-        // remove extra whitespaces
-        return rawString.trim();
-    }
-
-    /**
      * Given an annotation, return true if it should be documented and false
      * otherwise.
      *
@@ -656,20 +593,42 @@
     }
 
     /**
-     * Replace all tabs with the appropriate number of spaces.
+     * Replace all tabs in a string with the appropriate number of spaces.
+     * The string may be a multi-line string.
      * @param configuration the doclet configuration defining the setting for the
      *                      tab length.
-     * @param sb the StringBuilder in which to replace the tabs
+     * @param text the text for which the tabs should be expanded
+     * @return the text with all tabs expanded
      */
-    public static void replaceTabs(Configuration configuration, StringBuilder sb) {
-        int tabLength = configuration.sourcetab;
-        String whitespace = configuration.tabSpaces;
-        int index = 0;
-        while ((index = sb.indexOf("\t", index)) != -1) {
-            int spaceCount = tabLength - index % tabLength;
-            sb.replace(index, index+1, whitespace.substring(0, spaceCount));
-            index += spaceCount;
+    public static String replaceTabs(Configuration configuration, String text) {
+        if (text.indexOf("\t") == -1)
+            return text;
+
+        final int tabLength = configuration.sourcetab;
+        final String whitespace = configuration.tabSpaces;
+        final int textLength = text.length();
+        StringBuilder result = new StringBuilder(textLength);
+        int pos = 0;
+        int lineLength = 0;
+        for (int i = 0; i < textLength; i++) {
+            char ch = text.charAt(i);
+            switch (ch) {
+                case '\n': case '\r':
+                    lineLength = 0;
+                    break;
+                case '\t':
+                    result.append(text, pos, i);
+                    int spaceCount = tabLength - lineLength % tabLength;
+                    result.append(whitespace, 0, spaceCount);
+                    lineLength += spaceCount;
+                    pos = i + 1;
+                    break;
+                default:
+                    lineLength++;
+            }
         }
+        result.append(text, pos, textLength);
+        return result.toString();
     }
 
     /**
--- a/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/links/LinkFactory.java	Thu May 16 12:16:07 2013 -0700
+++ b/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/links/LinkFactory.java	Fri May 17 10:13:34 2013 -0700
@@ -26,6 +26,7 @@
 package com.sun.tools.doclets.internal.toolkit.util.links;
 
 import com.sun.javadoc.*;
+import com.sun.tools.doclets.internal.toolkit.Content;
 
 /**
  * A factory that constructs links from given link information.
@@ -41,11 +42,11 @@
 public abstract class LinkFactory {
 
     /**
-     * Return an empty instance of the link output object.
+     * Return an empty instance of a content object.
      *
-     * @return an empty instance of the link output object.
+     * @return an empty instance of a content object.
      */
-    protected abstract LinkOutput getOutputInstance();
+    protected abstract Content newContent();
 
     /**
      * Constructs a link from the given link information.
@@ -53,63 +54,59 @@
      * @param linkInfo the information about the link.
      * @return the output of the link.
      */
-    public LinkOutput getLinkOutput(LinkInfo linkInfo) {
+    public Content getLink(LinkInfo linkInfo) {
         if (linkInfo.type != null) {
             Type type = linkInfo.type;
-            LinkOutput linkOutput = getOutputInstance();
+            Content link = newContent();
             if (type.isPrimitive()) {
                 //Just a primitive.
-                linkInfo.displayLength += type.typeName().length();
-                linkOutput.append(type.typeName());
+                link.addContent(type.typeName());
             } else if (type.asAnnotatedType() != null && type.dimension().length() == 0) {
-                linkOutput.append(getTypeAnnotationLinks(linkInfo));
+                link.addContent(getTypeAnnotationLinks(linkInfo));
                 linkInfo.type = type.asAnnotatedType().underlyingType();
-                linkOutput.append(getLinkOutput(linkInfo));
-                return linkOutput;
+                link.addContent(getLink(linkInfo));
+                return link;
             } else if (type.asWildcardType() != null) {
                 //Wildcard type.
                 linkInfo.isTypeBound = true;
-                linkInfo.displayLength += 1;
-                linkOutput.append("?");
+                link.addContent("?");
                 WildcardType wildcardType = type.asWildcardType();
                 Type[] extendsBounds = wildcardType.extendsBounds();
                 for (int i = 0; i < extendsBounds.length; i++) {
-                    linkInfo.displayLength += i > 0 ? 2 : 9;
-                    linkOutput.append(i > 0 ? ", " : " extends ");
+                    link.addContent(i > 0 ? ", " : " extends ");
                     setBoundsLinkInfo(linkInfo, extendsBounds[i]);
-                    linkOutput.append(getLinkOutput(linkInfo));
+                    link.addContent(getLink(linkInfo));
                 }
                 Type[] superBounds = wildcardType.superBounds();
                 for (int i = 0; i < superBounds.length; i++) {
-                    linkInfo.displayLength += i > 0 ? 2 : 7;
-                    linkOutput.append(i > 0 ? ", " : " super ");
+                    link.addContent(i > 0 ? ", " : " super ");
                     setBoundsLinkInfo(linkInfo, superBounds[i]);
-                    linkOutput.append(getLinkOutput(linkInfo));
+                    link.addContent(getLink(linkInfo));
                 }
             } else if (type.asTypeVariable()!= null) {
-                linkOutput.append(getTypeAnnotationLinks(linkInfo));
+                link.addContent(getTypeAnnotationLinks(linkInfo));
                 linkInfo.isTypeBound = true;
                 //A type variable.
                 Doc owner = type.asTypeVariable().owner();
                 if ((! linkInfo.excludeTypeParameterLinks) &&
                         owner instanceof ClassDoc) {
                     linkInfo.classDoc = (ClassDoc) owner;
-                    linkInfo.label = type.typeName();
-                    linkOutput.append(getClassLink(linkInfo));
+                    Content label = newContent();
+                    label.addContent(type.typeName());
+                    linkInfo.label = label;
+                    link.addContent(getClassLink(linkInfo));
                 } else {
                     //No need to link method type parameters.
-                    linkInfo.displayLength += type.typeName().length();
-                    linkOutput.append(type.typeName());
+                    link.addContent(type.typeName());
                 }
 
                 Type[] bounds = type.asTypeVariable().bounds();
                 if (! linkInfo.excludeTypeBounds) {
                     linkInfo.excludeTypeBounds = true;
                     for (int i = 0; i < bounds.length; i++) {
-                        linkInfo.displayLength += i > 0 ? 2 : 9;
-                        linkOutput.append(i > 0 ? " & " : " extends ");
+                        link.addContent(i > 0 ? " & " : " extends ");
                         setBoundsLinkInfo(linkInfo, bounds[i]);
-                        linkOutput.append(getLinkOutput(linkInfo));
+                        link.addContent(getLink(linkInfo));
                     }
                 }
             } else if (type.asClassDoc() != null) {
@@ -118,15 +115,15 @@
                         linkInfo.excludeTypeBoundsLinks) {
                     //Since we are excluding type parameter links, we should not
                     //be linking to the type bound.
-                    linkInfo.displayLength += type.typeName().length();
-                    linkOutput.append(type.typeName());
-                    linkOutput.append(getTypeParameterLinks(linkInfo));
-                    return linkOutput;
+                    link.addContent(type.typeName());
+                    link.addContent(getTypeParameterLinks(linkInfo));
+                    return link;
                 } else {
                     linkInfo.classDoc = type.asClassDoc();
-                    linkOutput = getClassLink(linkInfo);
+                    link = newContent();
+                    link.addContent(getClassLink(linkInfo));
                     if (linkInfo.includeTypeAsSepLink) {
-                        linkOutput.append(getTypeParameterLinks(linkInfo, false));
+                        link.addContent(getTypeParameterLinks(linkInfo, false));
                     }
                 }
             }
@@ -135,36 +132,37 @@
                 if (type.dimension().length() > 2) {
                     //Javadoc returns var args as array.
                     //Strip out the first [] from the var arg.
-                    linkInfo.displayLength += type.dimension().length()-2;
-                    linkOutput.append(type.dimension().substring(2));
+                    link.addContent(type.dimension().substring(2));
                 }
-                linkInfo.displayLength += 3;
-                linkOutput.append("...");
+                link.addContent("...");
             } else {
                 while (type != null && type.dimension().length() > 0) {
-                    linkInfo.displayLength += type.dimension().length();
                     if (type.asAnnotatedType() != null) {
                         linkInfo.type = type;
-                        linkOutput.append(" ");
-                        linkOutput.append(getTypeAnnotationLinks(linkInfo));
-                        linkOutput.append("[]");
+                        link.addContent(" ");
+                        link.addContent(getTypeAnnotationLinks(linkInfo));
+                        link.addContent("[]");
                         type = type.asAnnotatedType().underlyingType().getElementType();
                     } else {
-                        linkOutput.append("[]");
+                        link.addContent("[]");
                         type = type.getElementType();
                     }
                 }
                 linkInfo.type = type;
-                linkOutput.insert(0, getTypeAnnotationLinks(linkInfo));
+                Content newLink = newContent();
+                newLink.addContent(getTypeAnnotationLinks(linkInfo));
+                newLink.addContent(link);
+                link = newLink;
             }
-            return linkOutput;
+            return link;
         } else if (linkInfo.classDoc != null) {
             //Just a class link
-            LinkOutput linkOutput = getClassLink(linkInfo);
+            Content link = newContent();
+            link.addContent(getClassLink(linkInfo));
             if (linkInfo.includeTypeAsSepLink) {
-                linkOutput.append(getTypeParameterLinks(linkInfo, false));
+                link.addContent(getTypeParameterLinks(linkInfo, false));
             }
-            return linkOutput;
+            return link;
         } else {
             return null;
         }
@@ -183,7 +181,7 @@
      *
      * @return the link for the given class.
      */
-    protected abstract LinkOutput getClassLink(LinkInfo linkInfo);
+    protected abstract Content getClassLink(LinkInfo linkInfo);
 
     /**
      * Return the link to the given type parameter.
@@ -191,10 +189,10 @@
      * @param linkInfo     the information about the link to construct.
      * @param typeParam the type parameter to link to.
      */
-    protected abstract LinkOutput getTypeParameterLink(LinkInfo linkInfo,
+    protected abstract Content getTypeParameterLink(LinkInfo linkInfo,
         Type typeParam);
 
-    protected abstract LinkOutput getTypeAnnotationLink(LinkInfo linkInfo,
+    protected abstract Content getTypeAnnotationLink(LinkInfo linkInfo,
             AnnotationDesc annotation);
 
     /**
@@ -203,7 +201,7 @@
      * @param linkInfo     the information about the link to construct.
      * @return the links to the type parameters.
      */
-    public LinkOutput getTypeParameterLinks(LinkInfo linkInfo) {
+    public Content getTypeParameterLinks(LinkInfo linkInfo) {
         return getTypeParameterLinks(linkInfo, true);
     }
 
@@ -215,8 +213,8 @@
      *                     the type parameters portion of the link.
      * @return the links to the type parameters.
      */
-    public LinkOutput getTypeParameterLinks(LinkInfo linkInfo, boolean isClassLabel) {
-        LinkOutput output = getOutputInstance();
+    public Content getTypeParameterLinks(LinkInfo linkInfo, boolean isClassLabel) {
+        Content links = newContent();
         Type[] vars;
         if (linkInfo.executableMemberDoc != null) {
             vars = linkInfo.executableMemberDoc.typeParameters();
@@ -227,62 +225,37 @@
             vars = linkInfo.classDoc.typeParameters();
         } else {
             //Nothing to document.
-            return output;
+            return links;
         }
         if (((linkInfo.includeTypeInClassLinkLabel && isClassLabel) ||
              (linkInfo.includeTypeAsSepLink && ! isClassLabel)
               )
             && vars.length > 0) {
-            linkInfo.displayLength += 1;
-            output.append(getLessThanString());
+            links.addContent("<");
             for (int i = 0; i < vars.length; i++) {
                 if (i > 0) {
-                    linkInfo.displayLength += 1;
-                    output.append(",");
+                    links.addContent(",");
                 }
-                output.append(getTypeParameterLink(linkInfo, vars[i]));
+                links.addContent(getTypeParameterLink(linkInfo, vars[i]));
             }
-            linkInfo.displayLength += 1;
-            output.append(getGreaterThanString());
+            links.addContent(">");
         }
-        return output;
+        return links;
     }
 
-    public LinkOutput getTypeAnnotationLinks(LinkInfo linkInfo) {
-        LinkOutput output = getOutputInstance();
+    public Content getTypeAnnotationLinks(LinkInfo linkInfo) {
+        Content links = newContent();
         if (linkInfo.type.asAnnotatedType() == null)
-            return output;
+            return links;
         AnnotationDesc[] annotations = linkInfo.type.asAnnotatedType().annotations();
         for (int i = 0; i < annotations.length; i++) {
             if (i > 0) {
-                linkInfo.displayLength += 1;
-                output.append(" ");
+                links.addContent(" ");
             }
-            output.append(getTypeAnnotationLink(linkInfo, annotations[i]));
+            links.addContent(getTypeAnnotationLink(linkInfo, annotations[i]));
         }
 
-        linkInfo.displayLength += 1;
-        output.append(" ");
-        return output;
-    }
-
-    /**
-     * Return &amp;lt;, which is used in type parameters.  Override this
-     * if your doclet uses something different.
-     *
-     * @return return &amp;lt;, which is used in type parameters.
-     */
-    protected String getLessThanString() {
-        return "&lt;";
-    }
-
-    /**
-     * Return &amp;gt;, which is used in type parameters.  Override this
-     * if your doclet uses something different.
-     *
-     * @return return &amp;gt;, which is used in type parameters.
-     */
-    protected String getGreaterThanString() {
-        return "&gt;";
+        links.addContent(" ");
+        return links;
     }
 }
--- a/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/links/LinkInfo.java	Thu May 16 12:16:07 2013 -0700
+++ b/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/links/LinkInfo.java	Fri May 17 10:13:34 2013 -0700
@@ -27,6 +27,7 @@
 
 import com.sun.javadoc.*;
 import com.sun.tools.doclets.internal.toolkit.Configuration;
+import com.sun.tools.doclets.internal.toolkit.Content;
 
 /**
  * Encapsulates information about a link.
@@ -77,7 +78,7 @@
     /**
      * The label for the link.
      */
-    public String label;
+    public Content label;
 
     /**
      * True if the link should be strong.
@@ -90,7 +91,7 @@
     public boolean includeTypeInClassLinkLabel = true;
 
     /**
-     * True if we should include the type as seperate link.  False otherwise.
+     * True if we should include the type as separate link.  False otherwise.
      */
     public boolean includeTypeAsSepLink = false;
 
@@ -116,24 +117,11 @@
     public boolean linkToSelf = true;
 
     /**
-     * The display length for the link.
+     * Return an empty instance of a content object.
+     *
+     * @return an empty instance of a content object.
      */
-    public int displayLength = 0;
-
-    /**
-     * Return the id indicating where the link appears in the documentation.
-     * This is used for special processing of different types of links.
-     *
-     * @return the id indicating where the link appears in the documentation.
-     */
-    public abstract int getContext();
-
-    /**
-     * Set the context.
-     *
-     * @param c the context id to set.
-     */
-    public abstract void setContext(int c);
+    protected abstract Content newContent();
 
     /**
      * Return true if this link is linkable and false if we can't link to the
@@ -150,13 +138,17 @@
      * @param configuration the current configuration of the doclet.
      * @return the label for this class link.
      */
-    public String getClassLinkLabel(Configuration configuration) {
-        if (label != null && label.length() > 0) {
+    public Content getClassLinkLabel(Configuration configuration) {
+        if (label != null && !label.isEmpty()) {
             return label;
         } else if (isLinkable()) {
-            return classDoc.name();
+            Content label = newContent();
+            label.addContent(classDoc.name());
+            return label;
         } else {
-            return configuration.getClassName(classDoc);
+            Content label = newContent();
+            label.addContent(configuration.getClassName(classDoc));
+            return label;
         }
     }
 }
--- a/src/share/classes/com/sun/tools/doclint/Checker.java	Thu May 16 12:16:07 2013 -0700
+++ b/src/share/classes/com/sun/tools/doclint/Checker.java	Fri May 17 10:13:34 2013 -0700
@@ -42,7 +42,6 @@
 import javax.lang.model.element.ElementKind;
 import javax.lang.model.element.ExecutableElement;
 import javax.lang.model.element.Name;
-import javax.lang.model.element.TypeElement;
 import javax.lang.model.type.TypeKind;
 import javax.lang.model.type.TypeMirror;
 import javax.tools.Diagnostic.Kind;
@@ -70,7 +69,8 @@
 import com.sun.source.doctree.ThrowsTree;
 import com.sun.source.doctree.ValueTree;
 import com.sun.source.doctree.VersionTree;
-import com.sun.source.util.DocTreeScanner;
+import com.sun.source.util.DocTreePath;
+import com.sun.source.util.DocTreePathScanner;
 import com.sun.source.util.TreePath;
 import com.sun.tools.doclint.HtmlTag.AttrKind;
 import com.sun.tools.javac.tree.DocPretty;
@@ -85,7 +85,7 @@
  * risk.  This code and its internal interfaces are subject to change
  * or deletion without notice.</b></p>
  */
-public class Checker extends DocTreeScanner<Void, Void> {
+public class Checker extends DocTreePathScanner<Void, Void> {
     final Env env;
 
     Set<Element> foundParams = new HashSet<Element>();
@@ -152,7 +152,7 @@
         foundInheritDoc = false;
         foundReturn = false;
 
-        scan(tree, (Void) null);
+        scan(new DocTreePath(p, tree), null);
 
         if (!isOverridingMethod) {
             switch (env.currElement.getKind()) {
@@ -620,47 +620,36 @@
     }
 
     @Override
+    @SuppressWarnings("fallthrough")
     public Void visitParam(ParamTree tree, Void ignore) {
         boolean typaram = tree.isTypeParameter();
         IdentifierTree nameTree = tree.getName();
-        Element e = env.currElement;
-        switch (e.getKind()) {
-            case METHOD: case CONSTRUCTOR: {
-                ExecutableElement ee = (ExecutableElement) e;
-                checkParamDeclared(nameTree, typaram ? ee.getTypeParameters() : ee.getParameters());
-                break;
+        Element paramElement = nameTree != null ? env.trees.getElement(new DocTreePath(getCurrentPath(), nameTree)) : null;
+
+        if (paramElement == null) {
+            switch (env.currElement.getKind()) {
+                case CLASS: case INTERFACE: {
+                    if (!typaram) {
+                        env.messages.error(REFERENCE, tree, "dc.invalid.param");
+                        break;
+                    }
+                }
+                case METHOD: case CONSTRUCTOR: {
+                    env.messages.error(REFERENCE, nameTree, "dc.param.name.not.found");
+                    break;
+                }
+
+                default:
+                    env.messages.error(REFERENCE, tree, "dc.invalid.param");
+                    break;
             }
+        } else {
+            foundParams.add(paramElement);
+        }
 
-            case CLASS: case INTERFACE: {
-                TypeElement te = (TypeElement) e;
-                if (typaram) {
-                    checkParamDeclared(nameTree, te.getTypeParameters());
-                } else {
-                    env.messages.error(REFERENCE, tree, "dc.invalid.param");
-                }
-                break;
-            }
-
-            default:
-                env.messages.error(REFERENCE, tree, "dc.invalid.param");
-                break;
-        }
         warnIfEmpty(tree, tree.getDescription());
         return super.visitParam(tree, ignore);
     }
-    // where
-    private void checkParamDeclared(IdentifierTree nameTree, List<? extends Element> list) {
-        Name name = nameTree.getName();
-        boolean found = false;
-        for (Element e: list) {
-            if (name.equals(e.getSimpleName())) {
-                foundParams.add(e);
-                found = true;
-            }
-        }
-        if (!found)
-            env.messages.error(REFERENCE, nameTree, "dc.param.name.not.found");
-    }
 
     private void checkParamsDocumented(List<? extends Element> list) {
         if (foundInheritDoc)
@@ -678,7 +667,7 @@
 
     @Override
     public Void visitReference(ReferenceTree tree, Void ignore) {
-        Element e = env.trees.getElement(env.currPath, tree);
+        Element e = env.trees.getElement(getCurrentPath());
         if (e == null)
             env.messages.error(REFERENCE, tree, "dc.ref.not.found");
         return super.visitReference(tree, ignore);
@@ -716,7 +705,7 @@
     @Override
     public Void visitThrows(ThrowsTree tree, Void ignore) {
         ReferenceTree exName = tree.getExceptionName();
-        Element ex = env.trees.getElement(env.currPath, exName);
+        Element ex = env.trees.getElement(new DocTreePath(getCurrentPath(), exName));
         if (ex == null) {
             env.messages.error(REFERENCE, tree, "dc.ref.not.found");
         } else if (ex.asType().getKind() == TypeKind.DECLARED
--- a/src/share/classes/com/sun/tools/doclint/Env.java	Thu May 16 12:16:07 2013 -0700
+++ b/src/share/classes/com/sun/tools/doclint/Env.java	Fri May 17 10:13:34 2013 -0700
@@ -29,6 +29,7 @@
 import java.util.Set;
 
 import javax.lang.model.element.Element;
+import javax.lang.model.element.ElementKind;
 import javax.lang.model.element.ExecutableElement;
 import javax.lang.model.element.Modifier;
 import javax.lang.model.type.TypeMirror;
@@ -144,7 +145,7 @@
         AccessKind ak = null;
         for (TreePath p = path; p != null; p = p.getParentPath()) {
             Element e = trees.getElement(p);
-            if (e != null) {
+            if (e != null && e.getKind() != ElementKind.PACKAGE) {
                 ak = min(ak, AccessKind.of(e.getModifiers()));
             }
         }
--- a/src/share/classes/com/sun/tools/javac/api/JavacTrees.java	Thu May 16 12:16:07 2013 -0700
+++ b/src/share/classes/com/sun/tools/javac/api/JavacTrees.java	Fri May 17 10:13:34 2013 -0700
@@ -33,6 +33,7 @@
 import javax.lang.model.element.AnnotationMirror;
 import javax.lang.model.element.AnnotationValue;
 import javax.lang.model.element.Element;
+import javax.lang.model.element.ElementKind;
 import javax.lang.model.element.ExecutableElement;
 import javax.lang.model.element.TypeElement;
 import javax.lang.model.type.DeclaredType;
@@ -44,12 +45,12 @@
 
 import com.sun.source.doctree.DocCommentTree;
 import com.sun.source.doctree.DocTree;
-import com.sun.source.doctree.ReferenceTree;
 import com.sun.source.tree.CatchTree;
 import com.sun.source.tree.CompilationUnitTree;
 import com.sun.source.tree.Scope;
 import com.sun.source.tree.Tree;
 import com.sun.source.util.DocSourcePositions;
+import com.sun.source.util.DocTreePath;
 import com.sun.source.util.DocTreeScanner;
 import com.sun.source.util.DocTrees;
 import com.sun.source.util.JavacTask;
@@ -314,7 +315,7 @@
         return TreePath.getPath(treeTopLevel.snd, treeTopLevel.fst);
     }
 
-    public Element getElement(TreePath path) {
+    public Symbol getElement(TreePath path) {
         JCTree tree = (JCTree) path.getLeaf();
         Symbol sym = TreeInfo.symbolFor(tree);
         if (sym == null) {
@@ -332,22 +333,25 @@
                         }
                     }
                 }
-            } else if (tree.hasTag(Tag.TOPLEVEL)) {
-                JCCompilationUnit cu = (JCCompilationUnit) tree;
-                if (cu.sourcefile.isNameCompatible("package-info", JavaFileObject.Kind.SOURCE)) {
-                    sym = cu.packge;
-                }
             }
         }
         return sym;
     }
 
     @Override
-    public Element getElement(TreePath path, ReferenceTree reference) {
-        if (!(reference instanceof DCReference))
-            return null;
-        DCReference ref = (DCReference) reference;
+    public Element getElement(DocTreePath path) {
+        DocTree forTree = path.getLeaf();
+        if (forTree instanceof DCReference)
+            return attributeDocReference(path.getTreePath(), ((DCReference) forTree));
+        if (forTree instanceof DCIdentifier) {
+            if (path.getParentPath().getLeaf() instanceof DCParam) {
+                return attributeParamIdentifier(path.getTreePath(), (DCParam) path.getParentPath().getLeaf());
+            }
+        }
+        return null;
+    }
 
+    private Symbol attributeDocReference(TreePath path, DCReference ref) {
         Env<AttrContext> env = getAttrContext(path);
 
         Log.DeferredDiagnosticHandler deferredDiagnosticHandler =
@@ -427,6 +431,30 @@
         }
     }
 
+    private Symbol attributeParamIdentifier(TreePath path, DCParam ptag) {
+        Symbol javadocSymbol = getElement(path);
+        if (javadocSymbol == null)
+            return null;
+        ElementKind kind = javadocSymbol.getKind();
+        List<? extends Symbol> params = List.nil();
+        if (kind == ElementKind.METHOD || kind == ElementKind.CONSTRUCTOR) {
+            MethodSymbol ee = (MethodSymbol) javadocSymbol;
+            params = ptag.isTypeParameter()
+                    ? ee.getTypeParameters()
+                    : ee.getParameters();
+        } else if (kind.isClass() || kind.isInterface()) {
+            ClassSymbol te = (ClassSymbol) javadocSymbol;
+            params = te.getTypeParameters();
+        }
+
+        for (Symbol param : params) {
+            if (param.getSimpleName() == ptag.getName().getName()) {
+                return param;
+            }
+        }
+        return null;
+    }
+
     /** @see com.sun.tools.javadoc.ClassDocImpl#findField */
     private VarSymbol findField(ClassSymbol tsym, Name fieldName) {
         return searchField(tsym, fieldName, new HashSet<ClassSymbol>());
--- a/src/share/classes/com/sun/tools/javac/code/Annotations.java	Thu May 16 12:16:07 2013 -0700
+++ b/src/share/classes/com/sun/tools/javac/code/Annotations.java	Fri May 17 10:13:34 2013 -0700
@@ -76,11 +76,24 @@
     private List<Attribute.Compound> attributes = DECL_NOT_STARTED;
 
     /*
-     * This field should never be null
+     * Type attributes for this symbol.
+     * This field should never be null.
      */
     private List<Attribute.TypeCompound> type_attributes = List.<Attribute.TypeCompound>nil();
 
     /*
+     * Type attributes of initializers in this class.
+     * Unused if the current symbol is not a ClassSymbol.
+     */
+    private List<Attribute.TypeCompound> init_type_attributes = List.<Attribute.TypeCompound>nil();
+
+    /*
+     * Type attributes of class initializers in this class.
+     * Unused if the current symbol is not a ClassSymbol.
+     */
+    private List<Attribute.TypeCompound> clinit_type_attributes = List.<Attribute.TypeCompound>nil();
+
+    /*
      * The Symbol this Annotations instance belongs to
      */
     private final Symbol sym;
@@ -97,6 +110,14 @@
         return type_attributes;
     }
 
+    public List<Attribute.TypeCompound> getInitTypeAttributes() {
+        return init_type_attributes;
+    }
+
+    public List<Attribute.TypeCompound> getClassInitTypeAttributes() {
+        return clinit_type_attributes;
+    }
+
     public void setDeclarationAttributes(List<Attribute.Compound> a) {
         Assert.check(pendingCompletion() || !isStarted());
         if (a == null) {
@@ -112,12 +133,28 @@
         type_attributes = a;
     }
 
+    public void setInitTypeAttributes(List<Attribute.TypeCompound> a) {
+        if (a == null) {
+            throw new NullPointerException();
+        }
+        init_type_attributes = a;
+    }
+
+    public void setClassInitTypeAttributes(List<Attribute.TypeCompound> a) {
+        if (a == null) {
+            throw new NullPointerException();
+        }
+        clinit_type_attributes = a;
+    }
+
     public void setAttributes(Annotations other) {
         if (other == null) {
             throw new NullPointerException();
         }
         setDeclarationAttributes(other.getDeclarationAttributes());
         setTypeAttributes(other.getTypeAttributes());
+        setInitTypeAttributes(other.getInitTypeAttributes());
+        setClassInitTypeAttributes(other.getClassInitTypeAttributes());
     }
 
     public void setDeclarationAttributesWithCompletion(final Annotate.AnnotateRepeatedContext<Attribute.Compound> ctx) {
@@ -232,6 +269,28 @@
         return this;
     }
 
+    public Annotations appendInitTypeAttributes(List<Attribute.TypeCompound> l) {
+        if (l.isEmpty()) {
+            ; // no-op
+        } else if (init_type_attributes.isEmpty()) {
+            init_type_attributes = l;
+        } else {
+            init_type_attributes = init_type_attributes.appendList(l);
+        }
+        return this;
+    }
+
+    public Annotations appendClassInitTypeAttributes(List<Attribute.TypeCompound> l) {
+        if (l.isEmpty()) {
+            ; // no-op
+        } else if (clinit_type_attributes.isEmpty()) {
+            clinit_type_attributes = l;
+        } else {
+            clinit_type_attributes = clinit_type_attributes.appendList(l);
+        }
+        return this;
+    }
+
     public Annotations prepend(List<Attribute.Compound> l) {
         attributes = filterDeclSentinels(attributes);
 
--- a/src/share/classes/com/sun/tools/javac/code/Attribute.java	Thu May 16 12:16:07 2013 -0700
+++ b/src/share/classes/com/sun/tools/javac/code/Attribute.java	Fri May 17 10:13:34 2013 -0700
@@ -230,6 +230,42 @@
             this.position = position;
         }
 
+        public boolean hasUnknownPosition() {
+            return position == null || position.type == TargetType.UNKNOWN;
+        }
+
+        public boolean isContainerTypeCompound() {
+            if (isSynthesized() && values.size() == 1)
+                return getFirstEmbeddedTC() != null;
+            return false;
+        }
+
+        private TypeCompound getFirstEmbeddedTC() {
+            if (values.size() == 1) {
+                Pair<MethodSymbol, Attribute> val = values.get(0);
+                if (val.fst.getSimpleName().contentEquals("value")
+                        && val.snd instanceof Array) {
+                    Array arr = (Array) val.snd;
+                    if (arr.values.length != 0
+                            && arr.values[0] instanceof Attribute.TypeCompound)
+                        return (Attribute.TypeCompound) arr.values[0];
+                }
+            }
+            return null;
+        }
+
+        public boolean tryFixPosition() {
+            if (!isContainerTypeCompound())
+                return false;
+
+            TypeCompound from = getFirstEmbeddedTC();
+            if (from != null && from.position != null &&
+                    from.position.type != TargetType.UNKNOWN) {
+                position = from.position;
+                return true;
+            }
+            return false;
+        }
     }
 
     /** The value for an annotation element of an array type.
--- a/src/share/classes/com/sun/tools/javac/code/Printer.java	Thu May 16 12:16:07 2013 -0700
+++ b/src/share/classes/com/sun/tools/javac/code/Printer.java	Fri May 17 10:13:34 2013 -0700
@@ -31,6 +31,7 @@
 
 import com.sun.tools.javac.api.Messages;
 import com.sun.tools.javac.code.Type.AnnotatedType;
+import com.sun.tools.javac.code.Type.ArrayType;
 import com.sun.tools.javac.code.Symbol.*;
 import com.sun.tools.javac.code.Type.*;
 import com.sun.tools.javac.util.List;
@@ -127,7 +128,7 @@
     }
 
     /**
-     * Get a localized string represenation for a given type.
+     * Get a localized string representation for a given type.
      *
      * @param t type to be displayed
      * @param locale the locale in which the string is to be rendered
@@ -138,7 +139,7 @@
     }
 
     /**
-     * Get a localized string represenation for a given symbol.
+     * Get a localized string representation for a given symbol.
      *
      * @param s symbol to be displayed
      * @param locale the locale in which the string is to be rendered
@@ -182,7 +183,33 @@
 
     @Override
     public String visitArrayType(ArrayType t, Locale locale) {
-        return visit(t.elemtype, locale) + "[]";
+        StringBuilder res = new StringBuilder();
+        printBaseElementType(t, res, locale);
+        printBrackets(t, res, locale);
+        return res.toString();
+    }
+
+    void printBaseElementType(Type t, StringBuilder sb, Locale locale) {
+        Type arrel = t;
+        while (arrel.getKind() == TypeKind.ARRAY) {
+            arrel = arrel.unannotatedType();
+            arrel = ((ArrayType) arrel).elemtype;
+        }
+        sb.append(visit(arrel, locale));
+    }
+
+    void printBrackets(Type t, StringBuilder sb, Locale locale) {
+        Type arrel = t;
+        while (arrel.getKind() == TypeKind.ARRAY) {
+            if (arrel.isAnnotated()) {
+                sb.append(' ');
+                sb.append(arrel.getAnnotationMirrors());
+                sb.append(' ');
+            }
+            sb.append("[]");
+            arrel = arrel.unannotatedType();
+            arrel = ((ArrayType) arrel).elemtype;
+        }
     }
 
     @Override
@@ -237,10 +264,22 @@
     public String visitAnnotatedType(AnnotatedType t, Locale locale) {
         if (t.typeAnnotations != null &&
                 t.typeAnnotations.nonEmpty()) {
-            // TODO: better logic for arrays, ...
-            return "(" + t.typeAnnotations + " :: " + visit(t.underlyingType, locale) + ")";
+            if (t.underlyingType.getKind() == TypeKind.ARRAY) {
+                StringBuilder res = new StringBuilder();
+                printBaseElementType(t, res, locale);
+                printBrackets(t, res, locale);
+                return res.toString();
+            } else if (t.underlyingType.getKind() == TypeKind.DECLARED &&
+                    t.underlyingType.getEnclosingType() != Type.noType) {
+                return visit(t.underlyingType.getEnclosingType(), locale) +
+                        ". " +
+                        t.typeAnnotations +
+                        " " + className((ClassType)t.underlyingType, false, locale);
+            } else {
+                return t.typeAnnotations + " " + visit(t.underlyingType, locale);
+            }
         } else {
-            return "({} :: " + visit(t.underlyingType, locale) + ")";
+            return visit(t.underlyingType, locale);
         }
     }
 
@@ -253,7 +292,7 @@
 
     /**
      * Converts a class name into a (possibly localized) string. Anonymous
-     * inner classes gets converted into a localized string.
+     * inner classes get converted into a localized string.
      *
      * @param t the type of the class whose name is to be rendered
      * @param longform if set, the class' fullname is displayed - if unset the
@@ -266,7 +305,7 @@
         if (sym.name.length() == 0 && (sym.flags() & COMPOUND) != 0) {
             StringBuilder s = new StringBuilder(visit(t.supertype_field, locale));
             for (List<Type> is = t.interfaces_field; is.nonEmpty(); is = is.tail) {
-                s.append("&");
+                s.append('&');
                 s.append(visit(is.head, locale));
             }
             return s.toString();
--- a/src/share/classes/com/sun/tools/javac/code/Symtab.java	Thu May 16 12:16:07 2013 -0700
+++ b/src/share/classes/com/sun/tools/javac/code/Symtab.java	Fri May 17 10:13:34 2013 -0700
@@ -131,7 +131,6 @@
     public final Type methodHandleLookupType;
     public final Type methodTypeType;
     public final Type nativeHeaderType;
-    public final Type nativeHeaderType_old;
     public final Type throwableType;
     public final Type errorType;
     public final Type interruptedExceptionType;
@@ -526,7 +525,6 @@
                              autoCloseableType.tsym);
         trustMeType = enterClass("java.lang.SafeVarargs");
         nativeHeaderType = enterClass("java.lang.annotation.Native");
-        nativeHeaderType_old = enterClass("javax.tools.annotation.GenerateNativeHeader");
         lambdaMetafactory = enterClass("java.lang.invoke.LambdaMetafactory");
         functionalInterfaceType = enterClass("java.lang.FunctionalInterface");
 
--- a/src/share/classes/com/sun/tools/javac/code/Type.java	Thu May 16 12:16:07 2013 -0700
+++ b/src/share/classes/com/sun/tools/javac/code/Type.java	Fri May 17 10:13:34 2013 -0700
@@ -25,8 +25,6 @@
 
 package com.sun.tools.javac.code;
 
-import com.sun.tools.javac.model.JavacAnnoConstructs;
-import com.sun.tools.javac.model.JavacTypes;
 import java.lang.annotation.Annotation;
 import java.util.Collections;
 import java.util.EnumMap;
@@ -34,10 +32,10 @@
 import java.util.Map;
 import java.util.Set;
 
-import javax.lang.model.element.AnnotationMirror;
 import javax.lang.model.type.*;
 
 import com.sun.tools.javac.code.Symbol.*;
+import com.sun.tools.javac.model.JavacAnnoConstructs;
 import com.sun.tools.javac.util.*;
 import static com.sun.tools.javac.code.BoundKind.*;
 import static com.sun.tools.javac.code.Flags.*;
@@ -729,7 +727,7 @@
                     return s.toString();
                 } else if (sym.name.isEmpty()) {
                     String s;
-                    ClassType norm = (ClassType) tsym.type;
+                    ClassType norm = (ClassType) tsym.type.unannotatedType();
                     if (norm == null) {
                         s = Log.getLocalizedString("anonymous.class", (Object)null);
                     } else if (norm.interfaces_field != null && norm.interfaces_field.nonEmpty()) {
@@ -781,7 +779,7 @@
             return
                 getEnclosingType().isErroneous() ||
                 isErroneous(getTypeArguments()) ||
-                this != tsym.type && tsym.type.isErroneous();
+                this != tsym.type.unannotatedType() && tsym.type.isErroneous();
         }
 
         public boolean isParameterized() {
@@ -1693,7 +1691,10 @@
 
         @Override
         public String toString() {
-            // TODO more logic for arrays, etc.
+            // This method is only used for internal debugging output.
+            // See
+            // com.sun.tools.javac.code.Printer.visitAnnotatedType(AnnotatedType, Locale)
+            // for the user-visible logic.
             if (typeAnnotations != null &&
                     !typeAnnotations.isEmpty()) {
                 return "(" + typeAnnotations.toString() + " :: " + underlyingType.toString() + ")";
@@ -1705,9 +1706,13 @@
         @Override
         public boolean contains(Type t)          { return underlyingType.contains(t); }
 
-        // TODO: attach annotations?
         @Override
-        public Type withTypeVar(Type t)          { return underlyingType.withTypeVar(t); }
+        public Type withTypeVar(Type t) {
+            // Don't create a new AnnotatedType, as 'this' will
+            // get its annotations set later.
+            underlyingType = underlyingType.withTypeVar(t);
+            return this;
+        }
 
         // TODO: attach annotations?
         @Override
--- a/src/share/classes/com/sun/tools/javac/code/TypeAnnotationPosition.java	Thu May 16 12:16:07 2013 -0700
+++ b/src/share/classes/com/sun/tools/javac/code/TypeAnnotationPosition.java	Fri May 17 10:13:34 2013 -0700
@@ -27,6 +27,7 @@
 
 import java.util.Iterator;
 
+import com.sun.tools.javac.tree.JCTree.JCLambda;
 import com.sun.tools.javac.util.*;
 
 /** A type annotation position.
@@ -145,9 +146,18 @@
     // For class extends, implements, and throws clauses
     public int type_index = Integer.MIN_VALUE;
 
-    // For exception parameters, index into exception table
+    // For exception parameters, index into exception table.
+    // In com.sun.tools.javac.jvm.Gen.genCatch we first set the type_index
+    // to the catch type index - that value is only temporary.
+    // Then in com.sun.tools.javac.jvm.Code.fillExceptionParameterPositions
+    // we use that value to determine the exception table index.
     public int exception_index = Integer.MIN_VALUE;
 
+    // If this type annotation is within a lambda expression,
+    // store a pointer to the lambda expression tree in order
+    // to allow a later translation to the right method.
+    public JCLambda onLambda = null;
+
     public TypeAnnotationPosition() {}
 
     @Override
@@ -258,6 +268,11 @@
         sb.append(", pos = ");
         sb.append(pos);
 
+        if (onLambda != null) {
+            sb.append(", onLambda hash = ");
+            sb.append(onLambda.hashCode());
+        }
+
         sb.append(']');
         return sb.toString();
     }
@@ -271,6 +286,17 @@
         return !type.isLocal() || isValidOffset;
     }
 
+
+    public boolean matchesPos(int pos) {
+        return this.pos == pos;
+    }
+
+    public void updatePosOffset(int to) {
+        offset = to;
+        lvarOffset = new int[]{to};
+        isValidOffset = true;
+    }
+
     /**
      * Decode the binary representation for a type path and set
      * the {@code location} field.
--- a/src/share/classes/com/sun/tools/javac/code/TypeAnnotations.java	Thu May 16 12:16:07 2013 -0700
+++ b/src/share/classes/com/sun/tools/javac/code/TypeAnnotations.java	Fri May 17 10:13:34 2013 -0700
@@ -49,12 +49,16 @@
 import com.sun.tools.javac.code.TypeAnnotationPosition.TypePathEntryKind;
 import com.sun.tools.javac.code.TypeTag;
 import com.sun.tools.javac.code.Symbol.VarSymbol;
+import com.sun.tools.javac.code.Symbol.MethodSymbol;
+import com.sun.tools.javac.comp.Annotate;
 import com.sun.tools.javac.comp.Annotate.Annotator;
 import com.sun.tools.javac.tree.JCTree;
 import com.sun.tools.javac.tree.JCTree.JCBlock;
 import com.sun.tools.javac.tree.JCTree.JCClassDecl;
 import com.sun.tools.javac.tree.JCTree.JCExpression;
+import com.sun.tools.javac.tree.JCTree.JCLambda;
 import com.sun.tools.javac.tree.JCTree.JCMethodDecl;
+import com.sun.tools.javac.tree.JCTree.JCNewClass;
 import com.sun.tools.javac.tree.JCTree.JCTypeApply;
 import com.sun.tools.javac.tree.JCTree.JCVariableDecl;
 import com.sun.tools.javac.tree.TreeScanner;
@@ -81,17 +85,18 @@
      * determine the correct positions for type annotations.
      * This version only visits types in signatures and should be
      * called from MemberEnter.
-     * The method returns the Annotator object that should be added
-     * to the correct Annotate queue for later processing.
+     * The method takes the Annotate object as parameter and
+     * adds an Annotator to the correct Annotate queue for
+     * later processing.
      */
-    public static Annotator organizeTypeAnnotationsSignatures(final Symtab syms, final Names names,
-            final Log log, final JCClassDecl tree) {
-        return new Annotator() {
+    public static void organizeTypeAnnotationsSignatures(final Symtab syms, final Names names,
+            final Log log, final JCClassDecl tree, Annotate annotate) {
+        annotate.afterRepeated( new Annotator() {
             @Override
             public void enterAnnotation() {
                 new TypeAnnotationPositions(syms, names, log, true).scan(tree);
             }
-        };
+        } );
     }
 
     /**
@@ -102,10 +107,104 @@
         new TypeAnnotationPositions(syms, names, log, false).scan(tree);
     }
 
+    public enum AnnotationType { DECLARATION, TYPE, BOTH };
+
+    /**
+     * Determine whether an annotation is a declaration annotation,
+     * a type annotation, or both.
+     */
+    public static AnnotationType annotationType(Symtab syms, Names names,
+            Attribute.Compound a, Symbol s) {
+        Attribute.Compound atTarget =
+            a.type.tsym.attribute(syms.annotationTargetType.tsym);
+        if (atTarget == null) {
+            return inferTargetMetaInfo(a, s);
+        }
+        Attribute atValue = atTarget.member(names.value);
+        if (!(atValue instanceof Attribute.Array)) {
+            Assert.error("annotationType(): bad @Target argument " + atValue +
+                    " (" + atValue.getClass() + ")");
+            return AnnotationType.DECLARATION; // error recovery
+        }
+        Attribute.Array arr = (Attribute.Array) atValue;
+        boolean isDecl = false, isType = false;
+        for (Attribute app : arr.values) {
+            if (!(app instanceof Attribute.Enum)) {
+                Assert.error("annotationType(): unrecognized Attribute kind " + app +
+                        " (" + app.getClass() + ")");
+                isDecl = true;
+                continue;
+            }
+            Attribute.Enum e = (Attribute.Enum) app;
+            if (e.value.name == names.TYPE) {
+                if (s.kind == Kinds.TYP)
+                    isDecl = true;
+            } else if (e.value.name == names.FIELD) {
+                if (s.kind == Kinds.VAR &&
+                        s.owner.kind != Kinds.MTH)
+                    isDecl = true;
+            } else if (e.value.name == names.METHOD) {
+                if (s.kind == Kinds.MTH &&
+                        !s.isConstructor())
+                    isDecl = true;
+            } else if (e.value.name == names.PARAMETER) {
+                if (s.kind == Kinds.VAR &&
+                        s.owner.kind == Kinds.MTH &&
+                        (s.flags() & Flags.PARAMETER) != 0)
+                    isDecl = true;
+            } else if (e.value.name == names.CONSTRUCTOR) {
+                if (s.kind == Kinds.MTH &&
+                        s.isConstructor())
+                    isDecl = true;
+            } else if (e.value.name == names.LOCAL_VARIABLE) {
+                if (s.kind == Kinds.VAR &&
+                        s.owner.kind == Kinds.MTH &&
+                        (s.flags() & Flags.PARAMETER) == 0)
+                    isDecl = true;
+            } else if (e.value.name == names.ANNOTATION_TYPE) {
+                if (s.kind == Kinds.TYP &&
+                        (s.flags() & Flags.ANNOTATION) != 0)
+                    isDecl = true;
+            } else if (e.value.name == names.PACKAGE) {
+                if (s.kind == Kinds.PCK)
+                    isDecl = true;
+            } else if (e.value.name == names.TYPE_USE) {
+                if (s.kind == Kinds.TYP ||
+                        s.kind == Kinds.VAR ||
+                        (s.kind == Kinds.MTH && !s.isConstructor() &&
+                        !s.type.getReturnType().hasTag(TypeTag.VOID)) ||
+                        (s.kind == Kinds.MTH && s.isConstructor()))
+                    isType = true;
+            } else if (e.value.name == names.TYPE_PARAMETER) {
+                /* Irrelevant in this case */
+                // TYPE_PARAMETER doesn't aid in distinguishing between
+                // Type annotations and declaration annotations on an
+                // Element
+            } else {
+                Assert.error("annotationType(): unrecognized Attribute name " + e.value.name +
+                        " (" + e.value.name.getClass() + ")");
+                isDecl = true;
+            }
+        }
+        if (isDecl && isType) {
+            return AnnotationType.BOTH;
+        } else if (isType) {
+            return AnnotationType.TYPE;
+        } else {
+            return AnnotationType.DECLARATION;
+        }
+    }
+
+    /** Infer the target annotation kind, if none is give.
+     * We only infer declaration annotations.
+     */
+    private static AnnotationType inferTargetMetaInfo(Attribute.Compound a, Symbol s) {
+        return AnnotationType.DECLARATION;
+    }
+
+
     private static class TypeAnnotationPositions extends TreeScanner {
 
-        private enum AnnotationType { DECLARATION, TYPE, BOTH };
-
         private final Symtab syms;
         private final Names names;
         private final Log log;
@@ -154,7 +253,7 @@
             ListBuffer<Attribute.TypeCompound> typeAnnos = new ListBuffer<Attribute.TypeCompound>();
 
             for (Attribute.Compound a : annotations) {
-                switch (annotationType(a, sym)) {
+                switch (annotationType(syms, names, a, sym)) {
                 case DECLARATION:
                     declAnnos.append(a);
                     break;
@@ -175,6 +274,10 @@
             sym.annotations.reset();
             sym.annotations.setDeclarationAttributes(declAnnos.toList());
 
+            if (typeAnnos.isEmpty()) {
+                return;
+            }
+
             List<Attribute.TypeCompound> typeAnnotations = typeAnnos.toList();
 
             if (type == null) {
@@ -190,16 +293,33 @@
 
             if (sym.getKind() == ElementKind.METHOD) {
                 sym.type.asMethodType().restype = type;
+            } else if (sym.getKind() == ElementKind.PARAMETER) {
+                sym.type = type;
+                if (sym.getQualifiedName().equals(names._this)) {
+                    sym.owner.type.asMethodType().recvtype = type;
+                    // note that the typeAnnotations will also be added to the owner below.
+                } else {
+                    MethodType methType = sym.owner.type.asMethodType();
+                    List<VarSymbol> params = ((MethodSymbol)sym.owner).params;
+                    List<Type> oldArgs = methType.argtypes;
+                    ListBuffer<Type> newArgs = new ListBuffer<Type>();
+                    while (params.nonEmpty()) {
+                        if (params.head == sym) {
+                            newArgs.add(type);
+                        } else {
+                            newArgs.add(oldArgs.head);
+                        }
+                        oldArgs = oldArgs.tail;
+                        params = params.tail;
+                    }
+                    methType.argtypes = newArgs.toList();
+                }
             } else {
                 sym.type = type;
             }
 
             sym.annotations.appendUniqueTypes(typeAnnotations);
-            if (sym.getKind() == ElementKind.PARAMETER &&
-                    sym.getQualifiedName().equals(names._this)) {
-                sym.owner.type.asMethodType().recvtype = type;
-                // note that the typeAnnotations will also be added to the owner below.
-            }
+
             if (sym.getKind() == ElementKind.PARAMETER ||
                     sym.getKind() == ElementKind.LOCAL_VARIABLE ||
                     sym.getKind() == ElementKind.RESOURCE_VARIABLE ||
@@ -276,10 +396,21 @@
                     TypeAnnotationPosition p = a.position;
                     p.location = p.location.prependList(depth.toList());
                 }
+                typetree.type = toreturn;
                 return toreturn;
             } else if (type.hasTag(TypeTag.TYPEVAR)) {
                 // Nothing to do for type variables.
                 return type;
+            } else if (type.getKind() == TypeKind.UNION) {
+                // There is a TypeKind, but no TypeTag.
+                JCTypeUnion tutree = (JCTypeUnion) typetree;
+                JCExpression fst = tutree.alternatives.get(0);
+                Type res = typeWithAnnotations(fst, fst.type, annotations, log);
+                fst.type = res;
+                // TODO: do we want to set res as first element in uct.alternatives?
+                // UnionClassType uct = (com.sun.tools.javac.code.Type.UnionClassType)type;
+                // Return the un-annotated union-type.
+                return type;
             } else {
                 Type enclTy = type;
                 Element enclEl = type.asElement();
@@ -357,6 +488,7 @@
                 }
 
                 Type ret = typeWithAnnotations(type, enclTy, annotations);
+                typetree.type = ret;
                 return ret;
             }
         }
@@ -480,94 +612,6 @@
             return new Attribute.TypeCompound(a, p);
         }
 
-        private AnnotationType annotationType(Attribute.Compound a, Symbol s) {
-            Attribute.Compound atTarget =
-                a.type.tsym.attribute(syms.annotationTargetType.tsym);
-            if (atTarget == null) {
-                return inferTargetMetaInfo(a, s);
-            }
-            Attribute atValue = atTarget.member(names.value);
-            if (!(atValue instanceof Attribute.Array)) {
-                Assert.error("annotationType(): bad @Target argument " + atValue +
-                        " (" + atValue.getClass() + ")");
-                return AnnotationType.DECLARATION; // error recovery
-            }
-            Attribute.Array arr = (Attribute.Array) atValue;
-            boolean isDecl = false, isType = false;
-            for (Attribute app : arr.values) {
-                if (!(app instanceof Attribute.Enum)) {
-                    Assert.error("annotationType(): unrecognized Attribute kind " + app +
-                            " (" + app.getClass() + ")");
-                    isDecl = true;
-                    continue;
-                }
-                Attribute.Enum e = (Attribute.Enum) app;
-                if (e.value.name == names.TYPE) {
-                    if (s.kind == Kinds.TYP)
-                        isDecl = true;
-                } else if (e.value.name == names.FIELD) {
-                    if (s.kind == Kinds.VAR &&
-                            s.owner.kind != Kinds.MTH)
-                        isDecl = true;
-                } else if (e.value.name == names.METHOD) {
-                    if (s.kind == Kinds.MTH &&
-                            !s.isConstructor())
-                        isDecl = true;
-                } else if (e.value.name == names.PARAMETER) {
-                    if (s.kind == Kinds.VAR &&
-                            s.owner.kind == Kinds.MTH &&
-                            (s.flags() & Flags.PARAMETER) != 0)
-                        isDecl = true;
-                } else if (e.value.name == names.CONSTRUCTOR) {
-                    if (s.kind == Kinds.MTH &&
-                            s.isConstructor())
-                        isDecl = true;
-                } else if (e.value.name == names.LOCAL_VARIABLE) {
-                    if (s.kind == Kinds.VAR &&
-                            s.owner.kind == Kinds.MTH &&
-                            (s.flags() & Flags.PARAMETER) == 0)
-                        isDecl = true;
-                } else if (e.value.name == names.ANNOTATION_TYPE) {
-                    if (s.kind == Kinds.TYP &&
-                            (s.flags() & Flags.ANNOTATION) != 0)
-                        isDecl = true;
-                } else if (e.value.name == names.PACKAGE) {
-                    if (s.kind == Kinds.PCK)
-                        isDecl = true;
-                } else if (e.value.name == names.TYPE_USE) {
-                    if (s.kind == Kinds.TYP ||
-                            s.kind == Kinds.VAR ||
-                            (s.kind == Kinds.MTH && !s.isConstructor() &&
-                            !s.type.getReturnType().hasTag(TypeTag.VOID)) ||
-                            (s.kind == Kinds.MTH && s.isConstructor()))
-                        isType = true;
-                } else if (e.value.name == names.TYPE_PARAMETER) {
-                    /* Irrelevant in this case */
-                    // TYPE_PARAMETER doesn't aid in distinguishing between
-                    // Type annotations and declaration annotations on an
-                    // Element
-                } else {
-                    Assert.error("annotationType(): unrecognized Attribute name " + e.value.name +
-                            " (" + e.value.name.getClass() + ")");
-                    isDecl = true;
-                }
-            }
-            if (isDecl && isType) {
-                return AnnotationType.BOTH;
-            } else if (isType) {
-                return AnnotationType.TYPE;
-            } else {
-                return AnnotationType.DECLARATION;
-            }
-        }
-
-        /** Infer the target annotation kind, if none is give.
-         * We only infer declaration annotations.
-         */
-        private static AnnotationType inferTargetMetaInfo(Attribute.Compound a, Symbol s) {
-            return AnnotationType.DECLARATION;
-        }
-
 
         /* This is the beginning of the second part of organizing
          * type annotations: determine the type annotation positions.
@@ -585,7 +629,13 @@
 
             switch (frame.getKind()) {
                 case TYPE_CAST:
+                    JCTypeCast frameTC = (JCTypeCast) frame;
                     p.type = TargetType.CAST;
+                    if (frameTC.clazz.hasTag(Tag.TYPEINTERSECTION)) {
+                        // This case was already handled by INTERSECTION_TYPE
+                    } else {
+                        p.type_index = 0;
+                    }
                     p.pos = frame.pos;
                     return;
 
@@ -595,8 +645,22 @@
                     return;
 
                 case NEW_CLASS:
-                    JCNewClass frameNewClass = (JCNewClass)frame;
-                    if (frameNewClass.typeargs.contains(tree)) {
+                    JCNewClass frameNewClass = (JCNewClass) frame;
+                    if (frameNewClass.def != null) {
+                        // Special handling for anonymous class instantiations
+                        JCClassDecl frameClassDecl = frameNewClass.def;
+                        if (frameClassDecl.extending == tree) {
+                            p.type = TargetType.CLASS_EXTENDS;
+                            p.type_index = -1;
+                        } else if (frameClassDecl.implementing.contains(tree)) {
+                            p.type = TargetType.CLASS_EXTENDS;
+                            p.type_index = frameClassDecl.implementing.indexOf(tree);
+                        } else {
+                            // In contrast to CLASS below, typarams cannot occur here.
+                            Assert.error("Could not determine position of tree " + tree +
+                                    " within frame " + frame);
+                        }
+                    } else if (frameNewClass.typeargs.contains(tree)) {
                         p.type = TargetType.CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT;
                         p.type_index = frameNewClass.typeargs.indexOf(tree);
                     } else {
@@ -649,6 +713,8 @@
                 }
 
                 case PARAMETERIZED_TYPE: {
+                    List<JCTree> newPath = path.tail;
+
                     if (((JCTypeApply)frame).clazz == tree) {
                         // generic: RAW; noop
                     } else if (((JCTypeApply)frame).arguments.contains(tree)) {
@@ -656,13 +722,21 @@
                         int arg = taframe.arguments.indexOf(tree);
                         p.location = p.location.prepend(new TypePathEntry(TypePathEntryKind.TYPE_ARGUMENT, arg));
 
-                        locateNestedTypes(taframe.type, p);
+                        Type typeToUse;
+                        if (newPath.tail != null && newPath.tail.head.hasTag(Tag.NEWCLASS)) {
+                            // If we are within an anonymous class instantiation, use its type,
+                            // because it contains a correctly nested type.
+