OpenJDK / amber / amber
changeset 60076:15489d82799e sealed-types
refactoring: removing outdated code, adding diagnostics
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Enter.java Fri Feb 14 16:11:31 2020 -0500 +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Enter.java Fri Feb 14 17:17:21 2020 -0500 @@ -559,32 +559,6 @@ */ public void main(List<JCCompilationUnit> trees) { complete(trees, null); - sealedClassVisitor.scan(trees); - } - - SealedClassVisitor sealedClassVisitor = new SealedClassVisitor(); - - class SealedClassVisitor extends TreeScanner { - @Override - public void visitClassDef(JCClassDecl tree) { - super.visitClassDef(tree); - if (tree != null && - tree.sym != null && - tree.sym.type != null && - (tree.sym.flags_field & Flags.NON_SEALED) == 0 && - (tree.sym.flags_field & Flags.SEALED) == 0 && - ((ClassType)tree.sym.type).hasSealedSuperInSameCU) { - // just checking we don't want final abstract classes - if ((((ClassType)tree.sym.type).permitted.isEmpty())) { - if ((tree.sym.flags_field & ABSTRACT) != 0 || (tree.sym.flags_field & INTERFACE) != 0) { - log.error(tree.pos(), Errors.ClassCantBeLeafInSealedHierarchy(tree.sym)); - } else { - tree.sym.flags_field |= (((ClassType)tree.sym.type).permitted.isEmpty()) ? FINAL : SEALED; - } - } - //tree.sym.flags_field = chk.checkFlags(tree.pos(), tree.sym.flags_field, tree.sym, tree); - } - } } /** Main method: enter classes from the list of toplevel trees, possibly
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties Fri Feb 14 16:11:31 2020 -0500 +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties Fri Feb 14 17:17:21 2020 -0500 @@ -3473,10 +3473,6 @@ compiler.err.non.sealed.sealed.or.final.expected=\ one of: sealed, non-sealed or final modifiers expected -# 0: symbol -compiler.err.class.cant.be.leaf.in.sealed.hierarchy=\ - {0} cannot be a leaf in a sealed hierarchy - compiler.err.sealed.or.non.sealed.local.classes.not.allowed=\ sealed or non-sealed local classes are not allowed
--- a/test/langtools/tools/javac/diags/examples/CantInheritFromSealed.java Fri Feb 14 16:11:31 2020 -0500 +++ b/test/langtools/tools/javac/diags/examples/CantInheritFromSealed.java Fri Feb 14 17:17:21 2020 -0500 @@ -22,6 +22,8 @@ */ // key: compiler.err.cant.inherit.from.sealed +// key: compiler.err.non.sealed.sealed.or.final.expected +// options: --enable-preview -source ${jdk.version} sealed interface SealedInterface permits Sub1 { void m();
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/langtools/tools/javac/diags/examples/DuplicateTypeInPermits.java Fri Feb 14 17:17:21 2020 -0500 @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2017, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +// key: compiler.err.duplicated.type.in.permits +// options: --enable-preview -source ${jdk.version} + +sealed class Sealed permits Sub, Sub {} + +final class Sub extends Sealed {}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/langtools/tools/javac/diags/examples/NonSealedWithNoSealedSuper.java Fri Feb 14 17:17:21 2020 -0500 @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2017, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +// key: compiler.err.non.sealed.with.no.sealed.supertype +// options: --enable-preview -source ${jdk.version} + +class C {} + +non-sealed class Sub extends C {}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/langtools/tools/javac/diags/examples/PermitsInNoSealedClass.java Fri Feb 14 17:17:21 2020 -0500 @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2017, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +// key: compiler.err.permits.in.no.sealed.class +// options: --enable-preview -source ${jdk.version} + +class C permits Sub {} + +final class Sub extends C {}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/langtools/tools/javac/diags/examples/SealedMustHaveSubtypes.java Fri Feb 14 17:17:21 2020 -0500 @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2017, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +// key: compiler.err.sealed.type.must.have.subtypes +// options: --enable-preview -source ${jdk.version} + +sealed class Sealed {}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/langtools/tools/javac/diags/examples/SubtypeDoesntExtendSealed.java Fri Feb 14 17:17:21 2020 -0500 @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2017, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +// key: compiler.err.subtype.listed.in.permits.doesnt.extend.sealed +// options: --enable-preview -source ${jdk.version} + +sealed class Sealed permits Sub {} + +final class Sub {}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/langtools/tools/javac/diags/examples/TypeVarInPermits.java Fri Feb 14 17:17:21 2020 -0500 @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2017, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +// key: compiler.err.type.var.listed.in.permits +// options: --enable-preview -source ${jdk.version} + +class Outer<T> { + sealed class Sealed permits T {} +}