本文整理汇总了Java中com.google.inject.spi.InjectionPoint类的典型用法代码示例。如果您正苦于以下问题:Java InjectionPoint类的具体用法?Java InjectionPoint怎么用?Java InjectionPoint使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
InjectionPoint类属于com.google.inject.spi包,在下文中一共展示了InjectionPoint类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: analyzeImplementation
import com.google.inject.spi.InjectionPoint; //导入依赖的package包/类
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);
}
}
示例2: checkOnlyAcceptsPlayer
import com.google.inject.spi.InjectionPoint; //导入依赖的package包/类
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;
}
示例3: newPassType
import com.google.inject.spi.InjectionPoint; //导入依赖的package包/类
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());
}
示例4: addStaticInjectionRequest
import com.google.inject.spi.InjectionPoint; //导入依赖的package包/类
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()));
}
}
}
示例5: injectValues
import com.google.inject.spi.InjectionPoint; //导入依赖的package包/类
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);
}
}
示例6: InternalProviderInstanceBindingImpl
import com.google.inject.spi.InjectionPoint; //导入依赖的package包/类
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;
}
示例7: toInstance
import com.google.inject.spi.InjectionPoint; //导入依赖的package包/类
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));
}
示例8: testInterceptOneMethod
import com.google.inject.spi.InjectionPoint; //导入依赖的package包/类
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);
}
示例9: formatInjectionPoint
import com.google.inject.spi.InjectionPoint; //导入依赖的package包/类
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());
}
}
示例10: testTurkeyBaconProblemUsingToConstuctor
import com.google.inject.spi.InjectionPoint; //导入依赖的package包/类
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());
}
示例11: toInstance
import com.google.inject.spi.InjectionPoint; //导入依赖的package包/类
@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));
}
示例12: createMembersInjectorBinding
import com.google.inject.spi.InjectionPoint; //导入依赖的package包/类
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);
}
示例13: getInjectors
import com.google.inject.spi.InjectionPoint; //导入依赖的package包/类
/** 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);
}
示例14: createMembersInjectorBinding
import com.google.inject.spi.InjectionPoint; //导入依赖的package包/类
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);
}
示例15: requestInjection
import com.google.inject.spi.InjectionPoint; //导入依赖的package包/类
/**
* 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;
}