Skip to content
This repository was archived by the owner on Aug 27, 2022. It is now read-only.
/ lanai Public archive

Commit 5be4de8

Browse files
committedNov 27, 2020
8245058: improve presentation of annotations for modules and packages
Reviewed-by: jjg
1 parent d51e2ab commit 5be4de8

File tree

53 files changed

+1094
-930
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1094
-930
lines changed
 

‎src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/AbstractExecutableMemberWriter.java

+11-12
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ protected void addParam(ExecutableElement member, VariableElement param, TypeMir
160160
*/
161161
protected void addReceiverAnnotations(ExecutableElement member, TypeMirror rcvrType,
162162
List<? extends AnnotationMirror> annotationMirrors, Content tree) {
163-
writer.addReceiverAnnotationInfo(member, rcvrType, annotationMirrors, tree);
163+
tree.add(writer.getAnnotationInfo(member.getReceiverType().getAnnotationMirrors(), false));
164164
tree.add(Entity.NO_BREAK_SPACE);
165165
tree.add(utils.getTypeName(rcvrType, false));
166166
LinkInfoImpl linkInfo = new LinkInfoImpl(configuration, RECEIVER_TYPE, rcvrType);
@@ -212,11 +212,11 @@ protected Content getParameters(ExecutableElement member, boolean includeAnnotat
212212

213213
if (param.getKind() != ElementKind.INSTANCE_INIT) {
214214
if (includeAnnotations) {
215-
boolean foundAnnotations =
216-
writer.addAnnotationInfo(param, paramTree);
217-
if (foundAnnotations) {
218-
paramTree.add(DocletConstants.NL);
219-
paramTree.add(" ");
215+
Content annotationInfo = writer.getAnnotationInfo(param, false);
216+
if (!annotationInfo.isEmpty()) {
217+
paramTree.add(annotationInfo)
218+
.add(DocletConstants.NL)
219+
.add(" ");
220220
}
221221
}
222222
addParam(member, param, paramType,
@@ -231,12 +231,11 @@ protected Content getParameters(ExecutableElement member, boolean includeAnnotat
231231
paramTree.add(" ");
232232

233233
if (includeAnnotations) {
234-
boolean foundAnnotations =
235-
writer.addAnnotationInfo(parameters.get(i),
236-
paramTree);
237-
if (foundAnnotations) {
238-
paramTree.add(DocletConstants.NL);
239-
paramTree.add(" ");
234+
Content annotationInfo = writer.getAnnotationInfo(parameters.get(i), false);
235+
if (!annotationInfo.isEmpty()) {
236+
paramTree.add(annotationInfo)
237+
.add(DocletConstants.NL)
238+
.add(" ");
240239
}
241240
}
242241
addParam(member, parameters.get(i), instMeth.getParameterTypes().get(i),

‎src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/AbstractMemberWriter.java

-231
Original file line numberDiff line numberDiff line change
@@ -421,235 +421,4 @@ public Content getMemberListItem(Content memberTree) {
421421
return writer.getMemberListItem(memberTree);
422422
}
423423

424-
/**
425-
* A content builder for member signatures.
426-
*/
427-
class MemberSignature {
428-
429-
private final Element element;
430-
private Content typeParameters;
431-
private Content returnType;
432-
private Content parameters;
433-
private Content exceptions;
434-
435-
// Threshold for length of type parameters before switching from inline to block representation.
436-
private static final int TYPE_PARAMS_MAX_INLINE_LENGTH = 50;
437-
438-
// Threshold for combined length of modifiers, type params and return type before breaking
439-
// it up with a line break before the return type.
440-
private static final int RETURN_TYPE_MAX_LINE_LENGTH = 50;
441-
442-
/**
443-
* Creates a new member signature builder.
444-
*
445-
* @param element the element for which to create a signature
446-
*/
447-
MemberSignature(Element element) {
448-
this.element = element;
449-
}
450-
451-
/**
452-
* Adds the type parameters for an executable member.
453-
*
454-
* @param typeParameters the content tree containing the type parameters to add.
455-
*
456-
* @return this instance
457-
*/
458-
MemberSignature addTypeParameters(Content typeParameters) {
459-
this.typeParameters = typeParameters;
460-
return this;
461-
}
462-
463-
/**
464-
* Adds the return type for an executable member.
465-
*
466-
* @param returnType the content tree containing the return type to add.
467-
*
468-
* @return this instance
469-
*/
470-
MemberSignature addReturnType(Content returnType) {
471-
this.returnType = returnType;
472-
return this;
473-
}
474-
475-
/**
476-
* Adds the type information for a non-executable member.
477-
*
478-
* @param type the type of the member.
479-
*
480-
* @return this instance
481-
*/
482-
MemberSignature addType(TypeMirror type) {
483-
this.returnType = writer.getLink(new LinkInfoImpl(configuration, LinkInfoImpl.Kind.MEMBER, type));
484-
return this;
485-
}
486-
487-
/**
488-
* Adds the parameter information of an executable member.
489-
*
490-
* @param paramTree the content tree containing the parameter information.
491-
*
492-
* @return this instance
493-
*/
494-
MemberSignature addParameters(Content paramTree) {
495-
this.parameters = paramTree;
496-
return this;
497-
}
498-
499-
/**
500-
* Adds the exception information of an executable member.
501-
*
502-
* @param exceptionTree the content tree containing the exception information
503-
*
504-
* @return this instance
505-
*/
506-
MemberSignature addExceptions(Content exceptionTree) {
507-
this.exceptions = exceptionTree;
508-
return this;
509-
}
510-
511-
/**
512-
* Returns an HTML tree containing the member signature.
513-
*
514-
* @return an HTML tree containing the member signature
515-
*/
516-
Content toContent() {
517-
Content content = new ContentBuilder();
518-
// Position of last line separator.
519-
int lastLineSeparator = 0;
520-
521-
// Annotations
522-
Content annotationInfo = writer.getAnnotationInfo(element.getAnnotationMirrors(), true);
523-
if (!annotationInfo.isEmpty()) {
524-
content.add(HtmlTree.SPAN(HtmlStyle.annotations, annotationInfo));
525-
lastLineSeparator = content.charCount();
526-
}
527-
528-
// Modifiers
529-
appendModifiers(content);
530-
531-
// Type parameters
532-
if (typeParameters != null && !typeParameters.isEmpty()) {
533-
lastLineSeparator = appendTypeParameters(content, lastLineSeparator);
534-
}
535-
536-
// Return type
537-
if (returnType != null) {
538-
content.add(HtmlTree.SPAN(HtmlStyle.returnType, returnType));
539-
content.add(Entity.NO_BREAK_SPACE);
540-
}
541-
542-
// Name
543-
HtmlTree nameSpan = new HtmlTree(TagName.SPAN);
544-
nameSpan.setStyle(HtmlStyle.memberName);
545-
if (options.linkSource()) {
546-
Content name = new StringContent(name(element));
547-
writer.addSrcLink(element, name, nameSpan);
548-
} else {
549-
nameSpan.add(name(element));
550-
}
551-
content.add(nameSpan);
552-
553-
// Parameters and exceptions
554-
if (parameters != null) {
555-
appendParametersAndExceptions(content, lastLineSeparator);
556-
}
557-
558-
return HtmlTree.DIV(HtmlStyle.memberSignature, content);
559-
}
560-
561-
/**
562-
* Adds the modifier for the member. The modifiers are ordered as specified
563-
* by <em>The Java Language Specification</em>.
564-
*
565-
* @param htmlTree the content tree to which the modifier information will be added
566-
*/
567-
private void appendModifiers(Content htmlTree) {
568-
Set<Modifier> set = new TreeSet<>(element.getModifiers());
569-
570-
// remove the ones we really don't need
571-
set.remove(NATIVE);
572-
set.remove(SYNCHRONIZED);
573-
set.remove(STRICTFP);
574-
575-
// According to JLS, we should not be showing public modifier for
576-
// interface methods and fields.
577-
if ((utils.isField(element) || utils.isMethod(element))) {
578-
Element te = element.getEnclosingElement();
579-
if (utils.isInterface(te) || utils.isAnnotationType(te)) {
580-
// Remove the implicit abstract and public modifiers
581-
if (utils.isMethod(element)) {
582-
set.remove(ABSTRACT);
583-
}
584-
set.remove(PUBLIC);
585-
}
586-
}
587-
if (!set.isEmpty()) {
588-
String mods = set.stream().map(Modifier::toString).collect(Collectors.joining(" "));
589-
htmlTree.add(HtmlTree.SPAN(HtmlStyle.modifiers, new StringContent(mods)))
590-
.add(Entity.NO_BREAK_SPACE);
591-
}
592-
}
593-
594-
/**
595-
* Appends the type parameter information to the HTML tree.
596-
*
597-
* @param htmlTree the HTML tree
598-
* @param lastLineSeparator index of last line separator in the HTML tree
599-
*
600-
* @return the new index of the last line separator
601-
*/
602-
private int appendTypeParameters(Content htmlTree, int lastLineSeparator) {
603-
// Apply different wrapping strategies for type parameters
604-
// depending of combined length of type parameters and return type.
605-
int typeParamLength = typeParameters.charCount();
606-
607-
if (typeParamLength >= TYPE_PARAMS_MAX_INLINE_LENGTH) {
608-
htmlTree.add(HtmlTree.SPAN(HtmlStyle.typeParametersLong, typeParameters));
609-
} else {
610-
htmlTree.add(HtmlTree.SPAN(HtmlStyle.typeParameters, typeParameters));
611-
}
612-
613-
int lineLength = htmlTree.charCount() - lastLineSeparator;
614-
int newLastLineSeparator = lastLineSeparator;
615-
616-
// sum below includes length of modifiers plus type params added above
617-
if (lineLength + returnType.charCount()> RETURN_TYPE_MAX_LINE_LENGTH) {
618-
htmlTree.add(DocletConstants.NL);
619-
newLastLineSeparator = htmlTree.charCount();
620-
} else {
621-
htmlTree.add(Entity.NO_BREAK_SPACE);
622-
}
623-
624-
return newLastLineSeparator;
625-
}
626-
627-
/**
628-
* Appends the parameters and exceptions information to the HTML tree.
629-
*
630-
* @param htmlTree the HTML tree
631-
* @param lastLineSeparator the index of the last line separator in the HTML tree
632-
*/
633-
private void appendParametersAndExceptions(Content htmlTree, int lastLineSeparator) {
634-
// Record current position for indentation of exceptions
635-
int indentSize = htmlTree.charCount() - lastLineSeparator;
636-
637-
if (parameters.charCount() == 2) {
638-
// empty parameters are added without packing
639-
htmlTree.add(parameters);
640-
} else {
641-
htmlTree.add(Entity.ZERO_WIDTH_SPACE)
642-
.add(HtmlTree.SPAN(HtmlStyle.parameters, parameters));
643-
}
644-
645-
// Exceptions
646-
if (exceptions != null && !exceptions.isEmpty()) {
647-
CharSequence indent = " ".repeat(Math.max(0, indentSize + 1 - 7));
648-
htmlTree.add(DocletConstants.NL)
649-
.add(indent)
650-
.add("throws ")
651-
.add(HtmlTree.SPAN(HtmlStyle.exceptions, exceptions));
652-
}
653-
}
654-
}
655424
}

0 commit comments

Comments
 (0)
This repository has been archived.