提交 8f7e96fe 编写于 作者: J jjg

8011650: reduce use of RawHtml nodes in doclet

Reviewed-by: darcy
上级 e904244f
......@@ -126,7 +126,7 @@ public abstract class AbstractExecutableMemberWriter extends AbstractMemberWrite
* @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 = writer.getLink(new LinkInfoImpl(
configuration, LinkInfoImpl.Kind.EXECUTABLE_MEMBER_PARAM,
......
......@@ -174,9 +174,6 @@ public class AbstractIndexWriter extends HtmlDocletWriter {
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.Kind.INDEX, member, name));
Content dt = HtmlTree.DT(span);
......
......@@ -378,7 +378,7 @@ public abstract class AbstractMemberWriter {
* @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;
}
......
......@@ -156,14 +156,13 @@ public class AllClassesFrameWriter extends HtmlDocletWriter {
if (!Util.isCoreClass(cd)) {
continue;
}
String label = italicsClassName(cd, false);
Content label = italicsClassName(cd, false);
Content linkContent;
if(wantFrames){
if (wantFrames) {
linkContent = getLink(new LinkInfoImpl(configuration,
LinkInfoImpl.Kind.ALL_CLASSES_FRAME, cd, label, "classFrame"));
} else {
linkContent = getLink(new LinkInfoImpl(
configuration, cd, label));
linkContent = getLink(new LinkInfoImpl(configuration, cd, label));
}
Content li = HtmlTree.LI(linkContent);
content.addContent(li);
......
......@@ -239,8 +239,8 @@ public class FieldWriterImpl extends AbstractMemberWriter
* {@inheritDoc}
*/
public void addInheritedSummaryLabel(ClassDoc cd, Content inheritedTree) {
Content classLink = new RawHtml(writer.getPreQualifiedClassLink(
LinkInfoImpl.Kind.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"));
......
......@@ -1074,9 +1074,9 @@ public class HtmlDocletWriter extends HtmlDocWriter {
}
}
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;
}
/**
......@@ -1141,8 +1141,8 @@ public class HtmlDocletWriter extends HtmlDocWriter {
* @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 +1150,9 @@ public class HtmlDocletWriter extends HtmlDocWriter {
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 +1162,8 @@ public class HtmlDocletWriter extends HtmlDocWriter {
//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),
"");
......@@ -1193,7 +1193,7 @@ public class HtmlDocletWriter extends HtmlDocWriter {
*/
public Content getQualifiedClassLink(LinkInfoImpl.Kind context, ClassDoc cd) {
return getLink(new LinkInfoImpl(configuration, context, cd,
configuration.getClassName(cd), ""));
new StringContent(configuration.getClassName(cd)), ""));
}
/**
......@@ -1216,15 +1216,15 @@ public class HtmlDocletWriter extends HtmlDocWriter {
* @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(LinkInfoImpl.Kind 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, cd.name(), isStrong)));
return classlink;
}
......@@ -1269,7 +1269,8 @@ public class HtmlDocletWriter extends HtmlDocWriter {
* @return a content tree for the doc link
*/
public Content getDocLink(LinkInfoImpl.Kind context, MemberDoc doc, String label) {
return getDocLink(context, doc.containingClass(), doc, label);
return getDocLink(context, doc.containingClass(), doc,
new StringContent(label));
}
/**
......@@ -1317,10 +1318,15 @@ public class HtmlDocletWriter extends HtmlDocWriter {
* @return the link for the given member.
*/
public Content getDocLink(LinkInfoImpl.Kind context, ClassDoc classDoc, MemberDoc doc,
String label, boolean strong, boolean isProperty) {
String label, boolean strong, boolean isProperty) {
return getDocLink(context, classDoc, doc, new RawHtml(label), strong, isProperty);
}
public Content getDocLink(LinkInfoImpl.Kind context, ClassDoc classDoc, MemberDoc doc,
Content label, boolean strong, boolean isProperty) {
if (! (doc.isIncluded() ||
Util.isLinkable(classDoc, configuration))) {
return new RawHtml(label);
return label;
} else if (doc instanceof ExecutableMemberDoc) {
ExecutableMemberDoc emd = (ExecutableMemberDoc)doc;
return getLink(new LinkInfoImpl(configuration, context, classDoc,
......@@ -1329,7 +1335,7 @@ public class HtmlDocletWriter extends HtmlDocWriter {
return getLink(new LinkInfoImpl(configuration, context, classDoc,
doc.name(), label, strong));
} else {
return new RawHtml(label);
return label;
}
}
......@@ -1345,10 +1351,10 @@ public class HtmlDocletWriter extends HtmlDocWriter {
* @return the link for the given member
*/
public Content getDocLink(LinkInfoImpl.Kind context, ClassDoc classDoc, MemberDoc doc,
String label) {
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 getLink(new LinkInfoImpl(configuration, context, classDoc,
......@@ -1357,7 +1363,7 @@ public class HtmlDocletWriter extends HtmlDocWriter {
return getLink(new LinkInfoImpl(configuration, context, classDoc,
doc.name(), label, false));
} else {
return new StringContent(label);
return label;
}
}
......@@ -1399,10 +1405,10 @@ public class HtmlDocletWriter extends HtmlDocWriter {
}
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,37 +1421,37 @@ public class HtmlDocletWriter extends HtmlDocWriter {
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).toString();
} 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)).toString();
} else if ((classCrossLink = getCrossClassLink(refClassName,
refMemName, label, false, "", !plain)) != null) {
//Class cross link found (possibly to a member in the class)
return classCrossLink;
return classCrossLink.toString();
} else {
//No cross link found so print warning
configuration.getDocletSpecificMsg().warning(see.position(), "doclet.see.class_or_package_not_found",
tagName, seetext);
return (label.isEmpty() ? text: label);
return (label.isEmpty() ? text: label).toString();
}
}
} 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)).toString();
} 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.
return (label.isEmpty() ? text: label);
return (label.isEmpty() ? text: label).toString();
} else {
// Must be a member reference since refClass is not null and refMemName is not null.
// refMem is not null, so this @see tag must be referencing a valid member.
......@@ -1478,10 +1484,10 @@ public class HtmlDocletWriter extends HtmlDocWriter {
}
}
text = plainOrCodeText(plain, Util.escapeHtmlChars(refMemName));
text = plainOrCode(plain, new StringContent(refMemName));
return getDocLink(LinkInfoImpl.Kind.SEE_TAG, containing,
refMem, (label.isEmpty() ? text: label), false).toString();
refMem, (label.isEmpty() ? text: label).toString(), false).toString();
}
}
......@@ -1489,6 +1495,10 @@ public class HtmlDocletWriter extends HtmlDocWriter {
return (plain || text.isEmpty()) ? text : codeText(text);
}
private Content plainOrCode(boolean plain, Content body) {
return (plain || body.isEmpty()) ? body : HtmlTree.CODE(body);
}
/**
* Add the inline comment.
*
......@@ -2066,7 +2076,7 @@ public class HtmlDocletWriter extends HtmlDocWriter {
private void addAnnotations(AnnotationTypeDoc annotationDoc, LinkInfoImpl linkInfo,
StringBuilder annotation, AnnotationDesc.ElementValuePair[] pairs,
int indent, boolean linkBreak) {
linkInfo.label = "@" + annotationDoc.name();
linkInfo.label = new StringContent("@" + annotationDoc.name());
annotation.append(getLink(linkInfo));
if (pairs.length > 0) {
annotation.append('(');
......@@ -2144,9 +2154,9 @@ public class HtmlDocletWriter extends HtmlDocWriter {
if (type.asClassDoc() != null) {
LinkInfoImpl linkInfo = new LinkInfoImpl(configuration,
LinkInfoImpl.Kind.ANNOTATION, type);
linkInfo.label = (type.asClassDoc().isIncluded() ?
type.typeName() :
type.qualifiedTypeName()) + type.dimension() + ".class";
linkInfo.label = new StringContent((type.asClassDoc().isIncluded() ?
type.typeName() :
type.qualifiedTypeName()) + type.dimension() + ".class");
return getLink(linkInfo).toString();
} else {
return type.typeName() + type.dimension() + ".class";
......
......@@ -30,6 +30,7 @@ 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.*;
......@@ -65,7 +66,7 @@ public class LinkFactoryImpl extends LinkFactory {
*/
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.
......@@ -75,9 +76,8 @@ public class LinkFactoryImpl extends LinkFactory {
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);
classLinkInfo.displayLength += label.charCount();
Configuration configuration = m_writer.configuration;
Content link = new ContentBuilder();
if (classDoc.isIncluded()) {
......@@ -85,11 +85,11 @@ public class LinkFactoryImpl extends LinkFactory {
DocPath filename = getPath(classLinkInfo);
if (linkInfo.linkToSelf ||
!(DocPath.forName(classDoc)).equals(m_writer.filename)) {
link.addContent(new RawHtml(m_writer.getHyperLinkString(
link.addContent(m_writer.getHyperLink(
filename.fragment(classLinkInfo.where),
label.toString(),
label,
classLinkInfo.isStrong, classLinkInfo.styleName,
title, classLinkInfo.target)));
title, classLinkInfo.target));
if (noLabel && !classLinkInfo.excludeTypeParameterLinks) {
link.addContent(getTypeParameterLinks(linkInfo));
}
......@@ -97,12 +97,12 @@ public class LinkFactoryImpl extends LinkFactory {
}
}
} 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) {
link.addContent(new RawHtml(crossLink));
link.addContent(crossLink);
if (noLabel && !classLinkInfo.excludeTypeParameterLinks) {
link.addContent(getTypeParameterLinks(linkInfo));
}
......@@ -110,7 +110,7 @@ public class LinkFactoryImpl extends LinkFactory {
}
}
// Can't link so just write label.
link.addContent(new RawHtml(label.toString()));
link.addContent(label.toString());
if (noLabel && !classLinkInfo.excludeTypeParameterLinks) {
link.addContent(getTypeParameterLinks(linkInfo));
}
......
......@@ -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.*;
......@@ -222,7 +225,7 @@ public class LinkInfoImpl extends LinkInfo {
/**
* String style of text defined in style sheet.
*/
public String styleName ="";
public String styleName = "";
/**
* The value of the target.
......@@ -239,7 +242,7 @@ public class LinkInfoImpl extends LinkInfo {
* @param target the value of the target attribute.
*/
public LinkInfoImpl(ConfigurationImpl configuration,
Kind context, ClassDoc classDoc, String label, String target) {
Kind context, ClassDoc classDoc, Content label, String target) {
this.configuration = configuration;
this.classDoc = classDoc;
this.label = label;
......@@ -247,6 +250,13 @@ public class LinkInfoImpl extends LinkInfo {
setContext(context);
}
/**
* {@inherotDoc}
*/
protected Content newContent() {
return new ContentBuilder();
}
/**
* Construct a LinkInfo object.
*
......@@ -259,7 +269,7 @@ public class LinkInfoImpl extends LinkInfo {
* @param styleName String style of text defined in style sheet.
*/
public LinkInfoImpl(ConfigurationImpl configuration,
Kind context, ClassDoc classDoc, String where, String label,
Kind context, ClassDoc classDoc, String where, Content label,
boolean isStrong, String styleName) {
this.configuration = configuration;
this.classDoc = classDoc;
......@@ -277,17 +287,45 @@ public class LinkInfoImpl extends LinkInfo {
* @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 label the plain-text label for the link.
* @param isStrong true if the link should be strong.
*/
public LinkInfoImpl(ConfigurationImpl configuration,
Kind context, ClassDoc classDoc, String where, String label,
boolean isStrong) {
this(configuration, context, classDoc, where, new StringContent(label),
isStrong, "");
}
/**
* 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,
Kind context, ClassDoc classDoc, String where, Content label,
boolean isStrong) {
this(configuration, context, classDoc, where, label,
isStrong, "");
}
/**
* 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, Content label) {
this.configuration = configuration;
this.classDoc = classDoc;
this.where = where;
this.label = label;
this.isStrong = isStrong;
setContext(context);
}
......@@ -302,7 +340,7 @@ public class LinkInfoImpl extends LinkInfo {
ClassDoc classDoc, String label) {
this.configuration = configuration;
this.classDoc = classDoc;
this.label = label;
this.label = new StringContent(label);
setContext(context);
}
......@@ -375,12 +413,27 @@ public class LinkInfoImpl extends LinkInfo {
* @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 label plain-text label for the link.
* @param isStrong true if the link should be strong.
*/
public LinkInfoImpl(ConfigurationImpl configuration,
Kind context, Type type, String label,
boolean isStrong) {
this(configuration, context, type, new StringContent(label), isStrong);
}
/**
* 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.
*/
public LinkInfoImpl(ConfigurationImpl configuration,
Kind context, Type type, Content label,
boolean isStrong) {
this.configuration = configuration;
this.type = type;
this.label = label;
......@@ -394,12 +447,27 @@ public class LinkInfoImpl extends LinkInfo {
* @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 label plain-text label for the link.
* @param isStrong true if the link should be strong.
*/
public LinkInfoImpl(ConfigurationImpl configuration,
Kind context, ClassDoc classDoc, String label,
boolean isStrong) {
this(configuration, context, classDoc, new StringContent(label), isStrong);
}
/**
* 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.
*/
public LinkInfoImpl(ConfigurationImpl configuration,
Kind context, ClassDoc classDoc, Content label,
boolean isStrong) {
this.configuration = configuration;
this.classDoc = classDoc;
this.label = label;
......
......@@ -260,8 +260,8 @@ public class MethodWriterImpl extends AbstractExecutableMemberWriter
* {@inheritDoc}
*/
public void addInheritedSummaryLabel(ClassDoc cd, Content inheritedTree) {
Content classLink = new RawHtml(writer.getPreQualifiedClassLink(
LinkInfoImpl.Kind.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"));
......
......@@ -147,8 +147,8 @@ public class NestedClassWriterImpl extends AbstractMemberWriter
* {@inheritDoc}
*/
public void addInheritedSummaryLabel(ClassDoc cd, Content inheritedTree) {
Content classLink = new RawHtml(writer.getPreQualifiedClassLink(
LinkInfoImpl.Kind.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"));
......
......@@ -94,7 +94,7 @@ public class PackageFrameWriter extends HtmlDocletWriter {
packgen = new PackageFrameWriter(configuration, packageDoc);
String pkgName = Util.getPackageName(packageDoc);
Content body = packgen.getBody(false, packgen.getWindowTitle(pkgName));
Content pkgNameContent = new RawHtml(Util.escapeHtmlChars(pkgName));
Content pkgNameContent = new StringContent(pkgName);
Content heading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING, HtmlStyle.bar,
packgen.getTargetPackageLink(packageDoc, "classFrame", pkgNameContent));
body.addContent(heading);
......@@ -182,10 +182,10 @@ public class PackageFrameWriter extends HtmlDocletWriter {
contentTree.addContent(heading);
printedHeader = true;
}
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],
(arr[i].isInterface() ? italicsText(arr[i].name()) :
arr[i].name()),"classFrame"));
LinkInfoImpl.Kind.PACKAGE_FRAME, arr[i], arr_i_name, "classFrame"));
Content li = HtmlTree.LI(link);
ul.addContent(li);
}
......
......@@ -112,7 +112,7 @@ public class PackageIndexFrameWriter extends AbstractPackageIndexWriter {
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");
}
......
......@@ -173,10 +173,10 @@ public class ProfilePackageFrameWriter extends HtmlDocletWriter {
contentTree.addContent(heading);
printedHeader = true;
}
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],
(arr[i].isInterface() ? italicsText(arr[i].name()) :
arr[i].name()),"classFrame"));
LinkInfoImpl.Kind.PACKAGE_FRAME, arr[i], arr_i_name, "classFrame"));
Content li = HtmlTree.LI(link);
ul.addContent(li);
}
......
......@@ -118,7 +118,7 @@ public class ProfilePackageIndexFrameWriter extends AbstractProfileIndexWriter {
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");
}
......
......@@ -235,8 +235,8 @@ public class PropertyWriterImpl extends AbstractMemberWriter
* {@inheritDoc}
*/
public void addInheritedSummaryLabel(ClassDoc cd, Content inheritedTree) {
Content classLink = new RawHtml(writer.getPreQualifiedClassLink(
LinkInfoImpl.Kind.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"));
......
......@@ -127,10 +127,10 @@ public class SerializedFormWriterImpl extends SubWriterHolderWriter
* @return a content tree for the class header
*/
public Content getClassHeader(ClassDoc classDoc) {
String classLink = (classDoc.isPublic() || classDoc.isProtected()) ?
Content classLink = (classDoc.isPublic() || classDoc.isProtected()) ?
getLink(new LinkInfoImpl(configuration, classDoc,
configuration.getClassName(classDoc))).toString() :
classDoc.qualifiedName();
configuration.getClassName(classDoc))) :
new StringContent(classDoc.qualifiedName());
Content li = HtmlTree.LI(HtmlStyle.blockList, getMarkerAnchor(
classDoc.qualifiedName()));
String superClassLink =
......@@ -143,9 +143,9 @@ public class SerializedFormWriterImpl extends SubWriterHolderWriter
//Print the heading.
String className = superClassLink == null ?
configuration.getText(
"doclet.Class_0_implements_serializable", classLink) :
"doclet.Class_0_implements_serializable", classLink.toString()) :
configuration.getText(
"doclet.Class_0_extends_implements_serializable", classLink,
"doclet.Class_0_extends_implements_serializable", classLink.toString(),
superClassLink);
Content classNameContent = new RawHtml(className);
li.addContent(HtmlTree.HEADING(HtmlConstants.SERIALIZED_MEMBER_HEADING,
......
/*
* 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 @@ public class SourceToHTMLConverter {
/**
* 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;
......@@ -271,8 +271,7 @@ public class SourceToHTMLConverter {
if (line != null) {
StringBuilder lineBuffer = new StringBuilder(line);
Util.replaceTabs(configuration, lineBuffer);
Util.escapeHtmlChars(lineBuffer);
pre.addContent(new RawHtml(lineBuffer.toString()));
pre.addContent(lineBuffer.toString());
Content anchor = HtmlTree.A_NAME("line." + Integer.toString(currentLineNo));
pre.addContent(anchor);
pre.addContent(NEW_LINE);
......
......@@ -180,8 +180,7 @@ public class TagletWriterImpl extends TagletWriter {
((ClassWriterImpl) htmlWriter).getClassDoc().qualifiedName() + "." + ((FieldDoc) holder).name();
DocLink link = constantsPath.fragment(whichConstant);
result += htmlWriter.getHyperLinkString(link,
configuration.getText("doclet.Constants_Summary"),
false);
configuration.getText("doclet.Constants_Summary"));
}
if (holder.isClass() && ((ClassDoc)holder).isSerializable()) {
//Automatically add link to serialized form page for serializable classes.
......@@ -191,7 +190,7 @@ public class TagletWriterImpl extends TagletWriter {
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);
configuration.getText("doclet.Serialized_Form"));
}
}
return result.equals("") ? null : new TagletOutputImpl(result + "</dd>");
......
......@@ -81,6 +81,13 @@ public class ContentBuilder extends Content {
return true;
}
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>();
......
/*
* 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.*;
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;
/**
......@@ -73,21 +72,18 @@ public abstract class HtmlDocWriter extends HtmlWriter {
public abstract Configuration configuration();
/**
* Return Html Hyper Link string.
* Return Html hyperlink 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(DocPath link, String label) {
return getHyperLinkString(link, label, false, "", "", "");
}
public String getHyperLinkString(DocLink link,
String label, boolean strong) {
return getHyperLinkString(link, label, strong, "", "", "");
public String getHyperLinkString(DocLink link, String label) {
return getHyperLinkString(link, label, false, "", "", "");
}
/**
......@@ -125,19 +121,17 @@ public abstract class HtmlDocWriter extends HtmlWriter {
}
/**
* 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, "", "");
}
......@@ -190,6 +184,28 @@ public abstract class HtmlDocWriter extends HtmlWriter {
return retlink.toString();
}
public Content getHyperLink(DocLink link,
Content label, boolean strong,
String stylename, String title, String target) {
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) {
l.addAttr(HtmlAttr.TITLE, title);
}
if (target != null && target.length() != 0) {
l.addAttr(HtmlAttr.TARGET, target);
}
return l;
}
/**
* Get Html Hyper Link.
*
......@@ -216,17 +232,6 @@ public abstract class HtmlDocWriter extends HtmlWriter {
return anchor;
}
/**
* 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.
*
......
......@@ -123,6 +123,13 @@ public class HtmlTree extends Content {
addContent(new StringContent(stringContent));
}
public int charCount() {
int n = 0;
for (Content c : content)
n += c.charCount();
return n;
}
/**
* Generates an HTML anchor tag.
*
......
......@@ -303,10 +303,11 @@ public class HtmlWriter {
*
* @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 +401,6 @@ public class HtmlWriter {
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>";
}
......
/*
* 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 @@ import com.sun.tools.doclets.internal.toolkit.util.*;
*
* @author Bhavesh Patel
*/
public class RawHtml extends Content{
public class RawHtml extends Content {
private String rawHtmlContent;
......@@ -90,10 +90,61 @@ public class RawHtml extends Content{
/**
* {@inheritDoc}
*/
@Override
public String toString() {
return rawHtmlContent;
}
private enum State { TEXT, ENTITY, TAG, STRING };
@Override
public int charCount() {
State state = State.TEXT;
int count = 0;
for (int i = 0; i < rawHtmlContent.length(); i++) {
char c = rawHtmlContent.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}
*/
......
/*
* 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
......@@ -91,6 +91,10 @@ public class StringContent extends Content{
return (stringContent.length() == 0);
}
public int charCount() {
return stringContent.length();
}
/**
* {@inheritDoc}
*/
......
......@@ -96,6 +96,10 @@ public abstract class Content {
return !isEmpty();
}
public int charCount() {
throw new UnsupportedOperationException();
}
/**
* Checks for null values.
*
......
......@@ -95,7 +95,9 @@ public abstract class LinkFactory {
if ((! linkInfo.excludeTypeParameterLinks) &&
owner instanceof ClassDoc) {
linkInfo.classDoc = (ClassDoc) owner;
linkInfo.label = type.typeName();
Content label = newContent();
label.addContent(type.typeName());
linkInfo.label = label;
link.addContent(getClassLink(linkInfo));
} else {
//No need to link method type parameters.
......
......@@ -27,6 +27,7 @@ package com.sun.tools.doclets.internal.toolkit.util.links;
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 @@ public abstract class LinkInfo {
/**
* The label for the link.
*/
public String label;
public Content label;
/**
* True if the link should be strong.
......@@ -120,6 +121,13 @@ public abstract class LinkInfo {
*/
public int displayLength = 0;
/**
* Return an empty instance of a content object.
*
* @return an empty instance of a content object.
*/
protected abstract Content newContent();
/**
* Return true if this link is linkable and false if we can't link to the
* desired place.
......@@ -135,13 +143,17 @@ public abstract class LinkInfo {
* @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;
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册