RFR: 8294982: Implementation of Classfile API [v12]
Adam Sotona
asotona at openjdk.org
Tue Feb 7 13:04:55 UTC 2023
On Tue, 7 Feb 2023 12:34:50 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:
>> `AttributedElement::attributedElementKind` identifies the one kind of the attributes holder.
>> The "places where an attribute can appear" is available through `AttributeMapper::whereApplicable` and matched against `AttributedElement::attributedElementKind`.
>> We may consider to hide or remove this auxiliary method, as `AttributedElement::attributedElementKind` might be computed from the ClassfileElement instance type.
>
> Still, there seems to be a modelling issue here. The property of "where could this attribute go" is a property of the attribute. Of course, for usability reason, an AttributedElement might expose a predicate saying "I only accept attributes of these kinds". But it seems to me as if the API has this relationship backwards, due to _where_ the Kind interface is being defined. I think if `Kind` was defined in `AttributeMapper` it would be a tad easier to understand. And, perhaps, the `attributedElementKind` name should be changed to something like `applicableAttributeKinds` or something like that.
The relation is that each `Attribute` is applicable in N `AttributedElements` and not vice versa.
For example `ClassModel::attributedElementKind` returns `CLASS` and for example `Attributes.RUNTIME_INVISIBLE_TYPE_ANNOTATIONS::applicableAttributeKinds` returns `Set.of(CLASS, METHOD, FIELD, CODE_ATTRIBUTE, RECORD_COMPONENT)`, so we know it is applicable.
However I'll try to re-visit this part of API if needed at all.
-------------
PR: https://git.openjdk.org/jdk/pull/10982
More information about the build-dev
mailing list