8321114: Rename "Unnamed Classes" to "Implicitly Declared Classes" better

Reviewed-by: jlaskey
This commit is contained in:
Pavel Rappo 2023-12-01 11:51:25 +00:00
parent ecd335d8f4
commit 8f1d40b48b
8 changed files with 19 additions and 19 deletions

View File

@ -190,21 +190,21 @@ import sun.reflect.misc.ReflectUtil;
* a class or interface is hidden has no bearing on the characteristics * a class or interface is hidden has no bearing on the characteristics
* exposed by the methods of class {@code Class}. * exposed by the methods of class {@code Class}.
* *
* <h2><a id=implicitClasses>Implicit Classes</a></h2> * <h2><a id=implicitClasses>Implicitly Declared Classes</a></h2>
* *
* Conventionally, a Java compiler, starting from a source file for an * Conventionally, a Java compiler, starting from a source file for an
* implicit class, say {@code HelloWorld.java}, creates a * implicitly declared class, say {@code HelloWorld.java}, creates a
* similarly-named {@code class} file, {@code HelloWorld.class}, where * similarly-named {@code class} file, {@code HelloWorld.class}, where
* the class stored in that {@code class} file is named {@code * the class stored in that {@code class} file is named {@code
* "HelloWorld"}, matching the base names of the source and {@code * "HelloWorld"}, matching the base names of the source and {@code
* class} files. * class} files.
* *
* For the {@code Class} object of an implicit class {@code * For the {@code Class} object of an implicitly declared class {@code
* HelloWorld}, the methods to get the {@linkplain #getName name} and * HelloWorld}, the methods to get the {@linkplain #getName name} and
* {@linkplain #getTypeName type name} return results * {@linkplain #getTypeName type name} return results
* equal to {@code "HelloWorld"}. The {@linkplain #getSimpleName * equal to {@code "HelloWorld"}. The {@linkplain #getSimpleName
* simple name} of such an implicit class is {@code "HelloWorld"} and the * simple name} of such an implicitly declared class is {@code "HelloWorld"} and
* {@linkplain #getCanonicalName canonical name} is {@code "HelloWorld"}. * the {@linkplain #getCanonicalName canonical name} is {@code "HelloWorld"}.
* *
* @param <T> the type of the class modeled by this {@code Class} * @param <T> the type of the class modeled by this {@code Class}
* object. For example, the type of {@code String.class} is {@code * object. For example, the type of {@code String.class} is {@code

View File

@ -71,7 +71,7 @@ public @interface PreviewFeature {
STRING_TEMPLATES, STRING_TEMPLATES,
@JEP(number=445, title="Unnamed Classes and Instance Main Methods", status="Deprecated") @JEP(number=445, title="Unnamed Classes and Instance Main Methods", status="Deprecated")
UNNAMED_CLASSES, UNNAMED_CLASSES,
@JEP(number=463, title="Implicit Classes and Instance Main Methods", status="Preview") @JEP(number=463, title="Implicitly Declared Classes and Instance Main Methods", status="Preview")
IMPLICIT_CLASSES, IMPLICIT_CLASSES,
@JEP(number=446, title="Scoped Values", status="Preview") @JEP(number=446, title="Scoped Values", status="Preview")
SCOPED_VALUES, SCOPED_VALUES,

View File

@ -181,7 +181,7 @@ public interface Filer {
* classes, the name argument is used to provide the leading component of the * classes, the name argument is used to provide the leading component of the
* name used for the output file. For example {@code filer.createSourceFile("Foo")} * name used for the output file. For example {@code filer.createSourceFile("Foo")}
* to create an implicitly declared class hosted in {@code Foo.java}. All * to create an implicitly declared class hosted in {@code Foo.java}. All
* implicit classes must be in an unnamed package. * implicitly declared classes must be in an unnamed package.
* *
* @apiNote To use a particular {@linkplain * @apiNote To use a particular {@linkplain
* java.nio.charset.Charset charset} to encode the contents of the * java.nio.charset.Charset charset} to encode the contents of the
@ -266,7 +266,7 @@ public interface Filer {
* classes, the name argument is used to provide the leading component of the * classes, the name argument is used to provide the leading component of the
* name used for the output file. For example {@code filer.createSourceFile("Foo")} * name used for the output file. For example {@code filer.createSourceFile("Foo")}
* to create an implicitly declared class hosted in {@code Foo.java}. All * to create an implicitly declared class hosted in {@code Foo.java}. All
* implicit classes must be in an unnamed package. * implicitly declared classes must be in an unnamed package.
* *
* @apiNote To avoid subsequent errors, the contents of the class * @apiNote To avoid subsequent errors, the contents of the class
* file should be compatible with the {@linkplain * file should be compatible with the {@linkplain

View File

@ -123,7 +123,7 @@ public class Flags {
*/ */
public static final int HASINIT = 1<<18; public static final int HASINIT = 1<<18;
/** Class is a implicit top level class. /** Class is an implicitly declared top level class.
*/ */
public static final int IMPLICIT_CLASS = 1<<19; public static final int IMPLICIT_CLASS = 1<<19;

View File

@ -1554,7 +1554,7 @@ public abstract class Symbol extends AnnoConstruct implements PoolConstant, Elem
@DefinedBy(Api.LANGUAGE_MODEL) @DefinedBy(Api.LANGUAGE_MODEL)
public NestingKind getNestingKind() { public NestingKind getNestingKind() {
apiComplete(); apiComplete();
if (owner.kind == PCK) // Handles implicit classes as well if (owner.kind == PCK) // Handles implicitly declared classes as well
return NestingKind.TOP_LEVEL; return NestingKind.TOP_LEVEL;
else if (name.isEmpty()) else if (name.isEmpty())
return NestingKind.ANONYMOUS; return NestingKind.ANONYMOUS;

View File

@ -3982,11 +3982,11 @@ public class JavacParser implements Parser {
defs.appendList(semiList.toList()); defs.appendList(semiList.toList());
boolean isTopLevelMethodOrField = false; boolean isTopLevelMethodOrField = false;
// Do to a significant number of existing negative tests // Due to a significant number of existing negative tests
// this code speculatively tests to see if a top level method // this code speculatively tests to see if a top level method
// or field can parse. If the method or field can parse then // or field can parse. If the method or field can parse then
// it is parsed. Otherwise, parsing continues as though // it is parsed. Otherwise, parsing continues as though
// implicit classes did not exist and error reporting // implicitly declared classes did not exist and error reporting
// is the same as in the past. // is the same as in the past.
if (Feature.IMPLICIT_CLASSES.allowedInSource(source) && !isDeclaration()) { if (Feature.IMPLICIT_CLASSES.allowedInSource(source) && !isDeclaration()) {
final JCModifiers finalMods = mods; final JCModifiers finalMods = mods;
@ -4014,7 +4014,7 @@ public class JavacParser implements Parser {
firstTypeDecl = false; firstTypeDecl = false;
} }
} }
List<JCTree> topLevelDefs = isImplicitClass ? constructImplictClass(defs.toList()) : defs.toList(); List<JCTree> topLevelDefs = isImplicitClass ? constructImplicitClass(defs.toList()) : defs.toList();
JCTree.JCCompilationUnit toplevel = F.at(firstToken.pos).TopLevel(topLevelDefs); JCTree.JCCompilationUnit toplevel = F.at(firstToken.pos).TopLevel(topLevelDefs);
if (!consumedToplevelDoc) if (!consumedToplevelDoc)
attach(toplevel, firstToken.docComment()); attach(toplevel, firstToken.docComment());
@ -4029,8 +4029,8 @@ public class JavacParser implements Parser {
return toplevel; return toplevel;
} }
// Restructure top level to be an implicit class. // Restructure top level to be an implicitly declared class.
private List<JCTree> constructImplictClass(List<JCTree> origDefs) { private List<JCTree> constructImplicitClass(List<JCTree> origDefs) {
ListBuffer<JCTree> topDefs = new ListBuffer<>(); ListBuffer<JCTree> topDefs = new ListBuffer<>();
ListBuffer<JCTree> defs = new ListBuffer<>(); ListBuffer<JCTree> defs = new ListBuffer<>();

View File

@ -525,10 +525,10 @@ compiler.err.bad.file.name=\
bad file name: {0} bad file name: {0}
compiler.err.implicit.class.should.not.have.package.declaration=\ compiler.err.implicit.class.should.not.have.package.declaration=\
implicit class should not have package declaration implicitly declared class should not have package declaration
compiler.err.implicit.class.does.not.have.main.method=\ compiler.err.implicit.class.does.not.have.main.method=\
implicit class does not have main method in the form of void main() or void main(String[] args) implicitly declared class does not have main method in the form of void main() or void main(String[] args)
# 0: name, 1: name # 0: name, 1: name
compiler.err.same.binary.name=\ compiler.err.same.binary.name=\
@ -3219,7 +3219,7 @@ compiler.misc.feature.unconditional.patterns.in.instanceof=\
unconditional patterns in instanceof unconditional patterns in instanceof
compiler.misc.feature.implicit.classes=\ compiler.misc.feature.implicit.classes=\
implicit classes implicitly declared classes
compiler.misc.feature.super.init=\ compiler.misc.feature.super.init=\
statements before super() statements before super()

View File

@ -52,7 +52,7 @@ import static javax.lang.model.util.ElementFilter.*;
import javax.tools.JavaFileObject; import javax.tools.JavaFileObject;
/** /**
* Test annotation processing representation of implicitly classes * Test annotation processing representation of implicitly declared classes
* constructed from either a source file or a class file. * constructed from either a source file or a class file.
*/ */
@SuppressWarnings("preview") @SuppressWarnings("preview")