All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.ruediste.salta.standard.DefaultJITBindingRule Maven / Gradle / Ivy

Go to download

Core of the Salta Framework. Provides most of the infrastructure, but no API

There is a newer version: 1.1
Show newest version
package com.github.ruediste.salta.standard;

import java.util.Optional;
import java.util.function.Function;

import com.github.ruediste.salta.core.JITBinding;
import com.github.ruediste.salta.core.JITBindingKey;
import com.github.ruediste.salta.core.JITBindingRule;
import com.github.ruediste.salta.core.RecipeCreationContext;
import com.github.ruediste.salta.core.compile.SupplierRecipe;
import com.github.ruediste.salta.standard.config.StandardInjectorConfiguration;
import com.google.common.reflect.TypeToken;

public final class DefaultJITBindingRule implements JITBindingRule {
	private StandardInjectorConfiguration config;

	public DefaultJITBindingRule(StandardInjectorConfiguration config) {
		this.config = config;
	}

	@Override
	public JITBinding apply(JITBindingKey key) {
		TypeToken type = DefaultJITBindingKeyRule.jitBindingKeyType.get(key);
		if (!config.doQualifiersMatch(DefaultJITBindingKeyRule.jitBindingKeyRequiredQualifiers.get(key),
				config.getAvailableQualifier(type.getRawType())))
			return null;

		Optional> recipe = config.construction
				.createConstructionRecipe(type).map(seed -> ctx -> seed.apply(ctx));
		if (!recipe.isPresent())
			return null;

		StandardJitBinding binding = new StandardJitBinding(type);
		binding.recipeFactory = recipe.get()::apply;
		binding.scopeSupplier = () -> config.scope.getScope(type);
		return binding;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy