本文整理汇总了Java中com.google.inject.spi.Dependency.getInjectionPoint方法的典型用法代码示例。如果您正苦于以下问题:Java Dependency.getInjectionPoint方法的具体用法?Java Dependency.getInjectionPoint怎么用?Java Dependency.getInjectionPoint使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.inject.spi.Dependency
的用法示例。
在下文中一共展示了Dependency.getInjectionPoint方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: analyzeDependencies
import com.google.inject.spi.Dependency; //导入方法依赖的package包/类
private void analyzeDependencies(final Collection<Dependency<?>> dependencies)
{
for( final Dependency<?> d : dependencies )
{
final Key<?> key = d.getKey();
InjectionPoint injectionPoint = d.getInjectionPoint();
if( injectionPoint != null && injectionPoint.isOptional() )
{
continue;
}
if( key.getAnnotationType() == Assisted.class )
{
continue;
}
TypeLiteral<?> typeLiteral = key.getTypeLiteral();
Class<?> rawType = typeLiteral.getRawType();
if( rawType == Injector.class )
{
continue;
}
if( rawType == MembersInjector.class )
{
Key<?> injectedKey = key
.ofType(((ParameterizedType) typeLiteral.getType()).getActualTypeArguments()[0]);
dependentKeys.add(injectedKey);
analyzeImplementation(injectedKey.getTypeLiteral(), true);
}
else if( rawType == Provider.class )
{
dependentKeys.add(key.ofType(((ParameterizedType) typeLiteral.getType()).getActualTypeArguments()[0]));
}
else
{
dependentKeys.add(key);
}
}
}
示例2: findInjectionPoint
import com.google.inject.spi.Dependency; //导入方法依赖的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;
}
示例3: newInstanceNode
import com.google.inject.spi.Dependency; //导入方法依赖的package包/类
/**
* Returns a new instance node for the given {@link Binding}.
*
* @param binding binding for the node to create
* @param instance value of the instance
* @return instance node for the given binding
*/
private <T extends Binding<?> & HasDependencies> InstanceNode newInstanceNode(
T binding, Object instance) {
Collection<Member> members = Lists.newArrayList();
for (Dependency<?> dependency : binding.getDependencies()) {
InjectionPoint injectionPoint = dependency.getInjectionPoint();
if (injectionPoint != null) {
members.add(injectionPoint.getMember());
}
}
return new InstanceNode(
NodeId.newInstanceId(binding.getKey()), binding.getSource(), instance, members);
}
示例4: cleanup
import com.google.inject.spi.Dependency; //导入方法依赖的package包/类
/**
* Iterates through the binding's dependencies to clean up any stray bindings that were leftover
* from a failed JIT binding. This is required because the bindings are eagerly & optimistically
* added to allow circular dependency support, so dependencies may pass where they should have
* failed.
*/
private boolean cleanup(BindingImpl<?> binding, Set<Key> encountered) {
boolean bindingFailed = false;
Set<Dependency<?>> deps = getInternalDependencies(binding);
for (Dependency dep : deps) {
Key<?> depKey = dep.getKey();
InjectionPoint ip = dep.getInjectionPoint();
if (encountered.add(depKey)) { // only check if we haven't looked at this key yet
BindingImpl depBinding = jitBindings.get(depKey);
if (depBinding != null) { // if the binding still exists, validate
boolean failed = cleanup(depBinding, encountered); // if children fail, we fail
if (depBinding instanceof ConstructorBindingImpl) {
ConstructorBindingImpl ctorBinding = (ConstructorBindingImpl) depBinding;
ip = ctorBinding.getInternalConstructor();
if (!ctorBinding.isInitialized()) {
failed = true;
}
}
if (failed) {
removeFailedJitBinding(depBinding, ip);
bindingFailed = true;
}
} else if (state.getExplicitBinding(depKey) == null) {
// ignore keys if they were explicitly bound, but if neither JIT
// nor explicit, it's also invalid & should let parent know.
bindingFailed = true;
}
}
}
return bindingFailed;
}
示例5: get
import com.google.inject.spi.Dependency; //导入方法依赖的package包/类
@Override
public Logger get(InternalContext context, Dependency<?> dependency, boolean linked) {
InjectionPoint injectionPoint = dependency.getInjectionPoint();
return injectionPoint == null
? Logger.getAnonymousLogger()
: Logger.getLogger(injectionPoint.getMember().getDeclaringClass().getName());
}
示例6: formatSource
import com.google.inject.spi.Dependency; //导入方法依赖的package包/类
static void formatSource(Formatter formatter, Object source, ElementSource elementSource) {
String modules = moduleSourceString(elementSource);
if (source instanceof Dependency) {
Dependency<?> dependency = (Dependency<?>) source;
InjectionPoint injectionPoint = dependency.getInjectionPoint();
if (injectionPoint != null) {
formatInjectionPoint(formatter, dependency, injectionPoint, elementSource);
} else {
formatSource(formatter, dependency.getKey(), elementSource);
}
} else if (source instanceof InjectionPoint) {
formatInjectionPoint(formatter, null, (InjectionPoint) source, elementSource);
} else if (source instanceof Class) {
formatter.format(" at %s%s%n", StackTraceElements.forType((Class<?>) source), modules);
} else if (source instanceof Member) {
formatter.format(" at %s%s%n", StackTraceElements.forMember((Member) source), modules);
} else if (source instanceof TypeLiteral) {
formatter.format(" while locating %s%s%n", source, modules);
} else if (source instanceof Key) {
Key<?> key = (Key<?>) source;
formatter.format(" while locating %s%n", convert(key, elementSource));
} else if (source instanceof Thread) {
formatter.format(" in thread %s%n", source);
} else {
formatter.format(" at %s%s%n", source, modules);
}
}
示例7: newInstanceNode
import com.google.inject.spi.Dependency; //导入方法依赖的package包/类
/**
* Returns a new instance node for the given {@link Binding}.
*
* @param binding binding for the node to create
* @param instance value of the instance
* @return instance node for the given binding
*/
private <T extends Binding<?> & HasDependencies> InstanceNode newInstanceNode(T binding,
Object instance) {
Collection<Member> members = Lists.newArrayList();
for (Dependency<?> dependency : binding.getDependencies()) {
InjectionPoint injectionPoint = dependency.getInjectionPoint();
if (injectionPoint != null) {
members.add(injectionPoint.getMember());
}
}
return new InstanceNode(NodeId.newInstanceId(binding.getKey()), binding.getSource(), instance,
members);
}
示例8: cleanup
import com.google.inject.spi.Dependency; //导入方法依赖的package包/类
/**
* Iterates through the binding's dependencies to clean up any stray bindings that were leftover
* from a failed JIT binding. This is required because the bindings are eagerly &
* optimistically added to allow circular dependency support, so dependencies may pass where they
* should have failed.
*/
private boolean cleanup(BindingImpl<?> binding, Set<Key> encountered) {
boolean bindingFailed = false;
Set<Dependency<?>> deps = getInternalDependencies(binding);
for(Dependency dep : deps) {
Key<?> depKey = dep.getKey();
InjectionPoint ip = dep.getInjectionPoint();
if(encountered.add(depKey)) { // only check if we haven't looked at this key yet
BindingImpl depBinding = jitBindings.get(depKey);
if(depBinding != null) { // if the binding still exists, validate
boolean failed = cleanup(depBinding, encountered); // if children fail, we fail
if(depBinding instanceof ConstructorBindingImpl) {
ConstructorBindingImpl ctorBinding = (ConstructorBindingImpl)depBinding;
ip = ctorBinding.getInternalConstructor();
if(!ctorBinding.isInitialized()) {
failed = true;
}
}
if(failed) {
removeFailedJitBinding(depBinding, ip);
bindingFailed = true;
}
} else if(state.getExplicitBinding(depKey) == null) {
// ignore keys if they were explicitly bound, but if neither JIT
// nor explicit, it's also invalid & should let parent know.
bindingFailed = true;
}
}
}
return bindingFailed;
}
示例9: formatSource
import com.google.inject.spi.Dependency; //导入方法依赖的package包/类
public static void formatSource(Formatter formatter, Object source, ElementSource elementSource) {
String modules = moduleSourceString(elementSource);
if (source instanceof Dependency) {
Dependency<?> dependency = (Dependency<?>) source;
InjectionPoint injectionPoint = dependency.getInjectionPoint();
if (injectionPoint != null) {
formatInjectionPoint(formatter, dependency, injectionPoint, elementSource);
} else {
formatSource(formatter, dependency.getKey(), elementSource);
}
} else if (source instanceof InjectionPoint) {
formatInjectionPoint(formatter, null, (InjectionPoint) source, elementSource);
} else if (source instanceof Class) {
formatter.format(" at %s%s%n", StackTraceElements.forType((Class<?>) source), modules);
} else if (source instanceof Member) {
formatter.format(" at %s%s%n", StackTraceElements.forMember((Member) source), modules);
} else if (source instanceof TypeLiteral) {
formatter.format(" while locating %s%s%n", source, modules);
} else if (source instanceof Key) {
Key<?> key = (Key<?>) source;
formatter.format(" while locating %s%n", convert(key, elementSource));
} else {
formatter.format(" at %s%s%n", source, modules);
}
}
示例10: getBindings
import com.google.inject.spi.Dependency; //导入方法依赖的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);
}
};
}
示例11: get
import com.google.inject.spi.Dependency; //导入方法依赖的package包/类
public Logger get(Errors errors, InternalContext context, Dependency<?> dependency, boolean linked) {
InjectionPoint injectionPoint = dependency.getInjectionPoint();
return injectionPoint == null
? Logger.getAnonymousLogger()
: Logger.getLogger(injectionPoint.getMember().getDeclaringClass().getName());
}