当前位置: 首页>>代码示例>>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;未经允许,请勿转载。