Skip to content

Commit

Permalink
fixed some warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
tomsontom committed Feb 9, 2018
1 parent b5276d9 commit 68bc576
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 23 deletions.
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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
/**
* Supplier working for {@link Adapt}
*/
@SuppressWarnings("restriction")
@Component(service=ExtendedObjectSupplier.class,property="dependency.injection.annotation:String=org.eclipse.fx.core.adapter.Adapt")
public class AdaptValueSupplier extends ExtendedObjectSupplier {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
/**
* Supplier which handles the {@link ContextValue}
*/
@SuppressWarnings("restriction")
@Component(service=ExtendedObjectSupplier.class,property="dependency.injection.annotation:String=org.eclipse.fx.core.di.ContextValue")
public class ContextBoundValueSupplier extends ExtendedObjectSupplier {

Expand Down
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;
Expand All @@ -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 {

Expand Down
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;
Expand All @@ -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 {

Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
/**
* DI Extension to inject {@link Log} into your DI-Bean
*/
@SuppressWarnings("restriction")
@Component(service=ExtendedObjectSupplier.class,property="dependency.injection.annotation:String=org.eclipse.fx.core.log.Log")
public class LoggerSupplier extends ExtendedObjectSupplier {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public PreferenceValue(@NonNull IEclipseContext context, @NonNull AdapterService
* @param defaultValue
* the default value
*/
@SuppressWarnings({ "unchecked", "null" })
@SuppressWarnings({ "unchecked" })
public void init(String nodePath, @NonNull String contextKey, Class<?> cl, Class<?> valueType, T defaultValue) {
this.contextKey = contextKey;
this.rootType = cl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
/**
* Context function to create requested object factory
*/
@SuppressWarnings("restriction")
@Component(service=IContextFunction.class,property="service.context.key:String=org.eclipse.fx.core.di.ScopedObjectFactory")
public class ScopedObjectFactoryFunction extends ContextFunction {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
*
* @since 1.2
*/
@SuppressWarnings("restriction")
@Component(service=ExtendedObjectSupplier.class,property="dependency.injection.annotation:String=org.eclipse.fx.core.di.Service")
public class ServiceSupplier extends ExtendedObjectSupplier {

Expand Down

0 comments on commit 68bc576

Please sign in to comment.