8227046: compiler implementation for sealed classes

8225056: VM support for sealed classes
8227044: javax.lang.model for sealed classes
8227045: Preview APIs support for sealed classes
8227047: Javadoc for sealed types
8245854: JVM TI Specification for sealed classes

Co-authored-by: Harold Seigel <harold.seigel@oracle.com>
Co-authored-by: Jan Lahoda <jan.lahoda@oracle.com>
Reviewed-by: mcimadamore, forax, darcy, dholmes, jlahoda, lfoltan, mchung, sspitsyn, vromero
This commit is contained in:
Vicente Romero 2020-06-01 17:00:40 -04:00
parent 567692e4ae
commit d42bfef8a4
139 changed files with 6877 additions and 192 deletions

View file

@ -112,8 +112,7 @@ public abstract class AbstractExecutableMemberWriter extends AbstractMemberWrite
Content tdSummary) {
ExecutableElement ee = (ExecutableElement)member;
Content memberLink = HtmlTree.SPAN(HtmlStyle.memberNameLink,
writer.getDocLink(context, te, ee,
name(ee), false));
writer.getDocLink(context, te, ee, name(ee), false));
Content code = HtmlTree.CODE(memberLink);
addParameters(ee, code);
tdSummary.add(code);

View file

@ -30,6 +30,7 @@ import java.util.List;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.stream.Collectors;
import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.Element;
@ -248,6 +249,32 @@ public class ClassWriterImpl extends SubWriterHolderWriter implements ClassWrite
}
}
}
List<? extends TypeMirror> permits = typeElement.getPermittedSubclasses();
List<? extends TypeMirror> linkablePermits = permits.stream()
.filter(t -> utils.isLinkable(utils.asTypeElement(t)))
.collect(Collectors.toList());
if (!linkablePermits.isEmpty()) {
boolean isFirst = true;
for (TypeMirror type : linkablePermits) {
TypeElement tDoc = utils.asTypeElement(type);
if (isFirst) {
pre.add(DocletConstants.NL);
pre.add("permits ");
isFirst = false;
} else {
pre.add(", ");
}
Content link = getLink(new LinkInfoImpl(configuration,
LinkInfoImpl.Kind.PERMITTED_SUBCLASSES,
type));
pre.add(link);
}
if (linkablePermits.size() < permits.size()) {
Content c = new StringContent(resources.getText("doclet.not.exhaustive"));
pre.add(" ");
pre.add(HtmlTree.SPAN(HtmlStyle.permitsNote, c));
}
}
classInfoTree.add(pre);
}

View file

@ -162,6 +162,11 @@ public class LinkInfoImpl extends LinkInfo {
*/
CLASS_SIGNATURE_PARENT_NAME,
/**
* Permitted subclasses of a sealed type.
*/
PERMITTED_SUBCLASSES,
/**
* The header for method documentation copied from parent.
*/
@ -360,6 +365,7 @@ public class LinkInfoImpl extends LinkInfo {
case CLASS_TREE_PARENT:
case TREE:
case CLASS_SIGNATURE_PARENT_NAME:
case PERMITTED_SUBCLASSES:
excludeTypeParameterLinks = true;
excludeTypeBounds = true;
includeTypeInClassLinkLabel = false;

View file

@ -77,6 +77,7 @@ public enum HtmlStyle {
packages,
packageHierarchyLabel,
packageUses,
permitsNote,
searchTagLink,
searchTagResult,
serializedPackageContainer,

View file

@ -1,5 +1,5 @@
#
# Copyright (c) 2010, 2019, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2010, 2020, 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
@ -62,6 +62,7 @@ doclet.navProperty=Property
doclet.navEnum=Enum Constants
doclet.navConstructor=Constr
doclet.navMethod=Method
doclet.not.exhaustive=(not exhaustive)
doclet.Index=Index
doclet.Window_Single_Index=Index
doclet.Window_Split_Index={0}-Index

View file

@ -504,8 +504,18 @@ public class Utils {
}
}
void addSealed(TypeElement e) {
if (e.getModifiers().contains(Modifier.SEALED)) {
append("sealed");
} else if (e.getModifiers().contains(Modifier.NON_SEALED)) {
append("non-sealed");
}
}
void addModifiers(Set<Modifier> modifiers) {
modifiers.stream().map(Modifier::toString).forEachOrdered(this::append);
modifiers.stream()
.map(Modifier::toString)
.forEachOrdered(this::append);
}
void append(String s) {
@ -527,6 +537,7 @@ public class Utils {
public String visitTypeAsInterface(TypeElement e, SortedSet<Modifier> mods) {
addVisibilityModifier(mods);
addStatic(mods);
addSealed(e);
return finalString("interface");
}