From ec03a19086dab6165e6b0c2cd8e92338e8f23387 Mon Sep 17 00:00:00 2001 From: Hannes Wellmann Date: Tue, 1 Oct 2024 23:37:41 +0200 Subject: [PATCH] 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 { ''' --- .../META-INF/MANIFEST.MF | 2 +- .../e4/core/contexts/IContextFunction.java | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/runtime/bundles/org.eclipse.e4.core.contexts/META-INF/MANIFEST.MF b/runtime/bundles/org.eclipse.e4.core.contexts/META-INF/MANIFEST.MF index 8115cbca090..d581e5c01d9 100644 --- a/runtime/bundles/org.eclipse.e4.core.contexts/META-INF/MANIFEST.MF +++ b/runtime/bundles/org.eclipse.e4.core.contexts/META-INF/MANIFEST.MF @@ -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 diff --git a/runtime/bundles/org.eclipse.e4.core.contexts/src/org/eclipse/e4/core/contexts/IContextFunction.java b/runtime/bundles/org.eclipse.e4.core.contexts/src/org/eclipse/e4/core/contexts/IContextFunction.java index df3934b0e80..32d64c57ae1 100644 --- a/runtime/bundles/org.eclipse.e4.core.contexts/src/org/eclipse/e4/core/contexts/IContextFunction.java +++ b/runtime/bundles/org.eclipse.e4.core.contexts/src/org/eclipse/e4/core/contexts/IContextFunction.java @@ -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 @@ -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 IContextFunction#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.