Java 类com.google.inject.spi.UntargettedBinding 实例源码

项目:ProjectAres    文件:Bindings.java   
public static <T> Optional<TypeLiteral<? extends T>> targetType(Injector injector, Binding<T> binding) {
    if(binding instanceof UntargettedBinding) {
        return Optional.of(binding.getKey().getTypeLiteral());
    } else if(binding instanceof ConstructorBinding) {
        return Optional.of((TypeLiteral<? extends T>) ((ConstructorBinding) binding).getConstructor().getDeclaringType());
    } else if(binding instanceof InstanceBinding) {
        return Optional.of(TypeLiteral.get((Class<T>) ((InstanceBinding) binding).getInstance().getClass()));
    } else if(binding instanceof LinkedKeyBinding) {
        return targetType(injector, injector.getBinding(((LinkedKeyBinding) binding).getLinkedKey()));
    } else if(binding instanceof ExposedBinding) {
        return targetType(((ExposedBinding) binding).getPrivateElements().getInjector(), binding.getKey());
    }
    return Optional.empty();
}
项目:Equella    文件:GuicePlugin.java   
@Override
public <T> Collection<T> getBeansOfType(Class<T> clazz)
{
    Injector injector = ensureInjector();
    List<T> beans = new ArrayList<T>();
    Map<Key<?>, Binding<?>> bindings = injector.getBindings();
    for( Binding<?> binding : bindings.values() )
    {
        Key<?> actualKey = null;
        if( binding instanceof UntargettedBinding || binding instanceof ConstructorBinding )
        {
            actualKey = binding.getKey();
        }
        else if( binding instanceof LinkedKeyBinding )
        {
            actualKey = ((LinkedKeyBinding<?>) binding).getLinkedKey();
        }
        else if( binding instanceof ProviderBinding )
        {
            actualKey = ((ProviderBinding<?>) binding).getProvidedKey();
        }
        if( actualKey != null && clazz.isAssignableFrom(actualKey.getTypeLiteral().getRawType()) )
        {
            beans.add(clazz.cast(binding.getProvider().get()));
        }
    }
    return beans;
}
项目:guiceberry    文件:InterceptingBindingsBuilder.java   
@Override
public <T> Void visit(Binding<T> binding) {
  final Key<T> key = binding.getKey();

  if (!keysToIntercept.contains(key)) {
    return super.visit(binding);
  }

  binding.acceptTargetVisitor(new DefaultBindingTargetVisitor<T, Void>() {
    @Override
    public Void visit(UntargettedBinding<? extends T> untargettedBinding) {
      binder.addError("Cannot intercept bare binding of %s. " +
                "You may only intercept bindings that bind a class to something.", key);
      return null;
    }
  });

  Key<T> anonymousKey = Key.get(key.getTypeLiteral(), UniqueAnnotations.create());
  binder.bind(key).toProvider(new InterceptingProvider<T>(key, binder.getProvider(anonymousKey)));

  ScopedBindingBuilder scopedBindingBuilder = bindKeyToTarget(binding, binder, anonymousKey);

  // we scope the user's provider, not the interceptor. This is dangerous,
  // but convenient. It means that although the user's provider will live
  // in its proper scope, the intereptor gets invoked without a scope
  applyScoping(binding, scopedBindingBuilder);

  keysIntercepted.add(key);
  return null;
}
项目:guiceberry    文件:InterceptingBindingsBuilder.java   
@Override
public <T> Void visit(Binding<T> binding) {
  final Key<T> key = binding.getKey();

  if (!keysToIntercept.contains(key)) {
    return super.visit(binding);
  }

  binding.acceptTargetVisitor(new DefaultBindingTargetVisitor<T, Void>() {
    @Override
    public Void visit(UntargettedBinding<? extends T> untargettedBinding) {
      binder.addError("Cannot intercept bare binding of %s. " +
                "You may only intercept bindings that bind a class to something.", key);
      return null;
    }
  });

  Key<T> anonymousKey = Key.get(key.getTypeLiteral(), UniqueAnnotations.create());
  binder.bind(key).toProvider(new InterceptingProvider<T>(key, binder.getProvider(anonymousKey)));

  ScopedBindingBuilder scopedBindingBuilder = bindKeyToTarget(binding, binder, anonymousKey);

  // we scope the user's provider, not the interceptor. This is dangerous,
  // but convenient. It means that although the user's provider will live
  // in its proper scope, the interceptor gets invoked without a scope
  applyScoping(binding, scopedBindingBuilder);

  keysIntercepted.add(key);
  return null;
}
项目:guice    文件:UntargettedBindingImpl.java   
@Override
public String toString() {
  return MoreObjects.toStringHelper(UntargettedBinding.class)
      .add("key", getKey())
      .add("source", getSource())
      .toString();
}
项目:ProjectAres    文件:BindingTargetTypeResolver.java   
@Override
public Optional<TypeLiteral<?>> visit(UntargettedBinding<?> binding) {
    // Return the key type
    return of(binding.getKey().getTypeLiteral());
}
项目:ProjectAres    文件:DependencyCollector.java   
@Override
public Object visit(UntargettedBinding<? extends T> untargettedBinding) {
    processInjections(untargettedBinding.getKey().getTypeLiteral());
    return super.visit(untargettedBinding);
}
项目:ProjectAres    文件:Scoper.java   
@Override
public Void visit(UntargettedBinding<? extends T> binding) {
    scope(binding, rebind(binding));
    return null;
}
项目:Equella    文件:DependencyAnalyzer.java   
@Override
public Void visit(UntargettedBinding<? extends Object> untargettedBinding)
{
    analyzeImplementation(untargettedBinding.getKey().getTypeLiteral(), false);
    return null;
}
项目:google-gin    文件:GuiceBindingVisitor.java   
public Void visit(UntargettedBinding<? extends T> untargettedBinding) {
  addImplicitBinding(untargettedBinding);
  return null;
}
项目:guice    文件:Indexer.java   
@Override
public Indexer.IndexedBinding visit(UntargettedBinding<? extends Object> binding) {
  return new Indexer.IndexedBinding(binding, BindingType.UNTARGETTED, scope(binding), null);
}
项目:guice-old    文件:UntargettedBindingImpl.java   
@Override public String toString() {
  return Objects.toStringHelper(UntargettedBinding.class)
      .add("key", getKey())
      .add("source", getSource())
      .toString();
}
项目:google-guice    文件:UntargettedBindingImpl.java   
@Override public String toString() {
  return Objects.toStringHelper(UntargettedBinding.class)
      .add("key", getKey())
      .add("source", getSource())
      .toString();
}