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

项目:Equella    文件:DependencyAnalyzer.java   
private void analyzeImplementation(final TypeLiteral<?> type, boolean ignoreConstructor)
{
    if( !scannedTypes.contains(type) )
    {
        try
        {
            if( (type.getRawType().getModifiers() & (Modifier.INTERFACE | Modifier.ABSTRACT)) == 0 )
            {
                analyzeInjectionPoints(InjectionPoint.forInstanceMethodsAndFields(type));
                if( !ignoreConstructor )
                {
                    analyzeDependencies(InjectionPoint.forConstructorOf(type).getDependencies());
                }
            }
        }
        catch( ConfigurationException ce )
        {
            errors.merge(ce.getErrorMessages());
        }
        scannedTypes.add(type);
    }
}
项目:pl    文件:JCommandExecutor.java   
private static boolean checkOnlyAcceptsPlayer(Class<? extends JCmd> executor) {
    for (InjectionPoint point : InjectionPoint.forInstanceMethodsAndFields(executor)) {
        if (!(point.getMember() instanceof Field))
            continue;

        Key<?> key = point.getDependencies().get(0).getKey();
        if (key.getTypeLiteral().getRawType().equals(Player.class)) {
            return true;
        }
    }

    return false;
}
项目:wava    文件:PassType.java   
public static PassType newPassType(String name, Class<? extends Pass> cls)
{
    ImmutableList.Builder<TypeLiteral<?>> inputs = ImmutableList.builder();
    ImmutableList.Builder<TypeLiteral<?>> outputs = ImmutableList.builder();
    InjectionPoint passCtor = InjectionPoint.forConstructorOf(cls);
    for (Dependency<?> dep : passCtor.getDependencies()) {
        Key key = dep.getKey();
        if (key.getAnnotation() instanceof PassInput) {
            inputs.add(key.getTypeLiteral());
        }
        else if (key.getAnnotation() instanceof PassOutput) {
            checkState(key.getTypeLiteral().getRawType() == Consumer.class);
            ParameterizedType parameterized = (ParameterizedType) key.getTypeLiteral().getType();
            java.lang.reflect.Type outputType = parameterized.getActualTypeArguments()[0];
            outputs.add(TypeLiteral.get(outputType));
        }
    }
    return new PassType(name, cls, inputs.build(), outputs.build());
}
项目:google-gin    文件:GinjectorBindings.java   
void addStaticInjectionRequest(Class<?> type, Object source) {
  assertNotFinalized();
  staticInjectionRequests.add(type);

  // Calculate required bindings and add to dependencies
  for (InjectionPoint injectionPoint : InjectionPoint.forStaticMethodsAndFields(type)) {
    Member member = injectionPoint.getMember();
    if (member instanceof Method) {
      addDependencies(guiceUtil.getDependencies(Dependency.GINJECTOR,
          MethodLiteral.get((Method) member, TypeLiteral.get(member.getDeclaringClass()))));
    } else if (member instanceof Field) {
      FieldLiteral<?> field =
          FieldLiteral.get((Field) member, TypeLiteral.get(member.getDeclaringClass()));
      Key<?> key = guiceUtil.getKey(field);
      addDependency(new Dependency(
          Dependency.GINJECTOR, key, guiceUtil.isOptional(field), false,
          source.toString()));
    }
  }
}
项目:dropwizard-guicey    文件:GuiceyInterceptor.java   
private void injectValues(final Object target, final boolean sharedFields) throws IllegalAccessException {
    for (InjectionPoint point : injectionPoints) {
        if (!(point.getMember() instanceof Field)) {
            throw new GuiceyExtensionException("Method injection is not supported; use field injection instead");
        }

        final Field field = (Field) point.getMember();
        if (field.isAnnotationPresent(Shared.class) != sharedFields) {
            continue;
        }

        final Object value = externalRuleAdapter.getInjector().getInstance(point.getDependencies().get(0).getKey());
        field.setAccessible(true);
        field.set(target, value);
    }
}
项目:guice    文件:InternalProviderInstanceBindingImpl.java   
InternalProviderInstanceBindingImpl(
    InjectorImpl injector,
    Key<T> key,
    Object source,
    Factory<T> originalFactory,
    InternalFactory<? extends T> scopedFactory,
    Scoping scoping) {
  super(
      injector,
      key,
      source,
      scopedFactory,
      scoping,
      originalFactory,
      ImmutableSet.<InjectionPoint>of());
  this.originalFactory = originalFactory;
}
项目:guice-old    文件:BindingBuilder.java   
public void toInstance(T instance) {
  checkNotTargetted();

  // lookup the injection points, adding any errors to the binder's errors list
  Set<InjectionPoint> injectionPoints;
  if (instance != null) {
    try {
      injectionPoints = InjectionPoint.forInstanceMethodsAndFields(instance.getClass());
    } catch (ConfigurationException e) {
      copyErrorsToBinder(e);
      injectionPoints = e.getPartialValue();
    }
  } else {
    binder.addError(BINDING_TO_NULL);
    injectionPoints = ImmutableSet.of();
  }

  BindingImpl<T> base = getBinding();
  setBinding(new InstanceBindingImpl<T>(
      base.getSource(), base.getKey(), Scoping.EAGER_SINGLETON, injectionPoints, instance));
}
项目:guice-old    文件:ProxyFactoryTest.java   
public void testInterceptOneMethod()
    throws NoSuchMethodException, InvocationTargetException, ErrorsException {
  SimpleInterceptor interceptor = new SimpleInterceptor();

  aspects.add(new MethodAspect(only(Bar.class), annotatedWith(Intercept.class), interceptor));

  ConstructionProxy<Foo> fooFactory
      = new ProxyFactory<Foo>(InjectionPoint.forConstructorOf(Foo.class), aspects).create();
  ConstructionProxy<Bar> barFactory
      = new ProxyFactory<Bar>(InjectionPoint.forConstructorOf(Bar.class), aspects).create();

  Foo foo = fooFactory.newInstance();
  Bar bar = barFactory.newInstance();

  foo.foo();
  assertTrue(foo.fooCalled);
  assertFalse(interceptor.invoked);

  bar.bar();
  assertTrue(bar.barCalled);
  assertFalse(interceptor.invoked);

  bar.intercepted();
  assertTrue(bar.interceptedCalled);
  assertTrue(interceptor.invoked);
}
项目:guice-old    文件:Errors.java   
public static void formatInjectionPoint(Formatter formatter, Dependency<?> dependency,
    InjectionPoint injectionPoint, ElementSource elementSource) {
  Member member = injectionPoint.getMember();
  Class<? extends Member> memberType = Classes.memberType(member);

  if (memberType == Field.class) {
    dependency = injectionPoint.getDependencies().get(0);
    formatter.format("  while locating %s%n", convert(dependency.getKey(), elementSource));
    formatter.format("    for field at %s%n", StackTraceElements.forMember(member));

  } else if (dependency != null) {
    formatter.format("  while locating %s%n", convert(dependency.getKey(), elementSource));
    formatter.format("    for parameter %s at %s%n",
        dependency.getParameterIndex(), StackTraceElements.forMember(member));

  } else {
    formatSource(formatter, injectionPoint.getMember());
  }
}
项目:guice-old    文件:BindingTest.java   
public void testTurkeyBaconProblemUsingToConstuctor() {
  Injector injector = Guice.createInjector(new AbstractModule() {
    @SuppressWarnings("unchecked")
    @Override
    public void configure() {
      bind(Bacon.class).to(UncookedBacon.class);
      bind(Bacon.class).annotatedWith(named("Turkey")).to(TurkeyBacon.class);
      bind(Bacon.class).annotatedWith(named("Cooked")).toConstructor(
          (Constructor)InjectionPoint.forConstructorOf(Bacon.class).getMember());
    }
  });
  Bacon bacon = injector.getInstance(Bacon.class);
  assertEquals(Food.PORK, bacon.getMaterial());
  assertFalse(bacon.isCooked());

  Bacon turkeyBacon = injector.getInstance(Key.get(Bacon.class, named("Turkey")));
  assertEquals(Food.TURKEY, turkeyBacon.getMaterial());
  assertTrue(turkeyBacon.isCooked());

  Bacon cookedBacon = injector.getInstance(Key.get(Bacon.class, named("Cooked")));
  assertEquals(Food.PORK, cookedBacon.getMaterial());
  assertTrue(cookedBacon.isCooked());    
}
项目:guice    文件:BindingBuilder.java   
@Override
public void toInstance(T instance) {
  checkNotTargetted();

  // lookup the injection points, adding any errors to the binder's errors list
  Set<InjectionPoint> injectionPoints;
  if (instance != null) {
    try {
      injectionPoints = InjectionPoint.forInstanceMethodsAndFields(instance.getClass());
    } catch (ConfigurationException e) {
      copyErrorsToBinder(e);
      injectionPoints = e.getPartialValue();
    }
  } else {
    binder.addError(BINDING_TO_NULL);
    injectionPoints = ImmutableSet.of();
  }

  BindingImpl<T> base = getBinding();
  setBinding(
      new InstanceBindingImpl<T>(
          base.getSource(), base.getKey(), Scoping.EAGER_SINGLETON, injectionPoints, instance));
}
项目:guice-old    文件:InjectorImpl.java   
private <T> BindingImpl<MembersInjector<T>> createMembersInjectorBinding(
    Key<MembersInjector<T>> key, Errors errors) throws ErrorsException {
  Type membersInjectorType = key.getTypeLiteral().getType();
  if (!(membersInjectorType instanceof ParameterizedType)) {
    throw errors.cannotInjectRawMembersInjector().toException();
  }

  @SuppressWarnings("unchecked") // safe because T came from Key<MembersInjector<T>>
  TypeLiteral<T> instanceType = (TypeLiteral<T>) TypeLiteral.get(
      ((ParameterizedType) membersInjectorType).getActualTypeArguments()[0]);
  MembersInjector<T> membersInjector = membersInjectorStore.get(instanceType, errors);

  InternalFactory<MembersInjector<T>> factory = new ConstantFactory<MembersInjector<T>>(
      Initializables.of(membersInjector));


  return new InstanceBindingImpl<MembersInjector<T>>(this, key, SourceProvider.UNKNOWN_SOURCE,
      factory, ImmutableSet.<InjectionPoint>of(), membersInjector);
}
项目:guice    文件:MembersInjectorStore.java   
/** Returns the injectors for the specified injection points. */
ImmutableList<SingleMemberInjector> getInjectors(
    Set<InjectionPoint> injectionPoints, Errors errors) {
  List<SingleMemberInjector> injectors = Lists.newArrayList();
  for (InjectionPoint injectionPoint : injectionPoints) {
    try {
      Errors errorsForMember =
          injectionPoint.isOptional()
              ? new Errors(injectionPoint)
              : errors.withSource(injectionPoint);
      SingleMemberInjector injector =
          injectionPoint.getMember() instanceof Field
              ? new SingleFieldInjector(this.injector, injectionPoint, errorsForMember)
              : new SingleMethodInjector(this.injector, injectionPoint, errorsForMember);
      injectors.add(injector);
    } catch (ErrorsException ignoredForNow) {
      // ignored for now
    }
  }
  return ImmutableList.copyOf(injectors);
}
项目:guice    文件:InjectorImpl.java   
private <T> BindingImpl<MembersInjector<T>> createMembersInjectorBinding(
    Key<MembersInjector<T>> key, Errors errors) throws ErrorsException {
  Type membersInjectorType = key.getTypeLiteral().getType();
  if (!(membersInjectorType instanceof ParameterizedType)) {
    throw errors.cannotInjectRawMembersInjector().toException();
  }

  @SuppressWarnings("unchecked") // safe because T came from Key<MembersInjector<T>>
  TypeLiteral<T> instanceType =
      (TypeLiteral<T>)
          TypeLiteral.get(((ParameterizedType) membersInjectorType).getActualTypeArguments()[0]);
  MembersInjector<T> membersInjector = membersInjectorStore.get(instanceType, errors);

  InternalFactory<MembersInjector<T>> factory =
      new ConstantFactory<MembersInjector<T>>(Initializables.of(membersInjector));

  return new InstanceBindingImpl<MembersInjector<T>>(
      this,
      key,
      SourceProvider.UNKNOWN_SOURCE,
      factory,
      ImmutableSet.<InjectionPoint>of(),
      membersInjector);
}
项目:guice-old    文件:Initializer.java   
/**
 * Registers an instance for member injection when that step is performed.
 *
 * @param instance an instance that optionally has members to be injected (each annotated with
 *      @Inject).
 * @param binding the binding that caused this initializable to be created, if it exists.
 * @param source the source location that this injection was requested
 */
<T> Initializable<T> requestInjection(InjectorImpl injector, T instance, Binding<T> binding,
    Object source, Set<InjectionPoint> injectionPoints) {
  checkNotNull(source);

  ProvisionListenerStackCallback<T> provisionCallback =
      binding == null ? null : injector.provisionListenerStore.get(binding);

  // short circuit if the object has no injections or listeners.
  if (instance == null || (injectionPoints.isEmpty()
      && !injector.membersInjectorStore.hasTypeListeners()
      && (provisionCallback == null || !provisionCallback.hasListeners()))) {
    return Initializables.of(instance);
  }

  InjectableReference<T> initializable = new InjectableReference<T>(
      injector, instance, binding == null ? null : binding.getKey(), provisionCallback, source);
  pendingInjection.put(instance, initializable);
  return initializable;
}
项目:guice    文件:Messages.java   
private static void formatInjectionPoint(
    Formatter formatter,
    Dependency<?> dependency,
    InjectionPoint injectionPoint,
    ElementSource elementSource) {
  Member member = injectionPoint.getMember();
  Class<? extends Member> memberType = Classes.memberType(member);

  if (memberType == Field.class) {
    dependency = injectionPoint.getDependencies().get(0);
    formatter.format("  while locating %s%n", convert(dependency.getKey(), elementSource));
    formatter.format("    for field at %s%n", StackTraceElements.forMember(member));

  } else if (dependency != null) {
    formatter.format("  while locating %s%n", convert(dependency.getKey(), elementSource));
    formatter.format("    for %s%n", formatParameter(dependency));

  } else {
    formatSource(formatter, injectionPoint.getMember());
  }
}
项目:guice    文件:InjectionRequestProcessor.java   
void validate() {
  Errors errorsForMember = errors.withSource(source);
  Set<InjectionPoint> injectionPoints;
  try {
    injectionPoints = request.getInjectionPoints();
  } catch (ConfigurationException e) {
    errorsForMember.merge(e.getErrorMessages());
    injectionPoints = e.getPartialValue();
  }
  if (injectionPoints != null) {
    memberInjectors =
        injector.membersInjectorStore.getInjectors(injectionPoints, errorsForMember);
  } else {
    memberInjectors = ImmutableList.of();
  }

  errors.merge(errorsForMember);
}
项目:guice    文件:MultibindingsScanner.java   
/**
 * @deprecated This method returns an empty scanner since the preexisting functionality is
 *     installed by default.
 */
@Deprecated
public static ModuleAnnotatedMethodScanner scanner() {
  return new ModuleAnnotatedMethodScanner() {
    @Override
    public Set<? extends Class<? extends Annotation>> annotationClasses() {
      return ImmutableSet.of();
    }

    @Override
    public <T> Key<T> prepareMethod(
        Binder binder, Annotation annotation, Key<T> key, InjectionPoint injectionPoint) {
      throw new IllegalStateException("Unexpected annotation: " + annotation);
    }
  };
}
项目:guice    文件:ProxyFactoryTest.java   
public void testInterceptOneMethod()
    throws NoSuchMethodException, InvocationTargetException, ErrorsException {
  SimpleInterceptor interceptor = new SimpleInterceptor();

  aspects.add(new MethodAspect(only(Bar.class), annotatedWith(Intercept.class), interceptor));

  ConstructionProxy<Foo> fooFactory =
      new ProxyFactory<Foo>(InjectionPoint.forConstructorOf(Foo.class), aspects).create();
  ConstructionProxy<Bar> barFactory =
      new ProxyFactory<Bar>(InjectionPoint.forConstructorOf(Bar.class), aspects).create();

  Foo foo = fooFactory.newInstance();
  Bar bar = barFactory.newInstance();

  foo.foo();
  assertTrue(foo.fooCalled);
  assertFalse(interceptor.invoked);

  bar.bar();
  assertTrue(bar.barCalled);
  assertFalse(interceptor.invoked);

  bar.intercepted();
  assertTrue(bar.interceptedCalled);
  assertTrue(interceptor.invoked);
}
项目:guice    文件:ProxyFactoryTest.java   
public void testMultipleInterceptors()
    throws NoSuchMethodException, InvocationTargetException, ErrorsException {
  DoubleInterceptor doubleInterceptor = new DoubleInterceptor();
  CountingInterceptor countingInterceptor = new CountingInterceptor();

  aspects.add(new MethodAspect(any(), any(), doubleInterceptor, countingInterceptor));
  ProxyFactory<Counter> factory =
      new ProxyFactory<Counter>(InjectionPoint.forConstructorOf(Counter.class), aspects);

  ConstructionProxy<Counter> constructor = factory.create();

  Counter counter = constructor.newInstance();
  counter.inc();
  assertEquals(2, counter.count);
  assertEquals(2, countingInterceptor.count);
}
项目:guice-old    文件:AbstractInjectorGrapherTest.java   
public void testLinkedAndInstanceBindings() throws Exception {
  grapher.graph(Guice.createInjector(new AbstractModule() {
      @Override protected void configure() {
        bind(IA.class).to(A.class);
        bind(IA.class).annotatedWith(Ann.class).to(A.class);
        bind(String.class).toInstance(TEST_STRING);
      }
  }));

  Set<Node> expectedNodes =
      ImmutableSet.<Node>of(iaNode, iaAnnNode, aNode, stringNode, stringInstanceNode);
  Set<Edge> expectedEdges = ImmutableSet.<Edge>of(
      new BindingEdge(iaNode.getId(), aNode.getId(), BindingEdge.Type.NORMAL),
      new BindingEdge(iaAnnNode.getId(), aNode.getId(), BindingEdge.Type.NORMAL),
      new BindingEdge(stringNode.getId(), stringInstanceNode.getId(), BindingEdge.Type.NORMAL),
      new DependencyEdge(aNode.getId(), stringNode.getId(),
          InjectionPoint.forConstructor(A.class.getConstructor(String.class))));
  assertEquals(expectedNodes, grapher.nodes);
  assertEquals(expectedEdges, grapher.edges);
}
项目:guice-old    文件:InjectorImpl.java   
/**
 * Converts a binding for a {@code Key<TypeLiteral<T>>} to the value {@code TypeLiteral<T>}. It's
 * a bit awkward because we have to pull out the inner type in the type literal.
 */
private <T> BindingImpl<TypeLiteral<T>> createTypeLiteralBinding(
    Key<TypeLiteral<T>> key, Errors errors) throws ErrorsException {
  Type typeLiteralType = key.getTypeLiteral().getType();
  if (!(typeLiteralType instanceof ParameterizedType)) {
    throw errors.cannotInjectRawTypeLiteral().toException();
  }

  ParameterizedType parameterizedType = (ParameterizedType) typeLiteralType;
  Type innerType = parameterizedType.getActualTypeArguments()[0];

  // this is unforunate. We don't support building TypeLiterals for type variable like 'T'. If
  // this proves problematic, we can probably fix TypeLiteral to support type variables
  if (!(innerType instanceof Class)
      && !(innerType instanceof GenericArrayType)
      && !(innerType instanceof ParameterizedType)) {
    throw errors.cannotInjectTypeLiteralOf(innerType).toException();
  }

  @SuppressWarnings("unchecked") // by definition, innerType == T, so this is safe
  TypeLiteral<T> value = (TypeLiteral<T>) TypeLiteral.get(innerType);
  InternalFactory<TypeLiteral<T>> factory = new ConstantFactory<TypeLiteral<T>>(
      Initializables.of(value));
  return new InstanceBindingImpl<TypeLiteral<T>>(this, key, SourceProvider.UNKNOWN_SOURCE,
      factory, ImmutableSet.<InjectionPoint>of(), value);
}
项目:guice-old    文件:ConstructorBindingImpl.java   
/** Returns a set of dependencies that can be iterated over to clean up stray JIT bindings. */
Set<Dependency<?>> getInternalDependencies() {
  ImmutableSet.Builder<InjectionPoint> builder = ImmutableSet.builder();
  if(factory.constructorInjector == null) {
    builder.add(constructorInjectionPoint);
    // If the below throws, it's OK -- we just ignore those dependencies, because no one
    // could have used them anyway.
    try {
      builder.addAll(InjectionPoint.forInstanceMethodsAndFields(constructorInjectionPoint.getDeclaringType()));
    } catch(ConfigurationException ignored) {}
  } else {
    builder.add(getConstructor())
           .addAll(getInjectableMembers());
  }

  return Dependency.forInjectionPoints(builder.build());
}
项目:ProjectAres    文件:Injection.java   
/**
 * Return all direct dependencies injected into the given type
 */
public static Stream<Dependency<?>> dependencies(Class<?> type) {
    return Stream.concat(
        Stream.of(InjectionPoint.forConstructorOf(type)),
        InjectionPoint.forInstanceMethodsAndFields(type).stream()
    ).flatMap(ip -> ip.getDependencies().stream());
}
项目:ProjectAres    文件:InjectableMethod.java   
private <D> InjectableMethod(@Nullable TypeLiteral<D> targetType, @Nullable D target, Method method, @Nullable T result) {
    final Errors errors = new Errors(method);

    if(Members.isStatic(method)) {
        checkArgument(target == null);
    } else {
        checkArgument(target != null);
    }

    targetType = targetType(targetType, target, method);

    checkArgument(method.getDeclaringClass().isAssignableFrom(targetType.getRawType()));

    this.method = method;
    this.dependencies = ImmutableSet.copyOf(InjectionPoint.forMethod(method, targetType).getDependencies());

    if(result != null) {
        this.result = result;
        this.providedKey = Keys.forInstance(result);
    } else {
        final TypeLiteral<T> returnType = (TypeLiteral<T>) targetType.getReturnType(method);
        if(!Void.class.equals(returnType.getRawType())) {
            final Annotation qualifier = Annotations.findBindingAnnotation(errors, method, method.getAnnotations());
            this.result = null;
            this.providedKey = Keys.get(returnType, qualifier);
        } else {
            this.result = (T) this;
            this.providedKey = Keys.forInstance(this.result);
        }
    }

    this.scope = Annotations.findScopeAnnotation(errors, method.getAnnotations());

    MethodHandle handle = MethodHandleUtils.privateUnreflect(method);
    if(target != null) {
        handle = handle.bindTo(target);
    }
    this.handle = handle;
}
项目:ProjectAres    文件:DependencyCollector.java   
public DependencyCollector log(Logger logger, Level level) {
    logger.log(level, "Dumping all dependencies:");
    for(Map.Entry<TypeLiteral<?>, Collection<InjectionPoint>> entry : injectionPointsByType().asMap().entrySet()) {
        logger.log(level, entry.getKey().toString());
        for(InjectionPoint ip : entry.getValue()) {
            logger.log(level, "  " + ip.getMember());
            for(Dependency<?> dep : dependenciesByInjectionPoint().get(ip)) {
                logger.log(level, "    " + dep);
            }
        }
    }
    return this;
}
项目:ProjectAres    文件:MemberInjectingFactory.java   
@Inject public MemberInjectingFactory(TypeLiteral<T> type, MembersInjector<T> injector) {
    this.type = type;
    this.injector = injector;
    this.injectionPoint = InjectionPoint.forConstructorOf(type);
    this.constructor = (Constructor<T>) injectionPoint.getMember();
    this.constructor.setAccessible(true);

    dependencies.addAll(Dependency.forInjectionPoints(InjectionPoint.forInstanceMethodsAndFields(type)));
}
项目:ProjectAres    文件:InjectionChecks.java   
public static void checkInjectableCGLibProxyBase(Class<?> cls) {
    InjectionPoint.forInstanceMethodsAndFields(cls).forEach(ip -> {
        if(ip.getMember() instanceof Method && !Modifier.isPrivate(ip.getMember().getModifiers())) {
            // CGLib proxies override all non-private methods on the base class,
            // and do not copy method annotations, so Guice will not find the
            // @Inject annotation on the base method. Declaring the method
            // private works around this. The proxy will not try to override
            // private methods, and Guice can find them just fine.
            throw new MethodFormException(
                (Method) ip.getMember(),
                "Injected method on CGLib proxied class must be private (see exception site for details)"
            );
        }
    });
}
项目:Equella    文件:DependencyAnalyzer.java   
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);
        }
    }
}
项目:Equella    文件:DependencyAnalyzer.java   
public void analyzeInjectionPoints(final Set<InjectionPoint> points)
{
    for( final InjectionPoint p : points )
    {
        analyzeDependencies(p.getDependencies());
    }
}
项目:sangria    文件:ContextSensitiveBinder.java   
@Override
public T get() {
    InjectionPoint ip = CURRENT_CONTEXT.get();
    if (ip != null) {
        return delegate().getInContext(ip);
    } else {
        return delegate().getInUnknownContext();
    }
}
项目:sangria    文件:ContextSensitiveBinder.java   
ProviderInstanceAdapter(ContextSensitiveProvider<? extends T> instance) {
    this.instance = instance;

    Set<InjectionPoint> injectionPoints;
    try {
        injectionPoints = InjectionPoint.forInstanceMethodsAndFields(instance.getClass());
    } catch (ConfigurationException e) {
        // We can ignore the error, the earlier requestInjection(instance) call will have reported it
        injectionPoints = e.getPartialValue();
    }
    this.injectionPoints = injectionPoints;
}
项目:guice-old    文件:InjectorImpl.java   
/** Cleans up any state that may have been cached when constructing the JIT binding. */
private void removeFailedJitBinding(Binding<?> binding, InjectionPoint ip) {
  failedJitBindings.add(binding.getKey());
  jitBindings.remove(binding.getKey());
  membersInjectorStore.remove(binding.getKey().getTypeLiteral());
  provisionListenerStore.remove(binding);
  if(ip != null) {
    constructors.remove(ip);
  }
}
项目:sangria    文件:ContextSensitiveBinderTest.java   
@Override
public Recursive getInContext(InjectionPoint injectionPoint) {
    Recursive result = new Recursive();
    membersInjector.injectMembers(result);
    result.self = injectionPoint.getDeclaringType().getRawType().getSimpleName();
    return result;
}
项目:guice    文件:DaggerMethodScanner.java   
@Override
public <T> Key<T> prepareMethod(
    Binder binder, Annotation rawAnnotation, Key<T> key, InjectionPoint injectionPoint) {
  Method providesMethod = (Method) injectionPoint.getMember();
  Provides annotation = (Provides) rawAnnotation;
  if (providesMethod.isAnnotationPresent(IntoSet.class)) {
    return processSetBinding(binder, key);
  } else if (providesMethod.isAnnotationPresent(ElementsIntoSet.class)) {
    binder.addError("@ElementsIntoSet contributions are not suppored by Guice.", providesMethod);
    return key;
  } else if (providesMethod.isAnnotationPresent(IntoMap.class)) {
    /* TODO(cgruber) implement map bindings */
    binder.addError("Map bindings are not yet supported.");
    return key;
  }

  switch (annotation.type()) {
    case UNIQUE:
      return key;
    case SET:
      return processSetBinding(binder, key);
    case SET_VALUES:
      binder.addError(
          Type.SET_VALUES.name() + " contributions are not supported by Guice.", providesMethod);
      return key;
    default:
      binder.addError("Unknown @Provides type " + annotation.type() + ".", providesMethod);
      return key;
  }
}
项目:guice    文件:GraphvizGrapher.java   
@Override
protected void newDependencyEdge(DependencyEdge edge) {
  GraphvizEdge gedge = new GraphvizEdge(edge.getFromId(), edge.getToId());
  InjectionPoint fromPoint = edge.getInjectionPoint();
  if (fromPoint == null) {
    gedge.setTailPortId("header");
  } else {
    gedge.setTailPortId(portIdFactory.getPortId(fromPoint.getMember()));
  }
  gedge.setArrowHead(ImmutableList.of(ArrowType.NORMAL));
  gedge.setTailCompassPoint(CompassPoint.EAST);

  edges.add(gedge);
}
项目:guice    文件:DefaultNodeCreator.java   
/**
 * 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);
}
项目:guice    文件:DefaultNodeCreator.java   
/**
 * Visitor for {@link ConstructorBinding}s. These are for classes that Guice will instantiate to
 * satisfy injection requests.
 */
@Override
public Collection<Node> visit(ConstructorBinding<?> binding) {
  Collection<Member> members = Lists.newArrayList();
  members.add(binding.getConstructor().getMember());
  for (InjectionPoint injectionPoint : binding.getInjectableMembers()) {
    members.add(injectionPoint.getMember());
  }

  return ImmutableList.<Node>of(newImplementationNode(binding, members));
}
项目:guice    文件:AbstractInjectorGrapherTest.java   
public void testLinkedAndInstanceBindings() throws Exception {
  grapher.graph(
      Guice.createInjector(
          new AbstractModule() {
            @Override
            protected void configure() {
              bind(IA.class).to(A.class);
              bind(IA.class).annotatedWith(Ann.class).to(A.class);
              bind(String.class).toInstance(TEST_STRING);
            }
          }));

  Set<Node> expectedNodes =
      ImmutableSet.<Node>of(iaNode, iaAnnNode, aNode, stringNode, stringInstanceNode);
  Set<Edge> expectedEdges =
      ImmutableSet.<Edge>of(
          new BindingEdge(iaNode.getId(), aNode.getId(), BindingEdge.Type.NORMAL),
          new BindingEdge(iaAnnNode.getId(), aNode.getId(), BindingEdge.Type.NORMAL),
          new BindingEdge(
              stringNode.getId(), stringInstanceNode.getId(), BindingEdge.Type.NORMAL),
          new DependencyEdge(
              aNode.getId(),
              stringNode.getId(),
              InjectionPoint.forConstructor(A.class.getConstructor(String.class))));
  assertEquals(expectedNodes, grapher.nodes);
  assertEquals(expectedEdges, grapher.edges);
}
项目:guice    文件:AbstractInjectorGrapherTest.java   
public void testProviderBindings() throws Exception {
  final Wrapper<Provider<A2>> wrapper = new Wrapper<>();
  grapher.graph(
      Guice.createInjector(
          new AbstractModule() {
            @Override
            protected void configure() {
              wrapper.value = getProvider(A2.class);
              bind(IA.class).toProvider(wrapper.value);
              bind(A2.class);
              bind(String.class).toInstance(TEST_STRING);
            }
          }));

  Node a2ProviderNode =
      new InstanceNode(
          NodeId.newInstanceId(Key.get(IA.class)),
          null,
          wrapper.value,
          ImmutableList.<Member>of());
  Set<Node> expectedNodes =
      ImmutableSet.<Node>of(iaNode, stringNode, a2Node, stringInstanceNode, a2ProviderNode);
  Set<Edge> expectedEdges =
      ImmutableSet.<Edge>of(
          new BindingEdge(
              stringNode.getId(), stringInstanceNode.getId(), BindingEdge.Type.NORMAL),
          new BindingEdge(iaNode.getId(), a2ProviderNode.getId(), BindingEdge.Type.PROVIDER),
          new DependencyEdge(
              a2Node.getId(),
              stringNode.getId(),
              InjectionPoint.forConstructor(A2.class.getConstructor(Provider.class))),
          new DependencyEdge(a2ProviderNode.getId(), a2Node.getId(), null));
  assertEquals("wrong nodes", expectedNodes, grapher.nodes);
  assertEquals("wrong edges", expectedEdges, grapher.edges);
}