< prev index next >
src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/AbstractMemberWriter.java
Print this page
*** 44,59 ****
--- 44,61 ----
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.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;
import static javax.lang.model.element.Modifier.NATIVE;
import static javax.lang.model.element.Modifier.PUBLIC;
*** 217,275 ****
* @param member the member being linked to
* @return a content tree representing the link
*/
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 "";
}
StringBuilder sb = new StringBuilder(len);
--- 219,228 ----
*** 561,566 ****
--- 514,696 ----
if (isLastContent)
return HtmlTree.LI(HtmlStyle.blockListLast, memberTree);
else
return HtmlTree.LI(HtmlStyle.blockList, memberTree);
}
+
+ /**
+ * A HtmlTree builder for member signatures.
+ */
+ class MemberSignature {
+
+ // The content builder
+ private Content content = new ContentBuilder();
+
+ // Position of last line separator.
+ private int lastNewLine = 0;
+
+ // 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 tree.
+ *
+ * @param element The element for which to create a signature.
+ */
+ MemberSignature(Element element) {
+ Content annotationInfo = writer.getAnnotationInfo(element.getAnnotationMirrors(), true);
+ if (!annotationInfo.isEmpty()) {
+ content.add(HtmlTree.SPAN(HtmlStyle.annotations, annotationInfo));
+ lastNewLine = content.charCount();
+ }
+ addModifiers(element);
+ }
+
+ /**
+ * 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.
+ */
+ void addModifiers(Element member) {
+ 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(" "));
+ content.add(HtmlTree.SPAN(HtmlStyle.modifiers, new StringContent(mods)));
+ content.add(Entity.NO_BREAK_SPACE);
+ }
+ }
+
+ /**
+ * Add the type parameters and return type for an executable member.
+ *
+ * @param typeParameters the content tree containing the type parameters to add.
+ * @param returnType the content tree containing the return type to add.
+ */
+ void addTypeParametersAndReturnType(Content typeParameters, Content returnType) {
+
+ if (!typeParameters.isEmpty()) {
+ // 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) {
+ content.add(HtmlTree.SPAN(HtmlStyle.typeParametersLong, typeParameters));
+ } else {
+ content.add(HtmlTree.SPAN(HtmlStyle.typeParameters, typeParameters));
+ }
+
+ // count below includes modifiers plus type params added above
+ if (charCountFromNewline() + returnType.charCount()> RETURN_TYPE_MAX_LINE_LENGTH) {
+ content.add(DocletConstants.NL);
+ lastNewLine = content.charCount();
+ } else {
+ content.add(Entity.NO_BREAK_SPACE);
+ }
+ }
+
+ content.add(HtmlTree.SPAN(HtmlStyle.returnType, returnType));
+ content.add(Entity.NO_BREAK_SPACE);
+ }
+
+ /**
+ * Add the type information for a non-executable member.
+ *
+ * @param type the type of the member.
+ */
+ void addType(TypeMirror type) {
+ Content typeLink = writer.getLink(new LinkInfoImpl(configuration, LinkInfoImpl.Kind.MEMBER, type));
+ content.add(HtmlTree.SPAN(HtmlStyle.returnType, typeLink));
+ content.add(Entity.NO_BREAK_SPACE);
+ }
+
+ /**
+ * Add the name of a member.
+ *
+ * @param element the member being documented.
+ */
+ void addName(Element element) {
+ 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);
+ }
+
+ /**
+ * Add the parameter and exception information of an executable member.
+ *
+ * @param paramTree the content tree containing the parameter information.
+ * @param exceptionTree the content tree containing the exception information.
+ */
+ void addParametersAndExceptions(Content paramTree, Content exceptionTree) {
+ int indentSize = charCountFromNewline();
+
+ if (paramTree.isEmpty()) {
+ content.add("()");
+ } else {
+ content.add(Entity.ZERO_WIDTH_SPACE);
+ content.add("(");
+ content.add(HtmlTree.SPAN(HtmlStyle.arguments, paramTree));
+ paramTree.add(")");
+ }
+
+ if (!exceptionTree.isEmpty()) {
+ CharSequence indent = makeSpace(indentSize + 1 - 7);
+ content.add(DocletConstants.NL);
+ content.add(indent);
+ content.add("throws ");
+ content.add(HtmlTree.SPAN(HtmlStyle.exceptions, exceptionTree));
+ }
+ }
+
+ /**
+ * Return the number of characters of plain text content since the last newline character.
+ *
+ * @return the number of plain text characters since the last newline character
+ */
+ int charCountFromNewline() {
+ return content.charCount() - lastNewLine;
+ }
+
+ /**
+ * Return a HTML tree containing the member signature.
+ *
+ * @return the member signature
+ */
+ Content toContent() {
+ return HtmlTree.DIV(HtmlStyle.memberSignature, content);
+ }
+
+ }
}
< prev index next >