Skip to content

Commit

Permalink
Add IContextFunction.ServiceContextKey OSGi component property type
Browse files Browse the repository at this point in the history
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 {
'''
  • Loading branch information
HannesWell committed Oct 12, 2024
1 parent 7fa51b7 commit edad7ba
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
dsVersion=V1_4
eclipse.preferences.version=1
enabled=true
generateBundleActivationPolicyLazy=true
path=OSGI-INF
validationErrorLevel=error
validationErrorLevel.missingImplicitUnbindMethod=error
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-SymbolicName: org.eclipse.e4.core.contexts
Bundle-Version: 1.12.600.qualifier
Bundle-Version: 1.13.0.qualifier
Bundle-Name: %pluginName
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@

package org.eclipse.e4.core.contexts;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import org.osgi.framework.BundleContext;
import org.osgi.service.component.annotations.ComponentPropertyType;

/**
* A context function encapsulates evaluation of some code within an
Expand Down Expand Up @@ -58,9 +61,23 @@ public interface IContextFunction {
* should be registered in.
*
* @see BundleContext#getServiceReference(String)
* @see ServiceContextKey
*/
String SERVICE_CONTEXT_KEY = "service.context.key"; //$NON-NLS-1$

/**
* An OSGi service component property type used to indicate the context key this
* function should be registered in.
*
* @since 1.13
* @see #SERVICE_CONTEXT_KEY
*/
@ComponentPropertyType
@Retention(RetentionPolicy.SOURCE)
public @interface ServiceContextKey {
Class<?> value();
}

/**
* Evaluates the function based on the provided arguments and context to
* produce a consistent result.
Expand Down

0 comments on commit edad7ba

Please sign in to comment.