changeset 60094:0b92ffe01e54 sealed-types

spec fixes, removing experimental code
author vromero
date Fri, 28 Feb 2020 23:31:19 -0500
parents a631c875d3bc
children c35f1585204b f3fbbdf71b59
files src/java.compiler/share/classes/javax/lang/model/element/TypeElement.java src/java.compiler/share/classes/javax/lang/model/util/Elements.java src/jdk.compiler/share/classes/com/sun/source/tree/ClassTree.java src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java src/jdk.compiler/share/classes/com/sun/tools/javac/comp/TypeEnter.java
diffstat 5 files changed, 24 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.compiler/share/classes/javax/lang/model/element/TypeElement.java	Fri Feb 28 16:29:03 2020 -0500
+++ b/src/java.compiler/share/classes/javax/lang/model/element/TypeElement.java	Fri Feb 28 23:31:19 2020 -0500
@@ -223,7 +223,6 @@
      */
     @jdk.internal.PreviewFeature(feature=jdk.internal.PreviewFeature.Feature.SEALED_TYPES,
                                  essentialAPI=false)
-    //@SuppressWarnings("preview")
     default List<? extends TypeMirror> getPermittedSubtypes() {
         return List.of();
     }
--- a/src/java.compiler/share/classes/javax/lang/model/util/Elements.java	Fri Feb 28 16:29:03 2020 -0500
+++ b/src/java.compiler/share/classes/javax/lang/model/util/Elements.java	Fri Feb 28 23:31:19 2020 -0500
@@ -679,8 +679,11 @@
      *
      * @param type the type element being examined
      * @return {@code true} if the type element is sealed, {@code false} otherwise
-     * @since amber
+     *
+     * @since 15
      */
+    @jdk.internal.PreviewFeature(feature=jdk.internal.PreviewFeature.Feature.SEALED_TYPES,
+            essentialAPI=false)
     default boolean isSealed(TypeElement type) {
         return false;
     }
--- a/src/jdk.compiler/share/classes/com/sun/source/tree/ClassTree.java	Fri Feb 28 16:29:03 2020 -0500
+++ b/src/jdk.compiler/share/classes/com/sun/source/tree/ClassTree.java	Fri Feb 28 23:31:19 2020 -0500
@@ -95,13 +95,15 @@
      *           features of the Java language.}
      *
      * Returns the subtypes permitted by this type declaration.
+     *
      * @implSpec this implementation returns an empty list
+     *
      * @return the subtypes
-     * @since amber
+     *
+     * @since 15
      */
     @jdk.internal.PreviewFeature(feature=jdk.internal.PreviewFeature.Feature.SEALED_TYPES,
                                              essentialAPI=false)
-    @SuppressWarnings("preview")
     default List<? extends Tree> getPermitsClause() {
         return Collections.emptyList();
     }
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java	Fri Feb 28 16:29:03 2020 -0500
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java	Fri Feb 28 23:31:19 2020 -0500
@@ -171,7 +171,6 @@
                 (!preview.isPreview(Feature.REIFIABLE_TYPES_INSTANCEOF) || preview.isEnabled());
         sourceName = source.name;
         useBeforeDeclarationWarning = options.isSet("useBeforeDeclarationWarning");
-        allowStaticMembersInInners = options.isSet("allowStaticMembersInInners");
 
         statInfo = new ResultInfo(KindSelector.NIL, Type.noType);
         varAssignmentInfo = new ResultInfo(KindSelector.ASG, Type.noType);
@@ -217,11 +216,6 @@
      */
     String sourceName;
 
-    /** Switch: allow static members in inner classes
-     *
-     */
-    boolean allowStaticMembersInInners;
-
     /** Check kind and type of given tree against protokind and prototype.
      *  If check succeeds, store type in tree and return it.
      *  If check fails, store errType in tree and return it.
@@ -5078,7 +5072,7 @@
                         }
                     }
                 }
-                if (!isNonSealed(c) && !isFinal(c) && !isSealed(c)) {
+                if (!c.isNonSealed() && !c.isFinal() && !c.isSealed()) {
                     log.error(TreeInfo.declarationFor(c, env.tree), Errors.NonSealedSealedOrFinalExpected);
                 }
 
@@ -5097,7 +5091,7 @@
                         }
                     }
 
-                    if (!isNonSealed(c) && !isFinal(c) && !isSealed(c)) {
+                    if (!c.isNonSealed() && !c.isFinal() && !c.isSealed()) {
                         log.error(TreeInfo.declarationFor(c, env.tree), Errors.NonSealedSealedOrFinalExpected);
                     }
                 }
@@ -5157,10 +5151,6 @@
         }
     }
 
-    boolean isNonSealed(Symbol sym) { return sym != null && (sym.flags_field & NON_SEALED) != 0; }
-    boolean isFinal(Symbol sym) { return sym != null && (sym.flags_field & FINAL) != 0; }
-    boolean isSealed(Symbol sym) { return sym != null && (sym.flags_field & SEALED) != 0; }
-
     public void visitImport(JCImport tree) {
         // nothing to do
     }
@@ -5256,19 +5246,17 @@
         for (List<JCTree> l = tree.defs; l.nonEmpty(); l = l.tail) {
             // Attribute declaration
             attribStat(l.head, env);
-            if (!allowStaticMembersInInners) {
-                // Check that declarations in inner classes are not static (JLS 8.1.2)
-                // Make an exception for static constants.
-                if (c.owner.kind != PCK &&
-                        ((c.flags() & STATIC) == 0 || c.name == names.empty) &&
-                        (TreeInfo.flags(l.head) & (STATIC | INTERFACE)) != 0) {
-                    Symbol sym = null;
-                    if (l.head.hasTag(VARDEF)) sym = ((JCVariableDecl) l.head).sym;
-                    if (sym == null ||
-                            sym.kind != VAR ||
-                            ((VarSymbol) sym).getConstValue() == null)
-                        log.error(l.head.pos(), Errors.IclsCantHaveStaticDecl(c));
-                }
+            // Check that declarations in inner classes are not static (JLS 8.1.2)
+            // Make an exception for static constants.
+            if (c.owner.kind != PCK &&
+                    ((c.flags() & STATIC) == 0 || c.name == names.empty) &&
+                    (TreeInfo.flags(l.head) & (STATIC | INTERFACE)) != 0) {
+                Symbol sym = null;
+                if (l.head.hasTag(VARDEF)) sym = ((JCVariableDecl) l.head).sym;
+                if (sym == null ||
+                        sym.kind != VAR ||
+                        ((VarSymbol) sym).getConstValue() == null)
+                    log.error(l.head.pos(), Errors.IclsCantHaveStaticDecl(c));
             }
         }
 
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/TypeEnter.java	Fri Feb 28 16:29:03 2020 -0500
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/TypeEnter.java	Fri Feb 28 23:31:19 2020 -0500
@@ -886,10 +886,6 @@
                     TreeInfo.declarationFor(sym2.outermostClass(), env.toplevel) != null;
         }
 
-        boolean isNonSealed(Symbol sym) { return sym != null && (sym.flags_field & NON_SEALED) != 0; }
-        boolean isFinal(Symbol sym) { return sym != null && (sym.flags_field & FINAL) != 0; }
-        boolean isSealed(Symbol sym) { return sym != null && (sym.flags_field & SEALED) != 0; }
-
         java.util.Set<Type> superTypesInASealedHierarchy(ClassSymbol csym, Env<AttrContext> env, boolean inSameCUOnly) {
             if (csym == null) {
                 return Set.of();
@@ -902,14 +898,15 @@
             if (supertype != null &&
                     supertype.tsym != null &&
                     supertype != syms.objectType &&
-                    !isNonSealed(supertype.tsym) &&
+                    supertype.tsym != null &&
+                    !supertype.tsym.isNonSealed() &&
                     (inSameCUOnly && areInSameCU(csym, supertype.tsym, env) || !inSameCUOnly)) {
                 supertypes.add(supertype);
             }
 
             if (csym.getInterfaces() != null) {
                 for (Type intf : csym.getInterfaces()) {
-                    if (intf != null && intf.tsym != null && !isNonSealed(intf.tsym) &&
+                    if (intf != null && intf.tsym != null && intf.tsym != null && !intf.tsym.isNonSealed() &&
                             (inSameCUOnly && areInSameCU(csym, intf.tsym, env) || !inSameCUOnly)) {
                         supertypes.add(intf);
                     }