8214126: Method signatures not formatted correctly in browser

Reviewed-by: jjg
This commit is contained in:
Hannes Wallnöfer 2019-06-04 16:33:37 +02:00
parent 4d08dd703e
commit 4b01aa4f71
41 changed files with 1305 additions and 883 deletions

View file

@ -73,19 +73,6 @@ public abstract class AbstractExecutableMemberWriter extends AbstractMemberWrite
super(writer);
}
/**
* Add the type parameters for the executable member.
*
* @param member the member to write type parameters for.
* @param htmltree the content tree to which the parameters will be added.
*/
protected void addTypeParameters(ExecutableElement member, Content htmltree) {
Content typeParameters = getTypeParameters(member);
if (!typeParameters.isEmpty()) {
htmltree.add(typeParameters);
htmltree.add(Entity.NO_BREAK_SPACE);
}
}
/**
* Get the type parameters for the executable member.
@ -134,7 +121,7 @@ public abstract class AbstractExecutableMemberWriter extends AbstractMemberWrite
writer.getDocLink(context, te, ee,
name(ee), false));
Content code = HtmlTree.CODE(memberLink);
addParameters(ee, false, code, name(ee).length() - 1);
addParameters(ee, code);
tdSummary.add(code);
}
@ -174,7 +161,7 @@ public abstract class AbstractExecutableMemberWriter extends AbstractMemberWrite
*
* @param member the member to write receiver annotations for.
* @param rcvrType the receiver type.
* @param descList list of annotation description.
* @param annotationMirrors list of annotation descriptions.
* @param tree the content tree to which the information will be added.
*/
protected void addReceiverAnnotations(ExecutableElement member, TypeMirror rcvrType,
@ -195,66 +182,8 @@ public abstract class AbstractExecutableMemberWriter extends AbstractMemberWrite
* @param member the member to write parameters for.
* @param htmltree the content tree to which the parameters information will be added.
*/
protected void addParameters(ExecutableElement member, Content htmltree, int indentSize) {
addParameters(member, true, htmltree, indentSize);
}
/**
* Add all the parameters for the executable member.
*
* @param member the member to write parameters for.
* @param includeAnnotations true if annotation information needs to be added.
* @param htmltree the content tree to which the parameters information will be added.
*/
protected void addParameters(ExecutableElement member,
boolean includeAnnotations, Content htmltree, int indentSize) {
Content paramTree = new ContentBuilder();
String sep = "";
List<? extends VariableElement> parameters = member.getParameters();
CharSequence indent = makeSpace(indentSize + 1);
TypeMirror rcvrType = member.getReceiverType();
if (includeAnnotations && rcvrType != null && utils.isAnnotated(rcvrType)) {
List<? extends AnnotationMirror> annotationMirrors = rcvrType.getAnnotationMirrors();
addReceiverAnnotations(member, rcvrType, annotationMirrors, paramTree);
sep = "," + DocletConstants.NL + indent;
}
int paramstart;
for (paramstart = 0; paramstart < parameters.size(); paramstart++) {
paramTree.add(sep);
VariableElement param = parameters.get(paramstart);
if (param.getKind() != ElementKind.INSTANCE_INIT) {
if (includeAnnotations) {
boolean foundAnnotations =
writer.addAnnotationInfo(indent.length(),
member, param, paramTree);
if (foundAnnotations) {
paramTree.add(DocletConstants.NL);
paramTree.add(indent);
}
}
addParam(member, param,
(paramstart == parameters.size() - 1) && member.isVarArgs(), paramTree);
break;
}
}
for (int i = paramstart + 1; i < parameters.size(); i++) {
paramTree.add(",");
paramTree.add(DocletConstants.NL);
paramTree.add(indent);
if (includeAnnotations) {
boolean foundAnnotations =
writer.addAnnotationInfo(indent.length(), member, parameters.get(i),
paramTree);
if (foundAnnotations) {
paramTree.add(DocletConstants.NL);
paramTree.add(indent);
}
}
addParam(member, parameters.get(i), (i == parameters.size() - 1) && member.isVarArgs(),
paramTree);
}
protected void addParameters(ExecutableElement member, Content htmltree) {
Content paramTree = getParameters(member, false);
if (paramTree.isEmpty()) {
htmltree.add("()");
} else {
@ -266,30 +195,80 @@ public abstract class AbstractExecutableMemberWriter extends AbstractMemberWrite
}
/**
* Add exceptions for the executable member.
* Add all the parameters for the executable member.
*
* @param member the member to write parameters for.
* @param includeAnnotations true if annotation information needs to be added.
* @return the content tree containing the parameter information
*/
protected Content getParameters(ExecutableElement member, boolean includeAnnotations) {
Content paramTree = new ContentBuilder();
String sep = "";
List<? extends VariableElement> parameters = member.getParameters();
TypeMirror rcvrType = member.getReceiverType();
if (includeAnnotations && rcvrType != null && utils.isAnnotated(rcvrType)) {
List<? extends AnnotationMirror> annotationMirrors = rcvrType.getAnnotationMirrors();
addReceiverAnnotations(member, rcvrType, annotationMirrors, paramTree);
sep = "," + DocletConstants.NL;
}
int paramstart;
for (paramstart = 0; paramstart < parameters.size(); paramstart++) {
paramTree.add(sep);
VariableElement param = parameters.get(paramstart);
if (param.getKind() != ElementKind.INSTANCE_INIT) {
if (includeAnnotations) {
boolean foundAnnotations =
writer.addAnnotationInfo(param, paramTree);
if (foundAnnotations) {
paramTree.add(DocletConstants.NL);
}
}
addParam(member, param,
(paramstart == parameters.size() - 1) && member.isVarArgs(), paramTree);
break;
}
}
for (int i = paramstart + 1; i < parameters.size(); i++) {
paramTree.add(",");
paramTree.add(DocletConstants.NL);
if (includeAnnotations) {
boolean foundAnnotations =
writer.addAnnotationInfo(parameters.get(i),
paramTree);
if (foundAnnotations) {
paramTree.add(DocletConstants.NL);
}
}
addParam(member, parameters.get(i), (i == parameters.size() - 1) && member.isVarArgs(),
paramTree);
}
return paramTree;
}
/**
* Get a content tree containing the exception information for the executable member.
*
* @param member the member to write exceptions for.
* @param htmltree the content tree to which the exceptions information will be added.
* @return the content tree containing the exceptions information.
*/
protected void addExceptions(ExecutableElement member, Content htmltree, int indentSize) {
protected Content getExceptions(ExecutableElement member) {
List<? extends TypeMirror> exceptions = member.getThrownTypes();
Content htmltree = new ContentBuilder();
if (!exceptions.isEmpty()) {
CharSequence indent = makeSpace(indentSize + 1 - 7);
htmltree.add(DocletConstants.NL);
htmltree.add(indent);
htmltree.add("throws ");
indent = makeSpace(indentSize + 1);
Content link = writer.getLink(new LinkInfoImpl(configuration, MEMBER, exceptions.get(0)));
htmltree.add(link);
for(int i = 1; i < exceptions.size(); i++) {
htmltree.add(",");
htmltree.add(DocletConstants.NL);
htmltree.add(indent);
Content exceptionLink = writer.getLink(new LinkInfoImpl(configuration, MEMBER,
exceptions.get(i)));
htmltree.add(exceptionLink);
}
}
return htmltree;
}
protected TypeElement implementsMethodInIntfac(ExecutableElement method,

View file

@ -46,12 +46,14 @@ import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle;
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTag;
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree;
import jdk.javadoc.internal.doclets.formats.html.markup.Links;
import jdk.javadoc.internal.doclets.formats.html.markup.StringContent;
import jdk.javadoc.internal.doclets.formats.html.markup.Table;
import jdk.javadoc.internal.doclets.formats.html.markup.TableHeader;
import jdk.javadoc.internal.doclets.toolkit.Content;
import jdk.javadoc.internal.doclets.toolkit.MemberSummaryWriter;
import jdk.javadoc.internal.doclets.toolkit.Resources;
import jdk.javadoc.internal.doclets.toolkit.taglets.DeprecatedTaglet;
import jdk.javadoc.internal.doclets.toolkit.util.DocletConstants;
import jdk.javadoc.internal.doclets.toolkit.util.Utils;
import static javax.lang.model.element.Modifier.ABSTRACT;
@ -219,55 +221,6 @@ public abstract class AbstractMemberWriter implements MemberSummaryWriter {
*/
protected abstract Content getDeprecatedLink(Element member);
/**
* 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.add(name);
}
/**
* Add the modifier for the member. The modifiers are ordered as specified
* by <em>The Java Language Specification</em>.
*
* @param member the member for which the modifier will be added.
* @param htmltree the content tree to which the modifier information will be added.
*/
protected void addModifiers(Element member, Content htmltree) {
Set<Modifier> set = new TreeSet<>(member.getModifiers());
// remove the ones we really don't need
set.remove(NATIVE);
set.remove(SYNCHRONIZED);
set.remove(STRICTFP);
// According to JLS, we should not be showing public modifier for
// interface methods.
if ((utils.isField(member) || utils.isMethod(member))
&& ((writer instanceof ClassWriterImpl
&& utils.isInterface(((ClassWriterImpl) writer).getTypeElement()) ||
writer instanceof AnnotationTypeWriterImpl) )) {
// Remove the implicit abstract and public modifiers
if (utils.isMethod(member) &&
(utils.isInterface(member.getEnclosingElement()) ||
utils.isAnnotationType(member.getEnclosingElement()))) {
set.remove(ABSTRACT);
set.remove(PUBLIC);
}
if (!utils.isMethod(member)) {
set.remove(PUBLIC);
}
}
if (!set.isEmpty()) {
String mods = set.stream().map(Modifier::toString).collect(Collectors.joining(" "));
htmltree.add(mods);
htmltree.add(Entity.NO_BREAK_SPACE);
}
}
protected CharSequence makeSpace(int len) {
if (len <= 0) {
return "";
@ -563,4 +516,237 @@ public abstract class AbstractMemberWriter implements MemberSummaryWriter {
else
return HtmlTree.LI(HtmlStyle.blockList, memberTree);
}
/**
* A content builder for member signatures.
*/
class MemberSignature {
private Element element;
private Content typeParameters;
private Content returnType;
private Content parameters;
private Content exceptions;
// Threshold for length of type parameters before switching from inline to block representation.
private final static int TYPE_PARAMS_MAX_INLINE_LENGTH = 50;
// Threshold for combined length of modifiers, type params and return type before breaking
// it up with a line break before the return type.
private final static int RETURN_TYPE_MAX_LINE_LENGTH = 50;
/**
* Create a new member signature builder.
*
* @param element The element for which to create a signature.
*/
MemberSignature(Element element) {
this.element = element;
}
/**
* Add the type parameters for an executable member.
*
* @param typeParameters the content tree containing the type parameters to add.
* @return this MemberSignature instance
*/
MemberSignature addTypeParameters(Content typeParameters) {
this.typeParameters = typeParameters;
return this;
}
/**
* Add the return type for an executable member.
*
* @param returnType the content tree containing the return type to add.
* @return this MemberSignature instance
*/
MemberSignature addReturnType(Content returnType) {
this.returnType = returnType;
return this;
}
/**
* Add the type information for a non-executable member.
*
* @param type the type of the member.
* @return this MemberSignature instance
*/
MemberSignature addType(TypeMirror type) {
this.returnType = writer.getLink(new LinkInfoImpl(configuration, LinkInfoImpl.Kind.MEMBER, type));
return this;
}
/**
* Add the parameter information of an executable member.
*
* @param paramTree the content tree containing the parameter information.
* @return this MemberSignature instance
*/
MemberSignature addParameters(Content paramTree) {
this.parameters = paramTree;
return this;
}
/**
* Add the exception information of an executable member.
*
* @param exceptionTree the content tree containing the exception information
* @return this MemberSignature instance
*/
MemberSignature addExceptions(Content exceptionTree) {
this.exceptions = exceptionTree;
return this;
}
/**
* Return a HTML tree containing the member signature.
*
* @return a HTML tree containing the member signature
*/
Content toContent() {
Content content = new ContentBuilder();
// Position of last line separator.
int lastLineSeparator = 0;
// Annotations
Content annotationInfo = writer.getAnnotationInfo(element.getAnnotationMirrors(), true);
if (!annotationInfo.isEmpty()) {
content.add(HtmlTree.SPAN(HtmlStyle.annotations, annotationInfo));
lastLineSeparator = content.charCount();
}
// Modifiers
appendModifiers(content);
// Type parameters
if (typeParameters != null && !typeParameters.isEmpty()) {
lastLineSeparator = appendTypeParameters(content, lastLineSeparator);
}
// Return type
if (returnType != null) {
content.add(HtmlTree.SPAN(HtmlStyle.returnType, returnType));
content.add(Entity.NO_BREAK_SPACE);
}
// Name
HtmlTree nameSpan = new HtmlTree(HtmlTag.SPAN);
nameSpan.setStyle(HtmlStyle.memberName);
if (configuration.linksource) {
Content name = new StringContent(name(element));
writer.addSrcLink(element, name, nameSpan);
} else {
nameSpan.add(name(element));
}
content.add(nameSpan);
// Parameters and exceptions
if (parameters != null) {
appendParametersAndExceptions(content, lastLineSeparator);
}
return HtmlTree.DIV(HtmlStyle.memberSignature, content);
}
/**
* Add the modifier for the member. The modifiers are ordered as specified
* by <em>The Java Language Specification</em>.
*
* @param htmltree the content tree to which the modifier information will be added.
*/
private void appendModifiers(Content htmltree) {
Set<Modifier> set = new TreeSet<>(element.getModifiers());
// remove the ones we really don't need
set.remove(NATIVE);
set.remove(SYNCHRONIZED);
set.remove(STRICTFP);
// According to JLS, we should not be showing public modifier for
// interface methods.
if ((utils.isField(element) || utils.isMethod(element))
&& ((writer instanceof ClassWriterImpl
&& utils.isInterface(((ClassWriterImpl) writer).getTypeElement()) ||
writer instanceof AnnotationTypeWriterImpl) )) {
// Remove the implicit abstract and public modifiers
if (utils.isMethod(element) &&
(utils.isInterface(element.getEnclosingElement()) ||
utils.isAnnotationType(element.getEnclosingElement()))) {
set.remove(ABSTRACT);
set.remove(PUBLIC);
}
if (!utils.isMethod(element)) {
set.remove(PUBLIC);
}
}
if (!set.isEmpty()) {
String mods = set.stream().map(Modifier::toString).collect(Collectors.joining(" "));
htmltree.add(HtmlTree.SPAN(HtmlStyle.modifiers, new StringContent(mods)));
htmltree.add(Entity.NO_BREAK_SPACE);
}
}
/**
* Append the type parameter information to the HTML tree.
*
* @param htmltree the HTML tree
* @param lastLineSeparator index of last line separator in HTML tree
* @return the new index of the last line separator
*/
private int appendTypeParameters(Content htmltree, int lastLineSeparator) {
// Apply different wrapping strategies for type parameters
// depending of combined length of type parameters and return type.
int typeParamLength = typeParameters.charCount();
if (typeParamLength >= TYPE_PARAMS_MAX_INLINE_LENGTH) {
htmltree.add(HtmlTree.SPAN(HtmlStyle.typeParametersLong, typeParameters));
} else {
htmltree.add(HtmlTree.SPAN(HtmlStyle.typeParameters, typeParameters));
}
int lineLength = htmltree.charCount() - lastLineSeparator;
int newLastLineSeparator = lastLineSeparator;
// sum below includes length of modifiers plus type params added above
if (lineLength + returnType.charCount()> RETURN_TYPE_MAX_LINE_LENGTH) {
htmltree.add(DocletConstants.NL);
newLastLineSeparator = htmltree.charCount();
} else {
htmltree.add(Entity.NO_BREAK_SPACE);
}
return newLastLineSeparator;
}
/**
* Append the parameters and exceptions information to the HTML tree.
*
* @param htmltree the HTML tree
* @param lastLineSeparator the index of the last line separator in HTML tree
*/
private void appendParametersAndExceptions(Content htmltree, int lastLineSeparator) {
// Record current position for indentation of exceptions
int indentSize = htmltree.charCount() - lastLineSeparator;
if (parameters.isEmpty()) {
htmltree.add("()");
} else {
parameters.add(")");
htmltree.add(Entity.ZERO_WIDTH_SPACE);
htmltree.add("(");
htmltree.add(HtmlTree.SPAN(HtmlStyle.arguments, parameters));
}
// Exceptions
if (exceptions != null && !exceptions.isEmpty()) {
CharSequence indent = makeSpace(indentSize + 1 - 7);
htmltree.add(DocletConstants.NL);
htmltree.add(indent);
htmltree.add("throws ");
htmltree.add(HtmlTree.SPAN(HtmlStyle.exceptions, exceptions));
}
}
}
}

View file

@ -33,7 +33,6 @@ import javax.lang.model.type.TypeMirror;
import jdk.javadoc.internal.doclets.formats.html.markup.ContentBuilder;
import jdk.javadoc.internal.doclets.formats.html.markup.Entity;
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle;
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTag;
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree;
import jdk.javadoc.internal.doclets.formats.html.markup.StringContent;
import jdk.javadoc.internal.doclets.formats.html.markup.Table;
@ -132,21 +131,9 @@ public class AnnotationTypeFieldWriterImpl extends AbstractMemberWriter
* {@inheritDoc}
*/
public Content getSignature(Element member) {
Content pre = new HtmlTree(HtmlTag.PRE);
writer.addAnnotationInfo(member, pre);
addModifiers(member, pre);
Content link =
writer.getLink(new LinkInfoImpl(configuration,
LinkInfoImpl.Kind.MEMBER, getType(member)));
pre.add(link);
pre.add(Entity.NO_BREAK_SPACE);
if (configuration.linksource) {
Content memberName = new StringContent(name(member));
writer.addSrcLink(member, memberName, pre);
} else {
addName(name(member), pre);
}
return pre;
return new MemberSignature(member)
.addType(getType(member))
.toContent();
}
/**

View file

@ -31,11 +31,8 @@ import javax.lang.model.element.TypeElement;
import javax.lang.model.type.TypeMirror;
import jdk.javadoc.internal.doclets.formats.html.markup.ContentBuilder;
import jdk.javadoc.internal.doclets.formats.html.markup.Entity;
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle;
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTag;
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree;
import jdk.javadoc.internal.doclets.formats.html.markup.StringContent;
import jdk.javadoc.internal.doclets.formats.html.markup.Table;
import jdk.javadoc.internal.doclets.formats.html.markup.TableHeader;
import jdk.javadoc.internal.doclets.toolkit.AnnotationTypeRequiredMemberWriter;
@ -136,21 +133,9 @@ public class AnnotationTypeRequiredMemberWriterImpl extends AbstractMemberWriter
* {@inheritDoc}
*/
public Content getSignature(Element member) {
Content pre = new HtmlTree(HtmlTag.PRE);
writer.addAnnotationInfo(member, pre);
addModifiers(member, pre);
Content link =
writer.getLink(new LinkInfoImpl(configuration,
LinkInfoImpl.Kind.MEMBER, getType(member)));
pre.add(link);
pre.add(Entity.NO_BREAK_SPACE);
if (configuration.linksource) {
Content memberName = new StringContent(name(member));
writer.addSrcLink(member, memberName, pre);
} else {
addName(name(member), pre);
}
return pre;
return new MemberSignature(member)
.addType(getType(member))
.toContent();
}
/**

View file

@ -37,7 +37,6 @@ import jdk.javadoc.internal.doclets.formats.html.markup.Entity;
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle;
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTag;
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree;
import jdk.javadoc.internal.doclets.formats.html.markup.StringContent;
import jdk.javadoc.internal.doclets.formats.html.markup.Table;
import jdk.javadoc.internal.doclets.formats.html.markup.TableHeader;
import jdk.javadoc.internal.doclets.toolkit.ConstructorWriter;
@ -152,20 +151,10 @@ public class ConstructorWriterImpl extends AbstractExecutableMemberWriter
*/
@Override
public Content getSignature(ExecutableElement constructor) {
Content pre = new HtmlTree(HtmlTag.PRE);
writer.addAnnotationInfo(constructor, pre);
int annotationLength = pre.charCount();
addModifiers(constructor, pre);
if (configuration.linksource) {
Content constructorName = new StringContent(name(constructor));
writer.addSrcLink(constructor, constructorName, pre);
} else {
addName(name(constructor), pre);
}
int indent = pre.charCount() - annotationLength;
addParameters(constructor, pre, indent);
addExceptions(constructor, pre, indent);
return pre;
return new MemberSignature(constructor)
.addParameters(getParameters(constructor, true))
.addExceptions(getExceptions(constructor))
.toContent();
}
/**

View file

@ -32,9 +32,7 @@ import javax.lang.model.element.VariableElement;
import jdk.javadoc.internal.doclets.formats.html.markup.ContentBuilder;
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle;
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTag;
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree;
import jdk.javadoc.internal.doclets.formats.html.markup.StringContent;
import jdk.javadoc.internal.doclets.formats.html.markup.Table;
import jdk.javadoc.internal.doclets.formats.html.markup.TableHeader;
import jdk.javadoc.internal.doclets.toolkit.Content;
@ -118,20 +116,9 @@ public class EnumConstantWriterImpl extends AbstractMemberWriter
*/
@Override
public Content getSignature(VariableElement enumConstant) {
Content pre = new HtmlTree(HtmlTag.PRE);
writer.addAnnotationInfo(enumConstant, pre);
addModifiers(enumConstant, pre);
Content enumConstantLink = writer.getLink(new LinkInfoImpl(
configuration, LinkInfoImpl.Kind.MEMBER, enumConstant.asType()));
pre.add(enumConstantLink);
pre.add(" ");
if (configuration.linksource) {
Content enumConstantName = new StringContent(name(enumConstant));
writer.addSrcLink(enumConstant, enumConstantName, pre);
} else {
addName(name(enumConstant), pre);
}
return pre;
return new MemberSignature(enumConstant)
.addType(enumConstant.asType())
.toContent();
}
/**

View file

@ -35,7 +35,6 @@ import javax.lang.model.element.VariableElement;
import jdk.javadoc.internal.doclets.formats.html.markup.ContentBuilder;
import jdk.javadoc.internal.doclets.formats.html.markup.Entity;
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle;
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTag;
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree;
import jdk.javadoc.internal.doclets.formats.html.markup.StringContent;
import jdk.javadoc.internal.doclets.formats.html.markup.Table;
@ -121,20 +120,9 @@ public class FieldWriterImpl extends AbstractMemberWriter
*/
@Override
public Content getSignature(VariableElement field) {
Content pre = new HtmlTree(HtmlTag.PRE);
writer.addAnnotationInfo(field, pre);
addModifiers(field, pre);
Content fieldlink = writer.getLink(new LinkInfoImpl(
configuration, LinkInfoImpl.Kind.MEMBER, field.asType()));
pre.add(fieldlink);
pre.add(" ");
if (configuration.linksource) {
Content fieldName = new StringContent(name(field));
writer.addSrcLink(field, fieldName, pre);
} else {
addName(name(field), pre);
}
return pre;
return new MemberSignature(field)
.addType(field.asType())
.toContent();
}
/**

View file

@ -1715,20 +1715,7 @@ public class HtmlDocletWriter {
* added
*/
public void addAnnotationInfo(PackageElement packageElement, Content htmltree) {
addAnnotationInfo(packageElement, packageElement.getAnnotationMirrors(), htmltree);
}
/**
* Add the annotation types of the executable receiver.
*
* @param method the executable to write the receiver annotations for.
* @param descList a list of annotation mirrors.
* @param htmltree the documentation tree to which the annotation info will be
* added
*/
public void addReceiverAnnotationInfo(ExecutableElement method, List<AnnotationMirror> descList,
Content htmltree) {
addAnnotationInfo(0, method, descList, false, htmltree);
addAnnotationInfo(packageElement.getAnnotationMirrors(), htmltree);
}
/*
@ -1739,7 +1726,7 @@ public class HtmlDocletWriter {
List<? extends AnnotationMirror> annotationMirrors, Content htmltree) {
TypeMirror rcvrType = method.getReceiverType();
List<? extends AnnotationMirror> annotationMirrors1 = rcvrType.getAnnotationMirrors();
addAnnotationInfo(0, method, annotationMirrors1, false, htmltree);
htmltree.add(getAnnotationInfo(annotationMirrors1, false));
}
/**
@ -1749,97 +1736,65 @@ public class HtmlDocletWriter {
* @param htmltree the content tree to which the annotation types will be added
*/
public void addAnnotationInfo(Element element, Content htmltree) {
addAnnotationInfo(element, element.getAnnotationMirrors(), htmltree);
addAnnotationInfo(element.getAnnotationMirrors(), htmltree);
}
/**
* Add the annotatation types for the given element and parameter.
*
* @param indent the number of spaces to indent the parameters.
* @param element the element to write annotations for.
* @param param the parameter to write annotations for.
* @param tree the content tree to which the annotation types will be added
*/
public boolean addAnnotationInfo(int indent, Element element, VariableElement param,
Content tree) {
return addAnnotationInfo(indent, element, param.getAnnotationMirrors(), false, tree);
public boolean addAnnotationInfo(VariableElement param, Content tree) {
Content annotaionInfo = getAnnotationInfo(param.getAnnotationMirrors(), false);
if (annotaionInfo.isEmpty()) {
return false;
}
tree.add(annotaionInfo);
return true;
}
/**
* Adds the annotatation types for the given Element.
*
* @param element the element to write annotations for.
* @param descList a list of annotation mirrors.
* @param htmltree the documentation tree to which the annotation info will be
* added
*/
private void addAnnotationInfo(Element element, List<? extends AnnotationMirror> descList,
Content htmltree) {
addAnnotationInfo(0, element, descList, true, htmltree);
private void addAnnotationInfo(List<? extends AnnotationMirror> descList, Content htmltree) {
htmltree.add(getAnnotationInfo(descList, true));
}
/**
* Adds the annotation types for the given element.
* Return a content tree containing the annotation types for the given element.
*
* @param indent the number of extra spaces to indent the annotations.
* @param element the element to write annotations for.
* @param descList a list of annotation mirrors.
* @param htmltree the documentation tree to which the annotation info will be
* added
* @return the documentation tree containing the annotation info.
*/
private boolean addAnnotationInfo(int indent, Element element,
List<? extends AnnotationMirror> descList, boolean lineBreak, Content htmltree) {
List<Content> annotations = getAnnotations(indent, descList, lineBreak);
Content getAnnotationInfo(List<? extends AnnotationMirror> descList, boolean lineBreak) {
List<Content> annotations = getAnnotations(descList, lineBreak);
String sep = "";
if (annotations.isEmpty()) {
return false;
}
ContentBuilder builder = new ContentBuilder();
for (Content annotation: annotations) {
htmltree.add(sep);
htmltree.add(annotation);
builder.add(sep);
builder.add(annotation);
if (!lineBreak) {
sep = " ";
}
}
return true;
}
/**
* Return the string representations of the annotation types for
* the given doc.
*
* @param indent the number of extra spaces to indent the annotations.
* @param descList a list of annotation mirrors.
* @param linkBreak if true, add new line between each member value.
* @return a list of strings representing the annotations being
* documented.
*/
private List<Content> getAnnotations(int indent, List<? extends AnnotationMirror> descList, boolean linkBreak) {
return getAnnotations(indent, descList, linkBreak, true);
}
private List<Content> getAnnotations(int indent, AnnotationMirror amirror, boolean linkBreak) {
List<AnnotationMirror> descList = new ArrayList<>();
descList.add(amirror);
return getAnnotations(indent, descList, linkBreak, true);
return builder;
}
/**
* Return the string representations of the annotation types for
* the given doc.
*
* A {@code null} {@code elementType} indicates that all the
* annotations should be returned without any filtering.
*
* @param indent the number of extra spaces to indent the annotations.
* @param descList a list of annotation mirrors.
* @param linkBreak if true, add new line between each member value.
* @param isJava5DeclarationLocation
* @return a list of strings representing the annotations being
* documented.
*/
public List<Content> getAnnotations(int indent, List<? extends AnnotationMirror> descList,
boolean linkBreak, boolean isJava5DeclarationLocation) {
public List<Content> getAnnotations(List<? extends AnnotationMirror> descList, boolean linkBreak) {
List<Content> results = new ArrayList<>();
ContentBuilder annotation;
for (AnnotationMirror aDesc : descList) {
@ -1853,11 +1808,6 @@ public class HtmlDocletWriter {
(!isAnnotationDocumented && !isContainerDocumented)) {
continue;
}
/* TODO: check logic here to correctly handle declaration
* and type annotations.
if (utils.isDeclarationAnnotation(annotationElement, isJava5DeclarationLocation)) {
continue;
}*/
annotation = new ContentBuilder();
isAnnotationDocumented = false;
LinkInfoImpl linkInfo = new LinkInfoImpl(configuration,
@ -1900,9 +1850,7 @@ public class HtmlDocletWriter {
new SimpleAnnotationValueVisitor9<Void, List<AnnotationValue>>() {
@Override
public Void visitArray(List<? extends AnnotationValue> vals, List<AnnotationValue> annotationTypeValues) {
for (AnnotationValue av : vals) {
annotationTypeValues.add(av);
}
annotationTypeValues.addAll(vals);
return null;
}
}.visit(a, annotationTypeValues);
@ -1917,13 +1865,11 @@ public class HtmlDocletWriter {
// If the container has 1 or more value defined and if the
// repeatable type annotation is not documented, print the container.
else {
addAnnotations(annotationElement, linkInfo, annotation, pairs,
indent, false);
addAnnotations(annotationElement, linkInfo, annotation, pairs, false);
}
}
else {
addAnnotations(annotationElement, linkInfo, annotation, pairs,
indent, linkBreak);
addAnnotations(annotationElement, linkInfo, annotation, pairs, linkBreak);
}
annotation.add(linkBreak ? DocletConstants.NL : "");
results.add(annotation);
@ -1938,13 +1884,12 @@ public class HtmlDocletWriter {
* @param linkInfo the information about the link
* @param annotation the annotation string to which the annotation will be added
* @param map annotation type element to annotation value pairs
* @param indent the number of extra spaces to indent the annotations.
* @param linkBreak if true, add new line between each member value
*/
private void addAnnotations(TypeElement annotationDoc, LinkInfoImpl linkInfo,
ContentBuilder annotation,
Map<? extends ExecutableElement, ? extends AnnotationValue> map,
int indent, boolean linkBreak) {
boolean linkBreak) {
linkInfo.label = new StringContent("@");
linkInfo.label.add(annotationDoc.getSimpleName());
annotation.add(getLink(linkInfo));
@ -1961,7 +1906,7 @@ public class HtmlDocletWriter {
if (linkBreak) {
annotation.add(DocletConstants.NL);
int spaces = annotationDoc.getSimpleName().length() + 2;
for (int k = 0; k < (spaces + indent); k++) {
for (int k = 0; k < (spaces); k++) {
annotation.add(" ");
}
}
@ -2074,7 +2019,7 @@ public class HtmlDocletWriter {
}
@Override
public Content visitAnnotation(AnnotationMirror a, Void p) {
List<Content> list = getAnnotations(0, a, false);
List<Content> list = getAnnotations(List.of(a), false);
ContentBuilder buf = new ContentBuilder();
for (Content c : list) {
buf.add(c);

View file

@ -41,6 +41,7 @@ import jdk.javadoc.internal.doclets.toolkit.Content;
import jdk.javadoc.internal.doclets.toolkit.Resources;
import jdk.javadoc.internal.doclets.toolkit.util.DocPath;
import jdk.javadoc.internal.doclets.toolkit.util.DocPaths;
import jdk.javadoc.internal.doclets.toolkit.util.DocletConstants;
import jdk.javadoc.internal.doclets.toolkit.util.links.LinkFactory;
import jdk.javadoc.internal.doclets.toolkit.util.links.LinkInfo;
@ -134,7 +135,7 @@ public class LinkFactoryImpl extends LinkFactory {
* {@inheritDoc}
*/
@Override
protected Content getTypeParameterLinks(LinkInfo linkInfo, boolean isClassLabel){
protected Content getTypeParameterLinks(LinkInfo linkInfo, boolean isClassLabel) {
Content links = newContent();
List<TypeMirror> vars = new ArrayList<>();
TypeMirror ctype = linkInfo.type != null
@ -164,6 +165,9 @@ public class LinkFactoryImpl extends LinkFactory {
if (many) {
links.add(",");
links.add(Entity.ZERO_WIDTH_SPACE);
if (((LinkInfoImpl) linkInfo).getContext() == LinkInfoImpl.Kind.MEMBER_TYPE_PARAMS) {
links.add(DocletConstants.NL);
}
}
links.add(getTypeParameterLink(linkInfo, t));
many = true;
@ -186,7 +190,6 @@ public class LinkFactoryImpl extends LinkFactory {
typeLinkInfo.excludeTypeBounds = linkInfo.excludeTypeBounds;
typeLinkInfo.excludeTypeParameterLinks = linkInfo.excludeTypeParameterLinks;
typeLinkInfo.linkToSelf = linkInfo.linkToSelf;
typeLinkInfo.isJava5DeclarationLocation = false;
return getLink(typeLinkInfo);
}
@ -218,7 +221,7 @@ public class LinkFactoryImpl extends LinkFactory {
if (annotations.isEmpty())
return links;
List<Content> annos = m_writer.getAnnotations(0, annotations, false, linkInfo.isJava5DeclarationLocation);
List<Content> annos = m_writer.getAnnotations(annotations, false);
boolean isFirst = true;
for (Content anno : annos) {

View file

@ -36,7 +36,6 @@ import javax.lang.model.type.TypeMirror;
import jdk.javadoc.internal.doclets.formats.html.markup.ContentBuilder;
import jdk.javadoc.internal.doclets.formats.html.markup.Entity;
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle;
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTag;
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree;
import jdk.javadoc.internal.doclets.formats.html.markup.StringContent;
import jdk.javadoc.internal.doclets.formats.html.markup.Table;
@ -140,23 +139,12 @@ public class MethodWriterImpl extends AbstractExecutableMemberWriter
*/
@Override
public Content getSignature(ExecutableElement method) {
HtmlTree pre = new HtmlTree(HtmlTag.PRE);
pre.setStyle(HtmlStyle.methodSignature);
writer.addAnnotationInfo(method, pre);
int annotationLength = pre.charCount();
addModifiers(method, pre);
addTypeParameters(method, pre);
addReturnType(method, pre);
if (configuration.linksource) {
Content methodName = new StringContent(name(method));
writer.addSrcLink(method, methodName, pre);
} else {
addName(name(method), pre);
}
int indent = pre.charCount() - annotationLength;
addParameters(method, pre, indent);
addExceptions(method, pre, indent);
return pre;
return new MemberSignature(method)
.addTypeParameters(getTypeParameters(method))
.addReturnType(getReturnType(method))
.addParameters(getParameters(method, true))
.addExceptions(getExceptions(method))
.toContent();
}
/**
@ -399,19 +387,17 @@ public class MethodWriterImpl extends AbstractExecutableMemberWriter
}
/**
* Add the return type.
* Get the return type for the given method.
*
* @param method the method being documented.
* @param htmltree the content tree to which the return type will be added
* @return content containing the return type
*/
protected void addReturnType(ExecutableElement method, Content htmltree) {
protected Content getReturnType(ExecutableElement method) {
TypeMirror type = utils.getReturnType(method);
if (type != null) {
Content linkContent = writer.getLink(
new LinkInfoImpl(configuration, LinkInfoImpl.Kind.RETURN_TYPE, type));
htmltree.add(linkContent);
htmltree.add(Entity.NO_BREAK_SPACE);
return writer.getLink(new LinkInfoImpl(configuration, LinkInfoImpl.Kind.RETURN_TYPE, type));
}
return new ContentBuilder();
}
@Override

View file

@ -32,7 +32,6 @@ import javax.lang.model.element.TypeElement;
import jdk.javadoc.internal.doclets.formats.html.markup.ContentBuilder;
import jdk.javadoc.internal.doclets.formats.html.markup.Entity;
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle;
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTag;
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree;
import jdk.javadoc.internal.doclets.formats.html.markup.StringContent;
import jdk.javadoc.internal.doclets.formats.html.markup.Table;
@ -114,21 +113,9 @@ public class PropertyWriterImpl extends AbstractMemberWriter
*/
@Override
public Content getSignature(ExecutableElement property) {
Content pre = new HtmlTree(HtmlTag.PRE);
writer.addAnnotationInfo(property, pre);
addModifiers(property, pre);
Content propertylink = writer.getLink(new LinkInfoImpl(
configuration, LinkInfoImpl.Kind.MEMBER,
utils.getReturnType(property)));
pre.add(propertylink);
pre.add(" ");
if (configuration.linksource) {
Content propertyName = new StringContent(name(property));
writer.addSrcLink(property, propertyName, pre);
} else {
addName(name(property), pre);
}
return pre;
return new MemberSignature(property)
.addType(utils.getReturnType(property))
.toContent();
}
/**

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2019, 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,6 +41,8 @@ public enum HtmlStyle {
allClassesContainer,
allPackagesContainer,
altColor,
annotations,
arguments,
bar,
block,
blockList,
@ -70,6 +72,7 @@ public enum HtmlStyle {
detail,
docSummary,
emphasizedPhrase,
exceptions,
externalLink,
fieldDetails,
fieldSummary,
@ -91,12 +94,15 @@ public enum HtmlStyle {
legalCopy,
mainContainer,
memberDetails,
memberName,
memberNameLabel,
memberNameLink,
memberSignature,
memberSummary,
methodDetails,
methodSignature,
methodSummary,
modifiers,
moduleDescription,
moduleLabelInPackage,
moduleLabelInType,
@ -122,6 +128,7 @@ public enum HtmlStyle {
providesSummary,
requiresSummary,
returnLabel,
returnType,
rightContainer,
rightIframe,
rowColor,
@ -147,6 +154,8 @@ public enum HtmlStyle {
topNav,
typeNameLabel,
typeNameLink,
typeParameters,
typeParametersLong,
typeSummary,
useSummary,
usesSummary

View file

@ -112,6 +112,11 @@ public class RawHtml extends Content {
state = State.ENTITY;
count++;
break;
case '\r':
case '\n':
// Windows uses "\r\n" as line separator while UNIX uses "\n".
// Ignore line separators to get consistent results across platforms.
break;
default:
count++;
}

View file

@ -1,4 +1,4 @@
/*
/*
* Javadoc style sheet
*/
@ -165,7 +165,7 @@ button {
height:2.8em;
padding-top:10px;
overflow:hidden;
font-size:12px;
font-size:12px;
}
.bottomNav {
margin-top:10px;
@ -533,9 +533,9 @@ td.colSecond a:link, td.colSecond a:visited,
th.colFirst a:link, th.colFirst a:visited,
th.colSecond a:link, th.colSecond a:visited,
th.colConstructorName a:link, th.colConstructorName a:visited,
th.colDeprecatedItemName a:link, th.colDeprecatedItemName a:visited,
.constantValuesContainer td a:link, .constantValuesContainer td a:visited,
.allClassesContainer td a:link, .allClassesContainer td a:visited,
th.colDeprecatedItemName a:link, th.colDeprecatedItemName a:visited,
.constantValuesContainer td a:link, .constantValuesContainer td a:visited,
.allClassesContainer td a:link, .allClassesContainer td a:visited,
.allPackagesContainer td a:link, .allPackagesContainer td a:visited {
font-weight:bold;
}
@ -571,6 +571,26 @@ td.colLast div {
td.colLast a {
padding-bottom:3px;
}
div.memberSignature {
font-family:'DejaVu Sans Mono', monospace;
font-size:14px;
margin-top:6px;
margin-bottom:14px;
white-space: pre-wrap;
}
div.memberSignature span.annotations {
white-space: pre-wrap;
}
div.memberSignature span.typeParametersLong,
div.memberSignature span.arguments,
div.memberSignature span.exceptions {
display: inline-block;
vertical-align: top;
white-space: pre;
}
div.memberSignature span.typeParameters {
white-space: normal;
}
/*
* Styles for formatting effect.
*/
@ -616,12 +636,12 @@ div.block div.block span.interfaceName {
* Styles for IFRAME.
*/
.mainContainer {
margin:0 auto;
padding:0;
height:100%;
width:100%;
position:fixed;
top:0;
margin:0 auto;
padding:0;
height:100%;
width:100%;
position:fixed;
top:0;
left:0;
}
.leftContainer {

View file

@ -71,12 +71,6 @@ public abstract class LinkInfo {
*/
public boolean isTypeBound = false;
/**
* Whether the document element is in a Java 5 declaration
* location or not.
*/
public boolean isJava5DeclarationLocation = true;
/**
* The label for the link.
*/
@ -161,7 +155,6 @@ public abstract class LinkInfo {
", type=" + type +
", isVarArg=" + isVarArg +
", isTypeBound=" + isTypeBound +
", isJava5DeclarationLocation=" + isJava5DeclarationLocation +
", label=" + label +
", isStrong=" + isStrong +
", includeTypeInClassLinkLabel=" + includeTypeInClassLinkLabel +