jandex
jandex copied to clipboard
Add support for sealed classes
I'm not aware of any prospective user, so filing this just for tracking. I'm thinking 3.x only, unless someone actually asks for a backport to 2.x.
Note to self: https://docs.oracle.com/javase/specs/jvms/se17/html/jvms-4.html#jvms-4.7.31
We need to read (and remember) the PermittedSubclasses attribute in the ClassFile structure, which lists the permitted subclasses of the present class. Its presence also signifies that the present class is sealed.
/**
* Returns the set of permitted subclasses of this {@code sealed} class (or interface).
* Returns an empty set if this class is not {@code sealed}.
*
* @return immutable set of names of this class's permitted subclasses, never {@code null}
*/
public Set<DotName> permittedSubclasses() {
...
}
and a helper method
/**
* @return {@code true} if this class object represents a sealed class (or interface)
*/
public boolean isSealed() {
return !permittedSubclasses().isEmpty();
}
We don't need an isNonSealed() method, because we already have isFinal() and a permitted subclass of a sealed class must always be either sealed, non-sealed or final.