Package com.google.inject.spi

Examples of com.google.inject.spi.InjectionPoint$InjectableMembers


   
    private String describeInjectionPoints(TypeLiteral<?> type) {
        StringBuilder sb = new StringBuilder();
       
        try {
            InjectionPoint ip = InjectionPoint.forConstructorOf(type);
            List<Dependency<?>> deps = ip.getDependencies();
            if (!deps.isEmpty()) {
                for (Dependency<?> dep : deps) {
                    sb.append("     dep : " + dep.getKey()).append("\n");
                }
            }
View Full Code Here


                }
               
                // If @Inject is present then instantiate using that constructor and manually inject
                // the dependencies.  Note that a null will be injected for excluded modules
                try {
                    InjectionPoint ip = InjectionPoint.forConstructorOf(type);
                    if (ip != null) {
                        Constructor<?> c = (Constructor<?>) ip.getMember();
                        c.setAccessible(true);
                        List<Dependency<?>> deps = ip.getDependencies();
                        if (!deps.isEmpty()) {
                            Object[] args = new Object[deps.size()];
                            for (Dependency<?> dep : deps) {
                                Class<?> type = dep.getKey().getTypeLiteral().getRawType();
                                if (Module.class.isAssignableFrom(type)) {
View Full Code Here

                return instance;
            }
           
            private T create() {
                // Look for an @Inject constructor or just create a new instance if not found
                InjectionPoint injectionPoint = InjectionPoint.forConstructorOf(type);
                final long startTime = System.nanoTime();
               
                for (LifecycleListener listener : listeners) {
                    listener.objectInjecting(TypeLiteral.get(type));
                }
                if (injectionPoint != null) {
                    List<Dependency<?>> deps = injectionPoint.getDependencies();
                    if (deps.size() > 0) {
                        Constructor<?> constructor = (Constructor<?>)injectionPoint.getMember();
                        // One thread for each dependency
                        ExecutorService executor = Executors.newCachedThreadPool(
                                new ThreadFactoryBuilder()
                                    .setDaemon(true)
                                    .setNameFormat("ConcurrentProviders-" + type.getSimpleName() + "-%d")
View Full Code Here

      copyErrorsToBinder(e);
      injectionPoints = e.getPartialValue();
    }

    try {
      @SuppressWarnings("unchecked") // safe; constructor is a subtype of toConstruct
      InjectionPoint constructorPoint = InjectionPoint.forConstructor(constructor, type);
      setBinding(new ConstructorBindingImpl<T>(base.getKey(), base.getSource(), base.getScoping(),
          constructorPoint, injectionPoints));
    } catch (ConfigurationException e) {
      copyErrorsToBinder(e);
View Full Code Here

            loggerFactory, ImmutableSet.<InjectionPoint>of()));
  }

  private static class LoggerFactory implements InternalFactory<Logger>, Provider<Logger> {
    public Logger get(Errors errors, InternalContext context, Dependency<?> dependency) {
      InjectionPoint injectionPoint = dependency.getInjectionPoint();
      return injectionPoint == null
          ? Logger.getAnonymousLogger()
          : Logger.getLogger(injectionPoint.getMember().getDeclaringClass().getName());
    }
View Full Code Here

  }

  public static void formatSource(Formatter formatter, Object source) {
    if (source instanceof Dependency) {
      Dependency<?> dependency = (Dependency<?>) source;
      InjectionPoint injectionPoint = dependency.getInjectionPoint();
      if (injectionPoint != null) {
        formatInjectionPoint(formatter, dependency, injectionPoint);
      } else {
        formatSource(formatter, dependency.getKey());
      }
View Full Code Here

    return new ConstructorBindingImpl<T>(
        null, key, getSource(), factory, getScoping(), factory, constructorInjectionPoint);
  }

  public void applyTo(Binder binder) {
    InjectionPoint constructor = getConstructor();
    getScoping().applyTo(binder.withSource(getSource()).bind(getKey()).toConstructor(
        (Constructor) getConstructor().getMember(), (TypeLiteral) constructor.getDeclaringType()));
  }
View Full Code Here

            loggerFactory, ImmutableSet.<InjectionPoint>of()));
  }

  private static class LoggerFactory implements InternalFactory<Logger>, Provider<Logger> {
    public Logger get(Errors errors, InternalContext context, Dependency<?> dependency) {
      InjectionPoint injectionPoint = dependency.getInjectionPoint();
      return injectionPoint == null
          ? Logger.getAnonymousLogger()
          : Logger.getLogger(injectionPoint.getMember().getDeclaringClass().getName());
    }
View Full Code Here

  }

  public static void formatSource(Formatter formatter, Object source) {
    if (source instanceof Dependency) {
      Dependency<?> dependency = (Dependency<?>) source;
      InjectionPoint injectionPoint = dependency.getInjectionPoint();
      if (injectionPoint != null) {
        formatInjectionPoint(formatter, dependency, injectionPoint);
      } else {
        formatSource(formatter, dependency.getKey());
      }
View Full Code Here

    }

    @Test
    public void ensureInjectable() {
        try {
            InjectionPoint ip = InjectionPoint.forConstructorOf(GuiceEnvironment.class);
        } catch (Exception e) {
            fail("Could not create constructor injection point.");
        }
    }
View Full Code Here

TOP

Related Classes of com.google.inject.spi.InjectionPoint$InjectableMembers

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.