當前位置: 首頁>>代碼示例>>Java>>正文


Java TypeEncounter類代碼示例

本文整理匯總了Java中com.google.inject.spi.TypeEncounter的典型用法代碼示例。如果您正苦於以下問題:Java TypeEncounter類的具體用法?Java TypeEncounter怎麽用?Java TypeEncounter使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


TypeEncounter類屬於com.google.inject.spi包,在下文中一共展示了TypeEncounter類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: configure

import com.google.inject.spi.TypeEncounter; //導入依賴的package包/類
@Override
protected void configure() {
    registerConfigFiles(this.configFiles);

    //init system runtime eagerly
    bind(SystemRuntime.IRuntime.class).to(BaseRuntime.class).asEagerSingleton();

    bind(IResourceClientLibrary.class).to(ResourceClientLibrary.class).in(Scopes.SINGLETON);
    bind(IBotStoreClientLibrary.class).to(BotStoreClientLibrary.class).in(Scopes.SINGLETON);
    bind(IPackageStoreClientLibrary.class).to(PackageStoreClientLibrary.class).in(Scopes.SINGLETON);
    bind(IPackageStoreService.class).to(PackageStoreService.class).in(Scopes.SINGLETON);
    bind(IBotStoreService.class).to(BotStoreService.class).in(Scopes.SINGLETON);

    bind(IBotFactory.class).to(BotFactory.class).in(Scopes.SINGLETON);
    bind(IPackageFactory.class).to(PackageFactory.class).in(Scopes.SINGLETON);

    bind(IAutoBotDeployment.class).to(AutoBotDeployment.class).in(Scopes.SINGLETON);

    //call init method of system runtime after creation
    bindListener(HasInitMethod.INSTANCE, new TypeListener() {
        public <I> void hear(TypeLiteral<I> type, TypeEncounter<I> encounter) {
            encounter.register(InitInvoker.INSTANCE);
        }
    });
}
 
開發者ID:labsai,項目名稱:EDDI,代碼行數:26,代碼來源:RuntimeModule.java

示例2: configure

import com.google.inject.spi.TypeEncounter; //導入依賴的package包/類
@Override
protected void configure() {
  final Destroyer destroyer = new Destroyer(errorHandler);
  bind(Destroyer.class).toInstance(destroyer);
  bindListener(
      Matchers.any(),
      new TypeListener() {
        @Override
        public <T> void hear(TypeLiteral<T> type, TypeEncounter<T> encounter) {
          encounter.register(
              new InjectionListener<T>() {
                @Override
                public void afterInjection(T injectee) {
                  final Method[] methods = get(injectee.getClass(), annotationType);
                  if (methods.length > 0) {
                    // copy array when pass it outside
                    final Method[] copy = new Method[methods.length];
                    System.arraycopy(methods, 0, copy, 0, methods.length);
                    destroyer.add(injectee, copy);
                  }
                }
              });
        }
      });
}
 
開發者ID:eclipse,項目名稱:che,代碼行數:26,代碼來源:DestroyModule.java

示例3: hear

import com.google.inject.spi.TypeEncounter; //導入依賴的package包/類
/**
 * {@inheritDoc}
 */
@Override
public final <I> void hear(
        final TypeLiteral<I> typeLiteral,
        final TypeEncounter<I> typeEncounter) {
    Preconditions.checkNotNull(typeLiteral);
    Preconditions.checkNotNull(typeEncounter);

    // Go through the class and its ancestors to find fields like this:
    //     @InjectLogger private Logger logger;

    Class<?> clazz = typeLiteral.getRawType();
    while (clazz != null) {
        for (final Field field : clazz.getDeclaredFields()) {
            if (field.getType() == ILogger.class &&
                    field.isAnnotationPresent(InjectLogger.class)) {
                typeEncounter.register(new MetaborgLoggerMembersInjector<>(field));
            }
        }
        clazz = clazz.getSuperclass();
    }
}
 
開發者ID:metaborg,項目名稱:spoofax-intellij,代碼行數:25,代碼來源:MetaborgLoggerTypeListener.java

示例4: hear

import com.google.inject.spi.TypeEncounter; //導入依賴的package包/類
/**
 * {@inheritDoc}
 */
@Override
public final <I> void hear(
        final TypeLiteral<I> typeLiteral,
        final TypeEncounter<I> typeEncounter) {
    Preconditions.checkNotNull(typeLiteral);
    Preconditions.checkNotNull(typeEncounter);

    // Go through the class and its ancestors to find fields like this:
    //     @InjectLogger private Logger logger;

    Class<?> clazz = typeLiteral.getRawType();
    while (clazz != null) {
        for (final Field field : clazz.getDeclaredFields()) {
            if (field.getType() == Logger.class &&
                    field.isAnnotationPresent(InjectLogger.class)) {
                typeEncounter.register(new Slf4JLoggerMembersInjector<>(field));
            }
        }
        clazz = clazz.getSuperclass();
    }
}
 
開發者ID:metaborg,項目名稱:spoofax-intellij,代碼行數:25,代碼來源:Slf4JLoggerTypeListener.java

示例5: hear

import com.google.inject.spi.TypeEncounter; //導入依賴的package包/類
@Override
public <T> void hear(final TypeLiteral<T> typeLiteral,
		final TypeEncounter<T> typeEncounter)
{
	for (Field field : typeLiteral.getRawType().getDeclaredFields())
	{
		if (!field.isAnnotationPresent(InjectLogger.class))
			continue;

		if (field.getType() == org.apache.log4j.Logger.class)
			typeEncounter.register(new Log4JMembersInjector<T>(field));
		else if (field.getType() == org.slf4j.Logger.class)
			typeEncounter.register(new SLF4JMembersInjector<T>(field));
		else if (field.getType() == java.util.logging.Logger.class)
			typeEncounter.register(new JULMembersInjector<T>(field));
		else
			LOG.warn("@" + InjectLogger.class.getSimpleName()
					+ " annotated unknown logger type " + field.getType());

		// TODO add/inject other logger type implementations
	}
}
 
開發者ID:krevelen,項目名稱:coala,代碼行數:23,代碼來源:InjectLoggerTypeListener.java

示例6: configure

import com.google.inject.spi.TypeEncounter; //導入依賴的package包/類
@Override
protected void configure() {
    bind(ActionRepository.class).to(CassandraActionRepository.class);
    bind(PlayerRepository.class).to(CassandraPlayerRepository.class);
    bind(BadgeRepository.class).to(CassandraBadgeRepository.class);
    bind(EventRepository.class).to(CassandraEventRepository.class);
    bind(EventTypeRepository.class).to(CassandraEventTypeRepository.class);

    this.eventBus =  new AsyncEventBus(java.util.concurrent.Executors.newCachedThreadPool());
    bind(EventBus.class).toInstance(eventBus);

    bindListener(Matchers.any(), new TypeListener() {
        public <I> void hear(TypeLiteral<I> typeLiteral, TypeEncounter<I> typeEncounter) {
            typeEncounter.register(new InjectionListener<I>() {
                public void afterInjection(I i) {
                    eventBus.register(i);
                }
            });
        }
    });
}
 
開發者ID:rridgley1,項目名稱:agon,代碼行數:22,代碼來源:AgonModule.java

示例7: testToConstructorSpiData

import com.google.inject.spi.TypeEncounter; //導入依賴的package包/類
public void testToConstructorSpiData() throws NoSuchMethodException {
  final Set<TypeLiteral<?>> heardTypes = Sets.newHashSet();

  final Constructor<D> constructor = D.class.getConstructor(Stage.class);
  final TypeListener listener =
      new TypeListener() {
        @Override
        public <I> void hear(TypeLiteral<I> type, TypeEncounter<I> encounter) {
          if (!heardTypes.add(type)) {
            fail("Heard " + type + " multiple times!");
          }
        }
      };

  Guice.createInjector(
      new AbstractModule() {
        @Override
        protected void configure() {
          bind(Object.class).toConstructor(constructor);
          bind(D.class).toConstructor(constructor);
          bindListener(Matchers.any(), listener);
        }
      });
  
  assertEquals(ImmutableSet.of(TypeLiteral.get(D.class)), heardTypes);
}
 
開發者ID:google,項目名稱:guice,代碼行數:27,代碼來源:BindingTest.java

示例8: testTypeListenersAreFired

import com.google.inject.spi.TypeEncounter; //導入依賴的package包/類
public void testTypeListenersAreFired() {
  final AtomicInteger firedCount = new AtomicInteger();

  final TypeListener typeListener =
      new TypeListener() {
        @Override
        public <I> void hear(TypeLiteral<I> type, TypeEncounter<I> encounter) {
          assertEquals(new TypeLiteral<A>() {}, type);
          firedCount.incrementAndGet();
        }
      };

  Guice.createInjector(
      new AbstractModule() {
        @Override
        protected void configure() {
          bindListener(onlyAbcd, typeListener);
          bind(A.class);
        }
      });

  assertEquals(1, firedCount.get());
}
 
開發者ID:google,項目名稱:guice,代碼行數:24,代碼來源:TypeListenerTest.java

示例9: testLookupsPostCreate

import com.google.inject.spi.TypeEncounter; //導入依賴的package包/類
public void testLookupsPostCreate() {
  Injector injector =
      Guice.createInjector(
          new AbstractModule() {
            @Override
            protected void configure() {
              bindListener(
                  only(TypeLiteral.get(C.class)),
                  new TypeListener() {
                    @Override
                    public <I> void hear(TypeLiteral<I> type, TypeEncounter<I> encounter) {
                      assertNotNull(encounter.getProvider(B.class).get());

                      A a = new A();
                      encounter.getMembersInjector(A.class).injectMembers(a);
                      assertNotNull(a.injector);
                    }
                  });
            }
          });

  injector.getInstance(C.class);
}
 
開發者ID:google,項目名稱:guice,代碼行數:24,代碼來源:TypeListenerTest.java

示例10: testTypesWithNoInjectableMembersAreNotified

import com.google.inject.spi.TypeEncounter; //導入依賴的package包/類
/**
 * We had a bug where we weren't notifying of types encountered for member injection when those
 * types had no members to be injected. Constructed types are always injected because they always
 * have at least one injection point: the class constructor.
 */
public void testTypesWithNoInjectableMembersAreNotified() {
  final AtomicInteger notificationCount = new AtomicInteger();

  Guice.createInjector(
      new AbstractModule() {
        @Override
        protected void configure() {
          bindListener(
              onlyAbcd,
              new TypeListener() {
                @Override
                public <I> void hear(TypeLiteral<I> type, TypeEncounter<I> encounter) {
                  notificationCount.incrementAndGet();
                }
              });

          bind(C.class).toInstance(new C());
        }
      });

  assertEquals(1, notificationCount.get());
}
 
開發者ID:google,項目名稱:guice,代碼行數:28,代碼來源:TypeListenerTest.java

示例11: testToConstructorSpiData

import com.google.inject.spi.TypeEncounter; //導入依賴的package包/類
public void testToConstructorSpiData() throws NoSuchMethodException {
  final Set<TypeLiteral<?>> heardTypes = Sets.newHashSet();

  final Constructor<D> constructor = D.class.getConstructor(Stage.class);
  final TypeListener listener = new TypeListener() {
    public <I> void hear(TypeLiteral<I> type, TypeEncounter<I> encounter) {
      if (!heardTypes.add(type)) {
        fail("Heard " + type + " multiple times!");
      }
    }
  };

  Guice.createInjector(new AbstractModule() {
    protected void configure() {
      bind(Object.class).toConstructor(constructor);
      bind(D.class).toConstructor(constructor);
      bindListener(Matchers.any(), listener);
    }
  });
  
  assertEquals(ImmutableSet.of(TypeLiteral.get(D.class)), heardTypes);
}
 
開發者ID:cgruber,項目名稱:guice-old,代碼行數:23,代碼來源:BindingTest.java

示例12: testTypeListenersAreFired

import com.google.inject.spi.TypeEncounter; //導入依賴的package包/類
public void testTypeListenersAreFired() {
  final AtomicInteger firedCount = new AtomicInteger();

  final TypeListener typeListener = new TypeListener() {
    public <I> void hear(TypeLiteral<I> type, TypeEncounter<I> encounter) {
      assertEquals(new TypeLiteral<A>() {}, type);
      firedCount.incrementAndGet();
    }
  };

  Guice.createInjector(new AbstractModule() {
    @Override protected void configure() {
      bindListener(onlyAbcd, typeListener);
      bind(A.class);
    }
  });

  assertEquals(1, firedCount.get());
}
 
開發者ID:cgruber,項目名稱:guice-old,代碼行數:20,代碼來源:TypeListenerTest.java

示例13: testAddingInterceptors

import com.google.inject.spi.TypeEncounter; //導入依賴的package包/類
public void testAddingInterceptors() throws NoSuchMethodException {
  final Matcher<Object> buzz = only(C.class.getMethod("buzz"));

  Injector injector = Guice.createInjector(new AbstractModule() {
    @Override protected void configure() {
      bindInterceptor(any(), buzz, prefixInterceptor("ka"));
      bindInterceptor(any(), any(), prefixInterceptor("fe"));

      bindListener(onlyAbcd, new TypeListener() {
        public <I> void hear(TypeLiteral<I> type, TypeEncounter<I> encounter) {
          encounter.bindInterceptor(any(), prefixInterceptor("li"));
          encounter.bindInterceptor(buzz, prefixInterceptor("no"));
        }
      });
    }
  });

  // interceptors must be invoked in the order they're bound.
  C c = injector.getInstance(C.class);
  assertEquals("kafelinobuzz", c.buzz());
  assertEquals("felibeep", c.beep());
}
 
開發者ID:cgruber,項目名稱:guice-old,代碼行數:23,代碼來源:TypeListenerTest.java

示例14: testLookupsPostCreate

import com.google.inject.spi.TypeEncounter; //導入依賴的package包/類
public void testLookupsPostCreate() {
  Injector injector = Guice.createInjector(new AbstractModule() {
    @Override protected void configure() {
      bindListener(only(TypeLiteral.get(C.class)), new TypeListener() {
        public <I> void hear(TypeLiteral<I> type, TypeEncounter<I> encounter) {
          assertNotNull(encounter.getProvider(B.class).get());

          A a = new A();
          encounter.getMembersInjector(A.class).injectMembers(a);
          assertNotNull(a.injector);
        }
      });
    }
  });
  
  injector.getInstance(C.class);
}
 
開發者ID:cgruber,項目名稱:guice-old,代碼行數:18,代碼來源:TypeListenerTest.java

示例15: testTypesWithNoInjectableMembersAreNotified

import com.google.inject.spi.TypeEncounter; //導入依賴的package包/類
/**
 * We had a bug where we weren't notifying of types encountered for member injection when those
 * types had no members to be injected. Constructed types are always injected because they always
 * have at least one injection point: the class constructor.
 */
public void testTypesWithNoInjectableMembersAreNotified() {
  final AtomicInteger notificationCount = new AtomicInteger();

  Guice.createInjector(new AbstractModule() {
    @Override protected void configure() {
      bindListener(onlyAbcd, new TypeListener() {
        public <I> void hear(TypeLiteral<I> type, TypeEncounter<I> encounter) {
          notificationCount.incrementAndGet();
        }
      });

      bind(C.class).toInstance(new C());
    }
  });

  assertEquals(1, notificationCount.get());
}
 
開發者ID:cgruber,項目名稱:guice-old,代碼行數:23,代碼來源:TypeListenerTest.java


注:本文中的com.google.inject.spi.TypeEncounter類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。