RFR: JDK-8227046: compiler implementation for sealed classes, JDK-8227047: Javadoc for sealed types and JDK-8227044: javax.lang.model for sealed classes
Joe Darcy
joe.darcy at oracle.com
Fri May 22 19:13:24 UTC 2020
On 5/21/2020 5:20 AM, Maurizio Cimadamore wrote:
>
> On 21/05/2020 06:31, Joe Darcy wrote:
>> Hi Jan,
>>
>> On 5/19/2020 5:44 AM, Jan Lahoda wrote:
>>> Hi Vicente,
>>>
>>> javac changes look overall OK to me.
>>>
>>>
>> [snip]
>>
>>
>>> -regarding TypeElement#getPermittedSubclasses: it currently returns
>>> List<? extends TypeMirror>; I wonder if returning List<? extends
>>> TypeElement> would be better?
>>>
>> I did discuss this design point with Vicente ahead of time. While we
>> could probably get away with List<TypeElement> here with the current
>> design, I think List<TypeMirror> is more in keeping with
>> TypeElement.getSuperclass returning a TypeMirror.
>
> What do you think, in general of the 'getPermittedSubclasses' name?
> This term doesn't seem to apply to interfaces, as per section 8.1.4:
>
> " The optional extends clause in a normal class declaration specifies
> the direct superclass of the current class. "
>
> ...
>
> "A class is said to be a direct subclass of its direct superclass. The
> direct superclass is the class from whose implementation the
> implementation of the current class is derived. "
>
> "The subclass relationship is the transitive closure of the direct
> subclass relationship. A class A is a subclass of class C if either of
> the following is true:
>
> A is the direct subclass of C
>
> There exists a class B such that A is a subclass of B, and B is a
> subclass of C, applying this definition recursively.
>
When possible, as a design principle the javax.lang.model API aligns
with the terminology usage in JLS. In the few cases where JLS doesn't
provide needed terminology, the API steps out on its own, as with the
name javax.lang.model.element.NestingKind.
For the classes and interfaces a sealed class or interface permits, I
think getPermittedSubtypes would be a reasonable name. However, uses
"type" as a noun to mean "class or interface" is on the way out of the
JLS. After first being named PermittedSubtypes, the class file attribute
is now named "PermittedSubclasses " (JDK-8242578).
The TypeElement interface is used to model both class and interface
declarations so the same method will be used to retrieve the permitted
information for both kinds of declarations. Candidate names for this
method are:
1) getPermittedSubclasses -- not entirely accurate for interfaces
2) getPermittedSubtypes -- not aligned with current JLS usage
3) getPermittedClassesOrInteraces -- too long, even for javax.lang.model
I view 1) and 2) as viable names for the method. Certainly before the
change in "type" usage, I would have preferred 2); however, I think 1)
is acceptable if the spec
214 * Returns the permitted classes of this type element in
215 * declaration order.
is amended to discuss the permitted information for interfaces in some way.
Thanks,
-Joe
More information about the compiler-dev
mailing list