Skip to content

Commit e14565e

Browse files
committed
Add IContextFunction.ServiceContextKey OSGi component property type
This annotation simplifies the specification of the 'service.context.key' service property for IContextFunction implementations and makes it type-safe and more robust: ''' @component(service = IContextFunction.class) @IContextFunction.ServiceContextKey(IProgressService.class) public class ProgressServiceCreationFunction extends ContextFunction { '''
1 parent 7fa51b7 commit e14565e

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
dsVersion=V1_4
2+
eclipse.preferences.version=1
3+
enabled=true
4+
generateBundleActivationPolicyLazy=true
5+
path=OSGI-INF
6+
validationErrorLevel=error
7+
validationErrorLevel.missingImplicitUnbindMethod=error

runtime/bundles/org.eclipse.e4.core.contexts/META-INF/MANIFEST.MF

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Manifest-Version: 1.0
22
Bundle-ManifestVersion: 2
33
Bundle-SymbolicName: org.eclipse.e4.core.contexts
4-
Bundle-Version: 1.12.600.qualifier
4+
Bundle-Version: 1.13.0.qualifier
55
Bundle-Name: %pluginName
66
Bundle-Vendor: %providerName
77
Bundle-Localization: plugin

runtime/bundles/org.eclipse.e4.core.contexts/src/org/eclipse/e4/core/contexts/IContextFunction.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2009, 2013 IBM Corporation and others.
2+
* Copyright (c) 2009, 2024 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -10,11 +10,15 @@
1010
*
1111
* Contributors:
1212
* IBM Corporation - initial API and implementation
13+
* Hannes Wellmann - Add IContextFunction.ServiceContextKey OSGi component property type
1314
*******************************************************************************/
1415

1516
package org.eclipse.e4.core.contexts;
1617

18+
import java.lang.annotation.Retention;
19+
import java.lang.annotation.RetentionPolicy;
1720
import org.osgi.framework.BundleContext;
21+
import org.osgi.service.component.annotations.ComponentPropertyType;
1822

1923
/**
2024
* A context function encapsulates evaluation of some code within an
@@ -58,9 +62,23 @@ public interface IContextFunction {
5862
* should be registered in.
5963
*
6064
* @see BundleContext#getServiceReference(String)
65+
* @see ServiceContextKey
6166
*/
6267
String SERVICE_CONTEXT_KEY = "service.context.key"; //$NON-NLS-1$
6368

69+
/**
70+
* An OSGi service component property type used to indicate the context key this
71+
* function should be registered in.
72+
*
73+
* @since 1.13
74+
* @see #SERVICE_CONTEXT_KEY
75+
*/
76+
@ComponentPropertyType
77+
@Retention(RetentionPolicy.SOURCE)
78+
public @interface ServiceContextKey {
79+
Class<?> value();
80+
}
81+
6482
/**
6583
* Evaluates the function based on the provided arguments and context to
6684
* produce a consistent result.

0 commit comments

Comments
 (0)