diff --git a/src/java.compiler/share/classes/javax/lang/model/element/package-info.java b/src/java.compiler/share/classes/javax/lang/model/element/package-info.java index 6e9b92bb806..1c3bc9292e1 100644 --- a/src/java.compiler/share/classes/javax/lang/model/element/package-info.java +++ b/src/java.compiler/share/classes/javax/lang/model/element/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2023, 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 @@ -110,6 +110,7 @@ * a {@code NullPointerException} if given a {@code null} argument. * * @see javax.lang.model.util.Elements + * @see javax.lang.model##elementsAndTypes Elements and Types * @see * JSR 269: Pluggable Annotation Processing API * @jls 6.1 Declarations diff --git a/src/java.compiler/share/classes/javax/lang/model/package-info.java b/src/java.compiler/share/classes/javax/lang/model/package-info.java index 44a31977bd0..5377b48065d 100644 --- a/src/java.compiler/share/classes/javax/lang/model/package-info.java +++ b/src/java.compiler/share/classes/javax/lang/model/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2023, 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 @@ -25,7 +25,7 @@ /** * Types and hierarchies of packages comprising a {@index "Java language - * model"}, a model of the declarations and types of the Java + * model"}, a reflective API that models the declarations and types of the Java * programming language. * * The members of this package and its subpackages are for use in @@ -52,6 +52,89 @@ *
Unless otherwise specified, methods in this package will throw * a {@code NullPointerException} if given a {@code null} argument. * + *
For example, consider the uses of {@code + * java.lang.String} in the string processing method {@code + * identityOrEmpty} below: + * + * {@snippet lang=java : + * // Return the argument if it is non-null and the empty string otherwise. + * public static @DefinitelyNotNull String identityOrEmpty(@MightBeNull String argument) { + * ... + * } + * } + * + * The return type of the method is a {@code String} annotated with + * a {@code @DefinitelyNotNull} type annotation while the type of + * the parameter is a {@code String} annotated with a {@code + * @MightBeNull} type annotation. In a reflective API, since the set + * of annotations is different for the two uses of {@code + * String} as a type, the return type and argument type would need to + * be represented by different objects to distinguish between these two + * cases. The definition of {@code java.lang.String} itself + * is annotated with neither of the type annotations in question. + * + *
Another example, consider the declaration of the generic
+ * interface (JLS {@jls 9.1.2}) {@code java.util.Set} which has one
+ * type parameter. This declaration captures commonality between the
+ * many parameterized types (JLS {@jls 4.5}) derived from that
+ * declaration such as {@code java.util.Set All elements can be {@linkplain
+ * javax.lang.model.element.Element#asType() mapped to} some type.
+ * The elements for classes and interfaces get {@linkplain
+ * javax.lang.model.element.TypeElement#asType() mapped to} a
+ * prototypical type. (If a class or interface is generic, its
+ * prototypical type mirror is parameterized with type arguments
+ * matching the type variables of the declaration, all
+ * unannotated. Otherwise, for a non-generic class or interface, the
+ * prototypical type mirror corresponds to an unannotated use of the
+ * type.) Conversely, in general, many types can map to the same
+ * {@linkplain javax.lang.model.element.TypeElement type element}. For
+ * example, the type mirror for the raw type {@code java.util.Set},
+ * the prototypical type {@code java.util.SetMapping between Elements and Types
+ *
+ * While distinct concepts, there are bidirectional (partial) mappings
+ * between elements and types, between definitions and uses. For
+ * example, roughly speaking, information that would be invariant for
+ * all uses of a type can be retrieved from the element defining a
+ * type. For example, consider a {@link
+ * javax.lang.model.type.DeclaredType DeclaredType} type mirror
+ * modeling a use of {@code java.lang.String}. Calling {@link
+ * javax.lang.model.type.DeclaredType#asElement()} would return the
+ * {@link javax.lang.model.element.TypeElement} for {@code
+ * java.lang.String}. From the {@code TypeElement}, common information
+ * such as {@linkplain
+ * javax.lang.model.element.TypeElement#getSimpleName() name} and
+ * {@linkplain javax.lang.model.element.TypeElement#getModifiers()
+ * modifiers} can be retrieved.
+ *
+ *