io.baratine.inject.Key.type()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(4.6k)|赞(0)|评价(0)|浏览(133)

本文整理了Java中io.baratine.inject.Key.type()方法的一些代码示例,展示了Key.type()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Key.type()方法的具体详情如下:
包路径:io.baratine.inject.Key
类名称:Key
方法名:type

Key.type介绍

[英]Returns associated type
[中]返回关联的类型

代码示例

代码示例来源:origin: baratine/baratine

private <T> WebBuilder view(ViewRender<T> view, Key key)
{
 _views.add(new ViewRefRender(view, (Class) key.type(), 0));
 return this;
}

代码示例来源:origin: baratine/baratine

/**
 * Returns raw class of associated type
 *
 * @return raw class
 */
public Class<T> rawClass()
{
 Type type = type();
 if (type instanceof Class) {
  return (Class) type;
 }
 else if (type instanceof ParameterizedType) {
  ParameterizedType pType = (ParameterizedType) type;
  return (Class) pType.getRawType();
 }
 else {
  throw new UnsupportedOperationException(type + " " + type.getClass().getName());
 }
}

代码示例来源:origin: baratine/baratine

sb.append("[");
Type type = type();
if (type instanceof Class<?>) {
 sb.append(((Class<?>) type).getSimpleName());

代码示例来源:origin: baratine/baratine

static <T> InjectionPoint<T> of(Key<T> key)
{
 return new InjectionPointImpl<>(key,
   key.type(),
   key.rawClass().getSimpleName(),
   key.annotations(),
   key.rawClass());
}

代码示例来源:origin: baratine/baratine

/**
 * Creates a new instance for a given key.
 */
@Override
public <T> T instance(Key<T> key)
{
 Objects.requireNonNull(key);
 Class<T> type = (Class) key.rawClass();
 if (type.equals(Provider.class)) {
  TypeRef typeRef = TypeRef.of(key.type());
  TypeRef param = typeRef.param(0);
  return (T) provider(Key.of(param.type()));
 }
 Provider<T> provider = provider(key);
 if (provider != null) {
  return provider.get();
 }
 else {
  return null;
 }
}

代码示例来源:origin: baratine/baratine

@Override
public <T> Provider<T> provider(Injector injector, 
                InjectionPoint<T> ip)
{
 Var var = ip.annotation(Var.class);
 if (var == null) {
  return null;
 }
 
 String name = var.value();
 
 if (name.isEmpty()) {
  name = ip.name();
 }
 
 String defaultValue = var.defaultValue();
 return new ProviderVar<T>((InjectorAmp) injector,
              (Class<T>) ip.key().type(),
              name,
              defaultValue);
}

代码示例来源:origin: baratine/baratine

private void buildViews(InjectorAmp inject)
{
 for (Binding<ViewRender> binding : inject.bindings(ViewRender.class)) {
  try {
   ViewRender<?> view = (ViewRender<?>) binding.provider().get();
   Key<ViewRender<?>> key = (Key) binding.key();
   TypeRef typeRef = TypeRef.of(key.type());
   TypeRef renderRef = typeRef.to(ViewRender.class).param(0);
   Class<?> type = renderRef != null ? renderRef.rawClass() : Object.class;
   _views.add(new ViewRefRender(view, type, binding.priority()));
  } catch (Exception e) {
   log.log(Level.FINE, e.toString(), e);
  }
 }
 for (Binding<ViewResolver> binding : inject.bindings(ViewResolver.class)) {
  try {
   ViewResolver<?> view = (ViewResolver<?>) binding.provider().get();
   Key<ViewResolver<?>> key = (Key) binding.key();
   TypeRef typeRef = TypeRef.of(key.type());
   TypeRef resolverRef = typeRef.to(ViewResolver.class).param(0);
   Class<?> type = resolverRef != null ? resolverRef.rawClass() : Object.class;
   _views.add(new ViewRefResolver(view, type, binding.priority()));
  } catch (Exception e) {
   log.log(Level.FINE, e.toString(), e);
  }
 }
}

代码示例来源:origin: baratine/baratine

/**
 * default provider
 */
private <T> Provider<T> createProvider(Key<T> key)
{
 Class<T> type = (Class<T>) key.rawClass();
 if (Provider.class.equals(type)) {
  TypeRef subType = TypeRef.of(key.type()).to(Provider.class).param(0);
  Key<Object> subkey = Key.of(subType.type(), key.annotationTypes());
  return (Provider) new ProviderProvider(key, -10, provider(subkey));
 }
 else if (Optional.class.equals(type)) {
  TypeRef subType = TypeRef.of(key.type()).to(Optional.class).param(0);
  Key<Object> subkey = Key.of(subType.type(), key.annotationTypes());
  return (Provider) new ProviderOptional(key, -10, provider(subkey));
 }
 else if (type.isInterface() || Modifier.isAbstract(type.getModifiers())) {
  return new ProviderNull(key, -10000, new InjectScopeSingleton());
 }
 int priority = -10;
 // auto-provider is factory
 InjectScope<T> scope = findScope(type);
 BindingAmp<T> binding = new ProviderConstructor<>(this, key, priority, scope, type);
 binding.bind();
 return binding.provider();
}

代码示例来源:origin: baratine/baratine

private void init()
{
 for (ConvertFrom<?> convertManager
   : ConvertManagerImpl.convertManagers()) {
  add(convertManager);
 }
 
 for (Binding<ConvertFrom<?>> binding
   : _injector.bindings(new Key<ConvertFrom<?>>() {})) {
  add(binding.provider().get());
 }
 
 for (Binding<Convert<?,?>> binding
   : _injector.bindings(new Key<Convert<?,?>>() {})) {
  TypeRef convertRef = TypeRef.of(binding.key().type())
                .to(Convert.class);
  Class<?> sourceType = convertRef.param(0).rawClass();
  Class<?> targetType = convertRef.param(1).rawClass();
  
  add(sourceType, targetType, (Convert) binding.provider().get());
 }
}

相关文章