Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DS] Use simple class name for single-element property annotations #1258

Merged

Conversation

HannesWell
Copy link
Member

@HannesWell HannesWell commented May 3, 2024

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:

Without this the generated component XML for the following class contains the wrong property names, instead of event.topics and my.comp the names are org.osgi.service.event.propertytypes.event.topics and my.comp.my.type.

package test.ds.component.props;

@Component(service = EventHandler.class)
@org.osgi.service.event.propertytypes.EventTopics(UIEvents.UILifeCycle.APP_STARTUP_COMPLETE)
@MyComp.MyType(Map.class)
public class MyComp implements EventHandler {

	@ComponentPropertyType
	@Target(ElementType.TYPE)
	public @interface MyType {
		Class<?>[] value();
	}

	@Override
	public void handleEvent(Event event) {
	}
}

[1] - https://docs.osgi.org/specification/osgi.cmpn/8.1.0/service.component.html#service.component-component.property.mapping

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
@HannesWell HannesWell requested a review from laeubi May 3, 2024 16:21
@laeubi
Copy link
Contributor

laeubi commented May 3, 2024

@HannesWell can you make sure we track this as a TCK in the OSGi repository?

Copy link

github-actions bot commented May 3, 2024

Test Results

   291 files  ±0     291 suites  ±0   54m 36s ⏱️ - 6m 15s
 3 526 tests ±0   3 468 ✅ ±0   58 💤 ±0  0 ❌ ±0 
10 875 runs  ±0  10 698 ✅ ±0  177 💤 ±0  0 ❌ ±0 

Results for commit af4b7dd. ± Comparison against base commit 6c8abe1.

@HannesWell
Copy link
Member Author

@HannesWell can you make sure we track this as a TCK in the OSGi repository?

I'll try to prepare a PR in the OSGi repository for such test-case. But since it will take some time any-ways until that is available I'll submit this now already.

@HannesWell HannesWell merged commit 8046286 into eclipse-pde:master May 3, 2024
17 checks passed
@HannesWell HannesWell deleted the fix-single-element-DS-annotations branch May 3, 2024 21:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants