forked from eclipse-efx/efxclipse-rt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refs eclipse-efx#182
- Loading branch information
Showing
9 changed files
with
55 additions
and
23 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
...ipse.fx.core.di.context/src/main/java/org/eclipse/fx/core/di/context/ScopeCalculator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,32 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2018 BestSolution.at and others. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Tom Schindl <[email protected]> - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.fx.core.di.context; | ||
|
||
import java.util.Optional; | ||
|
||
import org.eclipse.e4.core.contexts.IEclipseContext; | ||
import org.eclipse.fx.core.di.ContextScope; | ||
|
||
/** | ||
* Service to compute the {@link IEclipseContext} for the provided scope | ||
*/ | ||
public interface ScopeCalculator { | ||
/** | ||
* Compute the scope | ||
* | ||
* @param localContext | ||
* the local-context | ||
* @param scope | ||
* the scope | ||
* @return the context of an empty optional | ||
*/ | ||
public Optional<IEclipseContext> getContext(IEclipseContext localContext, ContextScope scope); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,13 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2018 BestSolution.at and others. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Tom Schindl <[email protected]> - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.fx.core.di.context.internal; | ||
|
||
import java.util.Optional; | ||
|
@@ -7,6 +17,9 @@ | |
import org.eclipse.fx.core.di.context.ScopeCalculator; | ||
import org.osgi.service.component.annotations.Component; | ||
|
||
/** | ||
* default implementation to compute the scope | ||
*/ | ||
@Component | ||
public class DefaultScopeCalculator implements ScopeCalculator { | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,18 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2018 BestSolution.at and others. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Tom Schindl <[email protected]> - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.fx.core.di.context.internal; | ||
|
||
import java.lang.reflect.Modifier; | ||
import java.lang.reflect.ParameterizedType; | ||
import java.lang.reflect.Type; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.function.Supplier; | ||
|
||
import javax.inject.Inject; | ||
|
@@ -20,7 +28,9 @@ | |
import org.eclipse.fx.core.di.Service; | ||
import org.osgi.service.component.annotations.Component; | ||
|
||
@SuppressWarnings("restriction") | ||
/** | ||
* Object supplier to compute local instance of the requested type | ||
*/ | ||
@Component(service=ExtendedObjectSupplier.class,property="dependency.injection.annotation:String=org.eclipse.fx.core.di.LocalInstance") | ||
public class LocalInstanceObjectSupplier extends ExtendedObjectSupplier { | ||
|
||
|
@@ -33,29 +43,21 @@ public Object get(IObjectDescriptor descriptor, IRequestor requestor, boolean tr | |
|
||
return instanceCreator.createInstance(descriptorsClass, r.getRequestingObjectClass()); | ||
} | ||
|
||
private static Class<?> getDesiredClass(Type desiredType) { | ||
if (desiredType instanceof Class<?>) | ||
return (Class<?>) desiredType; | ||
if (desiredType instanceof ParameterizedType) { | ||
Type rawType = ((ParameterizedType) desiredType).getRawType(); | ||
if (rawType instanceof Class<?>) | ||
return (Class<?>) rawType; | ||
} | ||
return null; | ||
} | ||
|
||
|
||
/** | ||
* Instance creation helper | ||
*/ | ||
public static class InstanceCreator { | ||
private final IEclipseContext context; | ||
private final List<TypeTypeProviderService<?>> providerList; | ||
|
||
@Inject | ||
public InstanceCreator(IEclipseContext context, @Service List<TypeTypeProviderService<?>> providerList) { | ||
InstanceCreator(IEclipseContext context, @Service List<TypeTypeProviderService<?>> providerList) { | ||
this.context = context; | ||
this.providerList = providerList; | ||
} | ||
|
||
public Object createInstance(Type iType, Class<?> owner) { | ||
Object createInstance(Type iType, Class<?> owner) { | ||
Supplier<Class<?>> classSuplier = () -> { | ||
if( iType instanceof Class<?> ) { | ||
Class<?> cl = (Class<?>) iType; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters