当前位置: 首页>>代码示例>>Java>>正文


Java DependencyAndSource类代码示例

本文整理汇总了Java中com.google.inject.spi.DependencyAndSource的典型用法代码示例。如果您正苦于以下问题:Java DependencyAndSource类的具体用法?Java DependencyAndSource怎么用?Java DependencyAndSource使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


DependencyAndSource类属于com.google.inject.spi包,在下文中一共展示了DependencyAndSource类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onProvision

import com.google.inject.spi.DependencyAndSource; //导入依赖的package包/类
@Override
public <T> void onProvision(ProvisionInvocation<T> provision) {
    for (DependencyAndSource dependencyAndSource : provision.getDependencyChain()) {
        Dependency<?> dependency = dependencyAndSource.getDependency();
        if (dependency != null && key.equals(dependency.getKey())) {
            try {
                ProviderAdapter.pushContext(dependency.getInjectionPoint());
                provision.provision();
            } finally {
                ProviderAdapter.popContext();
            }

            break;
        }
    }
}
 
开发者ID:tavianator,项目名称:sangria,代码行数:17,代码来源:ContextSensitiveBinder.java

示例2: findInjectionPoint

import com.google.inject.spi.DependencyAndSource; //导入依赖的package包/类
@Nullable
private static InjectionPoint findInjectionPoint(List<DependencyAndSource> dependencyChain) {
    if (dependencyChain.size() < 3) {
        new AssertionError("Provider is not included in the dependency chain").printStackTrace();
    }

    // @Inject InjectionPoint is the last, so we can skip it
    for (int i = dependencyChain.size() - 2; i >= 0; i--) {
        final Dependency<?> dependency = dependencyChain.get(i).getDependency();
        if (dependency == null) {
            return null;
        }
        final com.google.inject.spi.InjectionPoint spiInjectionPoint = dependency.getInjectionPoint();
        if (spiInjectionPoint != null) {
            final TypeToken<?> source = TypeToken.of(spiInjectionPoint.getDeclaringType().getType());
            final Member member = spiInjectionPoint.getMember();
            final InjectionPoint injectionPoint;
            if (member instanceof Field) {
                final Field field = (Field) member;
                injectionPoint = new InjectionPoint(source, TypeToken.of(field.getGenericType()), field.getAnnotations());
            } else if (member instanceof Executable) {
                final Executable executable = (Executable) member;
                final Annotation[][] parameterAnnotations = executable.getParameterAnnotations();
                final Type[] parameterTypes = executable.getGenericParameterTypes();
                final int index = dependency.getParameterIndex();
                injectionPoint = new InjectionPoint(source, TypeToken.of(parameterTypes[index]), parameterAnnotations[index]);
            } else {
                throw new IllegalStateException("Unsupported Member type: " + member.getClass().getName());
            }
            return injectionPoint;
        }
    }

    return null;
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:36,代码来源:InjectionPointProvider.java

示例3: getDependencyChain

import com.google.inject.spi.DependencyAndSource; //导入依赖的package包/类
/** Returns the current dependency chain (all the state). */
public List<DependencyAndSource> getDependencyChain() {
  ImmutableList.Builder<DependencyAndSource> builder = ImmutableList.builder();
  for (int i = 0; i < state.size(); i += 2) {
    builder.add(new DependencyAndSource(
        (Dependency<?>) state.get(i), state.get(i + 1)));
  }
  return builder.build();
}
 
开发者ID:cgruber,项目名称:guice-old,代码行数:10,代码来源:InternalContext.java

示例4: onProvision

import com.google.inject.spi.DependencyAndSource; //导入依赖的package包/类
public <T> void onProvision(ProvisionInvocation<T> provision) {
  List<Class<?>> actual = Lists.newArrayList();
  for (DependencyAndSource dep : provision.getDependencyChain()) {
    actual.add(dep.getDependency().getKey().getRawType());
  }
  assertEquals(expected, actual);
  provisionList.add(provision.getBinding().getKey().getRawType());
}
 
开发者ID:cgruber,项目名称:guice-old,代码行数:9,代码来源:ProvisionListenerTest.java

示例5: pushDependency

import com.google.inject.spi.DependencyAndSource; //导入依赖的package包/类
/** Sets the new current dependency & adds it to the state. */
public Dependency pushDependency(Dependency dependency, Object source) {
  Dependency previous = this.dependency;
  this.dependency = dependency;
  state.addLast(new DependencyAndSource(dependency, source));
  return previous;
}
 
开发者ID:utopiazh,项目名称:google-guice,代码行数:8,代码来源:InternalContext.java

示例6: getBindings

import com.google.inject.spi.DependencyAndSource; //导入依赖的package包/类
private Module getBindings(LogInject<_Logger_> logInject, Class<_Logger_> loggerClass)
{
    TypeLiteral<_Logger_> loggerType = TypeLiteral.get(loggerClass);
    GuiceLoggerProvider<_Logger_> provider = new GuiceLoggerProvider<>();
    Predicate<Dependency<?>> matchesLogger = dependency -> loggerType.equals(dependency.getKey().getTypeLiteral());
    return new AbstractModule()
    {
        @Override
        protected void configure()
        {
            ProvisionListener provisionListener = new ProvisionListener()
            {
                @Override
                public <_Target_> void onProvision(ProvisionInvocation<_Target_> provision)
                {
                    Binding<_Target_> binding = provision.getBinding();
                    if (loggerType.equals(binding.getKey().getTypeLiteral()))
                    {
                        Dependency<?> loggerDependency;
                        Stream<Dependency<?>> stream;
                        stream = provision.getDependencyChain().stream().map(DependencyAndSource::getDependency);
                        Iterator<Dependency<?>> dependencies = reverse(stream.collect(toList())).iterator();
                        if (dependencies.hasNext() && matchesLogger.test(loggerDependency = dependencies.next()))
                        {
                            InjectionPoint injectionPoint = loggerDependency.getInjectionPoint();
                            TypeLiteral<?> declaringType = injectionPoint.getDeclaringType();
                            TypeLiteral<?> targetType = null;
                            if (dependencies.hasNext())
                            {
                                TypeLiteral<?> typeLiteral = dependencies.next().getKey().getTypeLiteral();
                                if (declaringType.getRawType().isAssignableFrom(typeLiteral.getRawType()))
                                {
                                    targetType = typeLiteral;
                                }
                            }
                            Class<?> logger = (targetType != null? targetType:declaringType).getRawType();
                            BindingTargetVisitor<_Target_, Void> bindingTargetVisitor;
                            bindingTargetVisitor = new DefaultBindingTargetVisitor<_Target_, Void>()
                            {
                                @Override
                                public Void visit(ProviderInstanceBinding<? extends _Target_> instanceBinding)
                                {
                                    if (provider.equals(instanceBinding.getUserSuppliedProvider()))
                                    {
                                        provider.setLogger(logInject.createLogger(logger));
                                    }
                                    return null;
                                }
                            };
                            binding.acceptTargetVisitor(bindingTargetVisitor);
                        }
                    }
                }
            };
            bind(loggerClass).toProvider(provider);
            bindListener(Matchers.any(), provisionListener);
        }
    };
}
 
开发者ID:raner,项目名称:loginject,代码行数:60,代码来源:GuiceLogInjectionService.java

示例7: getDependencyChain

import com.google.inject.spi.DependencyAndSource; //导入依赖的package包/类
@Override
public List<DependencyAndSource> getDependencyChain() {
  return context.getDependencyChain();
}
 
开发者ID:cgruber,项目名称:guice-old,代码行数:5,代码来源:ProvisionListenerStackCallback.java

示例8: pushState

import com.google.inject.spi.DependencyAndSource; //导入依赖的package包/类
/** Adds to the state without setting the dependency. */
public void pushState(Key<?> key, Object source) {
  state.addLast(new DependencyAndSource(key == null ? null : Dependency.get(key), source));
}
 
开发者ID:utopiazh,项目名称:google-guice,代码行数:5,代码来源:InternalContext.java

示例9: getDependencyChain

import com.google.inject.spi.DependencyAndSource; //导入依赖的package包/类
/** Returns the current dependency chain (all the state). */
public List<DependencyAndSource> getDependencyChain() {
  return ImmutableList.copyOf(state);
}
 
开发者ID:utopiazh,项目名称:google-guice,代码行数:5,代码来源:InternalContext.java

示例10: getFor

import com.google.inject.spi.DependencyAndSource; //导入依赖的package包/类
/**
 * Provides an instance of {@link T} for a given binding and dependency.
 * The {@link InjectionPoint}s are available through the {@link DependencyAndSource}
 * objects. The last dependency in the list is the one being directly provided.
 *
 * Note carefully the cases in which {@link DependencyAndSource#getDependency} and
 * {@link Dependency#getInjectionPoint} can return null.
 */
protected abstract T getFor(Binding<T> binding, List<DependencyAndSource> dependencyChain);
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:10,代码来源:ContextualProvider.java


注:本文中的com.google.inject.spi.DependencyAndSource类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。