Skip to content

Commit

Permalink
[DS] Use simple class name for single-element property annotations
Browse files Browse the repository at this point in the history
Using the full name of the AST element representing a single-element
property annotations to derive the property name, makes the generated
annotation depend on the way a ComponentPropertyType annotation is
applied. For example with fully-qualified name or with the outer-class
if it's a inner class.
Instead the simple name of the resolved annotation class should be used
as stated in the OSGi compendium spec in '112.8.2.1 Component Property
Mapping' [1]:
'''
However, if the component property type is a single-element annotation,
see 9.7.3 in [7] The Java Language Specification, Java SE 8 Edition,
then the property name for the value method is derived from the name of
the component property type rather than the name of the method.

In this case, the simple name of the component property type, that is,
the name of the class without any package name or outer class name, if
the component property type is an inner class, must be converted to the
property name as follows:
'''

[1] - https://docs.osgi.org/specification/osgi.cmpn/8.1.0/service.component.html#service.component-component.property.mapping
  • Loading branch information
HannesWell committed May 3, 2024
1 parent 6c8abe1 commit 8046286
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1328,8 +1328,9 @@ private void processComponent(IDSModel model, TypeDeclaration type, ITypeBinding

private void collectComponentPropertyTypes(IDSDocumentFactory dsFactory,
LinkedHashMap<String, IDSProperty> newPropMap, Annotation propertyType) {
String fqdn = propertyType.getTypeName().getFullyQualifiedName();
ITypeBinding propertyTypeBinding = propertyType.resolveTypeBinding();
String simpleName = propertyTypeBinding.getName();

String prefix = getPrefix(propertyTypeBinding);
IMethodBinding[] methods = propertyTypeBinding.getDeclaredMethods();
Map<String, IDSProperty> map = Arrays.stream(methods)
Expand All @@ -1347,7 +1348,7 @@ private void collectComponentPropertyTypes(IDSDocumentFactory dsFactory,
}
if (propertyType instanceof MarkerAnnotation && map.isEmpty()) {
IDSProperty property = dsFactory.createProperty();
property.setPropertyName(NameGenerator.createClassPropertyName(fqdn, prefix));
property.setPropertyName(NameGenerator.createClassPropertyName(simpleName, prefix));
property.setPropertyType(IDSConstants.VALUE_PROPERTY_TYPE_BOOLEAN);
property.setPropertyValue(String.valueOf(Boolean.TRUE));
newPropMap.remove(property.getName()); // force re-insert (append)
Expand All @@ -1356,7 +1357,7 @@ private void collectComponentPropertyTypes(IDSDocumentFactory dsFactory,
}
if (propertyType instanceof SingleMemberAnnotation single && map.size() == 1) {
IDSProperty property = dsFactory.createProperty();
property.setPropertyName(NameGenerator.createClassPropertyName(fqdn, prefix));
property.setPropertyName(NameGenerator.createClassPropertyName(simpleName, prefix));
Expression expression = single.getValue();
property.setPropertyType(getPropertyType(expression.resolveTypeBinding()));
setPropertyValue(property, expression);
Expand Down

0 comments on commit 8046286

Please sign in to comment.