Skip to content
Permalink
Browse files
8265684: implement Sealed Classes as a standard feature in Java, java…
…doc changes

Reviewed-by: jjg
  • Loading branch information
Vicente Romero committed May 20, 2021
1 parent 0fa9223 commit 7dcb9fda89ee17a5eadc83999de21e4542f37133
Showing with 62 additions and 176 deletions.
  1. +3 −3 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ClassWriterImpl.java
  2. +0 −5 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlDocletWriter.java
  3. +0 −6 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/Signatures.java
  4. +0 −2 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/TagletWriterImpl.java
  5. +0 −1 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/BaseConfiguration.java
  6. +0 −1 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/CommentUtils.java
  7. +0 −1 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/ClassBuilder.java
  8. +0 −1 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/taglets/ParamTaglet.java
  9. +0 −1 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/taglets/TagletManager.java
  10. +0 −2 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/ClassUseMapper.java
  11. +0 −2 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/Comparators.java
  12. +0 −1 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/IndexItem.java
  13. +4 −21 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/Utils.java
  14. +0 −1 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/VisibleMemberTable.java
  15. +0 −3 src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/ElementsTable.java
  16. +4 −23 test/langtools/jdk/javadoc/doclet/testPreview/TestPreview.java
  17. +51 −102 test/langtools/jdk/javadoc/doclet/testSealedTypes/TestSealedTypes.java
@@ -27,6 +27,7 @@

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.SortedSet;
@@ -84,8 +85,7 @@
"java.lang.constant.ConstantDesc",
"java.io.Serializable");

private static final Set<String> previewModifiers
= Set.of("sealed", "non-sealed");
private static final Set<String> previewModifiers = Collections.emptySet();

protected final TypeElement typeElement;

@@ -196,7 +196,7 @@ protected TypeElement getCurrentPageElement() {
return typeElement;
}

@Override @SuppressWarnings("preview")
@Override
public void addClassSignature(String modifiers, Content classInfoTree) {
ContentBuilder mods = new ContentBuilder();
String sep = null;
@@ -1686,7 +1686,6 @@ private boolean shouldNotRedirectRelativeLinks() {
*
* @return the text, with all the relative links redirected to work.
*/
@SuppressWarnings("preview")
private String redirectRelativeLinks(Element element, TextTree tt) {
String text = tt.getBody();
if (element == null || utils.isOverviewElement(element) || shouldNotRedirectRelativeLinks()) {
@@ -2232,7 +2231,6 @@ public void addPreviewInfo(Element forWhat, Content target) {
}
}

@SuppressWarnings("preview")
private List<Content> getPreviewNotes(TypeElement el) {
String className = el.getSimpleName().toString();
List<Content> result = new ArrayList<>();
@@ -2257,9 +2255,6 @@ public void addPreviewInfo(Element forWhat, Content target) {
}
previewLanguageFeatures.addAll(utils.previewLanguageFeaturesUsed(el));
if (!previewLanguageFeatures.isEmpty()) {
if (previewLanguageFeatures.contains(DeclarationPreviewLanguageFeatures.SEALED_PERMITS)) {
previewLanguageFeatures.remove(DeclarationPreviewLanguageFeatures.SEALED);
}
for (DeclarationPreviewLanguageFeatures feature : previewLanguageFeatures) {
String featureDisplayName =
resources.getText("doclet.Declared_Using_Preview." + feature.name());
@@ -109,7 +109,6 @@ public TypeSignature setModifiers(Content modifiers) {
return this;
}

@SuppressWarnings("preview")
public Content toContent() {
Content content = new ContentBuilder();
Content annotationInfo = classWriter.getAnnotationInfo(typeElement, true);
@@ -185,10 +184,6 @@ public Content toContent() {
if (isFirst) {
content.add(DocletConstants.NL);
permitsSpan.add("permits");
Content link =
classWriter.links.createLink(classWriter.htmlIds.forPreviewSection(typeElement),
classWriter.contents.previewMark);
permitsSpan.add(HtmlTree.SUP(link));
permitsSpan.add(" ");
isFirst = false;
} else {
@@ -209,7 +204,6 @@ public Content toContent() {
return HtmlTree.DIV(HtmlStyle.typeSignature, content);
}

@SuppressWarnings("preview")
private Content getRecordComponents() {
Content content = new ContentBuilder();
content.add("(");
@@ -287,7 +287,6 @@ public Content getParamHeader(ParamTaglet.ParamKind kind) {
}

@Override
@SuppressWarnings("preview")
public Content paramTagOutput(Element element, ParamTree paramTag, String paramName) {
ContentBuilder body = new ContentBuilder();
CommentHelper ch = utils.getCommentHelper(element);
@@ -461,7 +460,6 @@ protected TypeElement getCurrentPageElement() {
return htmlWriter.getCurrentPageElement();
}

@SuppressWarnings("preview")
private Content createAnchorAndSearchIndex(Element element, String tagText, String desc, DocTree tree) {
Content result = null;
if (context.isFirstSentence && context.inSummary || context.inTags.contains(DocTree.Kind.INDEX)) {
@@ -625,7 +625,6 @@ public boolean isGeneratedDoc(TypeElement te) {
* Splits the elements in a collection to its individual
* collection.
*/
@SuppressWarnings("preview")
private static class Splitter {

final Set<ModuleElement> mset = new LinkedHashSet<>();
@@ -205,7 +205,6 @@ public void setRecordConstructorTree(ExecutableElement ee) {
* Generates the description for the standard {@code equals} method for a record.
* @param ee the {@code equals} method
*/
@SuppressWarnings("preview")
public void setRecordEqualsTree(ExecutableElement ee) {
List<DocTree> fullBody = new ArrayList<>();
add(fullBody, "doclet.record_equals_doc.fullbody.head");
@@ -450,7 +450,6 @@ private void setEnumDocumentation(TypeElement elem) {
* @param elem the record element
*/

@SuppressWarnings("preview")
private void setRecordDocumentation(TypeElement elem) {
CommentUtils cmtUtils = configuration.cmtUtils;
Set<Name> componentNames = elem.getRecordComponents().stream()
@@ -133,7 +133,6 @@ public void inherit(DocFinder.Input input, DocFinder.Output output) {
}

@Override
@SuppressWarnings("preview")
public Content getAllBlockTagOutput(Element holder, TagletWriter writer) {
Utils utils = writer.configuration().utils;
if (utils.isExecutableElement(holder)) {
@@ -353,7 +353,6 @@ void seenTag(String name) {
* @param trees the trees containing the comments
* @param inlineTrees true if the trees are inline and false otherwise
*/
@SuppressWarnings("preview")
public void checkTags(Element element, Iterable<? extends DocTree> trees, boolean inlineTrees) {
if (trees == null) {
return;
@@ -483,7 +483,6 @@ private void addAll(Map<TypeElement, List<TypeElement>> map, TypeElement te, Col
private <T extends Element> void mapTypeParameters(final Map<TypeElement, List<T>> map,
Element element, final T holder) {

@SuppressWarnings("preview")
SimpleElementVisitor14<Void, Void> elementVisitor
= new SimpleElementVisitor14<Void, Void>() {

@@ -561,7 +560,6 @@ public Void visitDeclared(DeclaredType t, Void p) {
* @param e whose type parameters are being checked.
* @param holder owning the type parameters.
*/
@SuppressWarnings("preview")
private <T extends Element> void mapAnnotations(final Map<TypeElement, List<T>> map,
Element e, final T holder) {
new SimpleElementVisitor14<Void, Void>() {
@@ -511,7 +511,6 @@ private int getKindIndex(Element e) {
};
}

@SuppressWarnings("preview")
boolean hasParameters(Element e) {
return new SimpleElementVisitor14<Boolean, Void>() {
@Override
@@ -533,7 +532,6 @@ protected Boolean defaultAction(Element e, Void p) {
* @return a negative integer, zero, or a positive integer as the first argument is less
* than, equal to, or greater than the second.
*/
@SuppressWarnings("preview")
private String getFullyQualifiedName(Element e) {
return new SimpleElementVisitor14<String, Void>() {
@Override
@@ -348,7 +348,6 @@ protected Category getCategory(DocTree docTree) {
};
}

@SuppressWarnings("preview")
protected Category getCategory(Element element) {
return new SimpleElementVisitor14<Category, Void>() {
@Override
@@ -34,6 +34,7 @@
import java.text.RuleBasedCollator;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Deque;
@@ -54,6 +55,7 @@
import java.util.TreeSet;
import java.util.function.Predicate;
import java.util.stream.Collectors;

import javax.lang.model.AnnotatedConstruct;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.AnnotationMirror;
@@ -488,7 +490,6 @@ public boolean definesSerializableFields(TypeElement aclass) {
return configuration.workArounds.definesSerializableFields( aclass);
}

@SuppressWarnings("preview")
public String modifiersToString(Element e, boolean trailingSpace) {
SortedSet<Modifier> modifiers = new TreeSet<>(e.getModifiers());
modifiers.remove(NATIVE);
@@ -2988,37 +2989,19 @@ public String toString() {
* @param e the Element to check.
* @return the set of preview language features used to declare the given element
*/
@SuppressWarnings("preview")
public Set<DeclarationPreviewLanguageFeatures> previewLanguageFeaturesUsed(Element e) {
Set<DeclarationPreviewLanguageFeatures> result = new HashSet<>();

if ((e.getKind().isClass() || e.getKind().isInterface()) &&
e.getModifiers().contains(Modifier.SEALED)) {
List<? extends TypeMirror> permits = ((TypeElement) e).getPermittedSubclasses();
boolean hasLinkablePermits = permits.stream()
.anyMatch(t -> isLinkable(asTypeElement(t)));
if (hasLinkablePermits) {
result.add(DeclarationPreviewLanguageFeatures.SEALED_PERMITS);
} else {
result.add(DeclarationPreviewLanguageFeatures.SEALED);
}
}

return result;
return new HashSet<>();
}

public enum DeclarationPreviewLanguageFeatures {

SEALED(List.of("sealed")),
SEALED_PERMITS(List.of("sealed", "permits"));
NONE(List.of(""));
public final List<String> features;

DeclarationPreviewLanguageFeatures(List<String> features) {
this.features = features;
}
}

@SuppressWarnings("preview")
public PreviewSummary declaredUsingPreviewAPIs(Element el) {
List<TypeElement> usedInDeclaration = new ArrayList<>();
usedInDeclaration.addAll(annotations2Classes(el));
@@ -784,7 +784,6 @@ private void addDocumentedAnnotations(Set<AnnotationMirror> annotations, List<?
}
}

@SuppressWarnings("preview")
String getMemberKey(Element e) {
return new SimpleElementVisitor14<String, Void>() {
@Override
@@ -977,7 +977,6 @@ private boolean isTypeElementSelected(TypeElement te) {
return (xclasses || toolEnv.getFileKind(te) == SOURCE) && isSelected(te);
}

@SuppressWarnings("preview")
SimpleElementVisitor14<Boolean, Void> visibleElementVisitor = null;
/**
* Returns true if the element is selected, by applying
@@ -989,7 +988,6 @@ private boolean isTypeElementSelected(TypeElement te) {
* @param e the element to be checked
* @return true if the element is visible
*/
@SuppressWarnings("preview")
public boolean isSelected(Element e) {
if (toolEnv.isSynthetic((Symbol) e)) {
return false;
@@ -1029,7 +1027,6 @@ public Boolean visitUnknown(Element e, Void p) {
return visibleElementVisitor.visit(e);
}

@SuppressWarnings("preview")
private class IncludedVisitor extends SimpleElementVisitor14<Boolean, Void> {
private final Set<Element> includedCache;

@@ -56,35 +56,16 @@ public void testUserJavadoc() {
"m/pkg");
checkExit(Exit.OK);

ResourceBundle bundle = ResourceBundle.getBundle("jdk.javadoc.internal.doclets.formats.html.resources.standard", ModuleLayer.boot().findModule("jdk.javadoc").get());

{
String zero = MessageFormat.format(bundle.getString("doclet.PreviewLeadingNote"), "<code>TestPreviewDeclaration</code>");
String one = MessageFormat.format(bundle.getString("doclet.Declared_Using_Preview"), "<code>TestPreviewDeclaration</code>", "<em>Sealed Classes</em>", "<code>sealed</code>");
String two = MessageFormat.format(bundle.getString("doclet.PreviewTrailingNote1"), "<code>TestPreviewDeclaration</code>");
String three = MessageFormat.format(bundle.getString("doclet.PreviewTrailingNote2"), new Object[0]);
String expectedTemplate = """
<div class="preview-block" id="preview-pkg.TestPreviewDeclaration"><span class="preview-label">{0}</span>
<ul class="preview-comment">
<li>{1}</li>
</ul>
<div class="preview-comment">{2}</div>
<div class="preview-comment">{3}</div>
</div>""";
String expected = MessageFormat.format(expectedTemplate, zero, one, two, three);
checkOutput("m/pkg/TestPreviewDeclaration.html", true, expected);
}

checkOutput("m/pkg/TestPreviewDeclarationUse.html", true,
"<code><a href=\"TestPreviewDeclaration.html\" title=\"interface in pkg\">TestPreviewDeclaration</a><sup><a href=\"TestPreviewDeclaration.html#preview-pkg.TestPreviewDeclaration\">PREVIEW</a></sup></code>");
"<code><a href=\"TestPreviewDeclaration.html\" title=\"interface in pkg\">TestPreviewDeclaration</a></code>");
checkOutput("m/pkg/TestPreviewAPIUse.html", true,
"<a href=\"" + doc + "java.base/preview/Core.html\" title=\"class or interface in preview\" class=\"external-link\">Core</a><sup><a href=\"" + doc + "java.base/preview/Core.html#preview-preview.Core\" title=\"class or interface in preview\" class=\"external-link\">PREVIEW</a>");
checkOutput("m/pkg/DocAnnotation.html", true,
"<div class=\"preview-block\" id=\"preview-pkg.DocAnnotation\"><span class=\"preview-label\">");
"<span class=\"modifiers\">public @interface </span><span class=\"element-name type-name-label\">DocAnnotation</span>");
checkOutput("m/pkg/DocAnnotationUse1.html", true,
"<div class=\"preview-block\" id=\"preview-pkg.DocAnnotationUse1\"><span class=\"preview-label\">");
"<div class=\"inheritance\">pkg.DocAnnotationUse1</div>");
checkOutput("m/pkg/DocAnnotationUse2.html", true,
"<div class=\"preview-block\" id=\"preview-pkg.DocAnnotationUse2\"><span class=\"preview-label\">");
"<div class=\"inheritance\">pkg.DocAnnotationUse2</div>");
}

@Test

0 comments on commit 7dcb9fd

Please sign in to comment.