本文整理汇总了Java中com.google.inject.spi.InjectionPoint类的典型用法代码示例。如果您正苦于以下问题:Java InjectionPoint类的具体用法?Java InjectionPoint怎么用?Java InjectionPoint使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
InjectionPoint类属于com.google.inject.spi包,在下文中一共展示了InjectionPoint类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
}
开发者ID:equella,项目名称:Equella,代码行数:23,代码来源:DependencyAnalyzer.java
示例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;
}
开发者ID:Twister915,项目名称:pl,代码行数:14,代码来源:JCommandExecutor.java
示例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());
}
开发者ID:wrmsr,项目名称:wava,代码行数:20,代码来源:PassType.java
示例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()));
}
}
}
开发者ID:google-code-export,项目名称:google-gin,代码行数:21,代码来源:GinjectorBindings.java
示例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);
}
}
开发者ID:xvik,项目名称:dropwizard-guicey,代码行数:17,代码来源:GuiceyInterceptor.java
示例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;
}
开发者ID:google,项目名称:guice,代码行数:18,代码来源:InternalProviderInstanceBindingImpl.java
示例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));
}
开发者ID:cgruber,项目名称:guice-old,代码行数:22,代码来源:BindingBuilder.java
示例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);
}
开发者ID:cgruber,项目名称:guice-old,代码行数:27,代码来源:ProxyFactoryTest.java
示例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());
}
}
开发者ID:cgruber,项目名称:guice-old,代码行数:20,代码来源:Errors.java
示例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());
}
开发者ID:cgruber,项目名称:guice-old,代码行数:24,代码来源:BindingTest.java
示例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));
}
开发者ID:google,项目名称:guice,代码行数:24,代码来源:BindingBuilder.java
示例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);
}
开发者ID:cgruber,项目名称:guice-old,代码行数:20,代码来源:InjectorImpl.java
示例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);
}
开发者ID:google,项目名称:guice,代码行数:22,代码来源:MembersInjectorStore.java
示例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);
}
开发者ID:google,项目名称:guice,代码行数:25,代码来源:InjectorImpl.java
示例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;
}
开发者ID:cgruber,项目名称:guice-old,代码行数:28,代码来源:Initializer.java
示例16: formatInjectionPoint
import com.google.inject.spi.InjectionPoint; //导入依赖的package包/类
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());
}
}
开发者ID:google,项目名称:guice,代码行数:22,代码来源:Messages.java
示例17: validate
import com.google.inject.spi.InjectionPoint; //导入依赖的package包/类
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);
}
开发者ID:google,项目名称:guice,代码行数:19,代码来源:InjectionRequestProcessor.java
示例18: scanner
import com.google.inject.spi.InjectionPoint; //导入依赖的package包/类
/**
* @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);
}
};
}
开发者ID:google,项目名称:guice,代码行数:20,代码来源:MultibindingsScanner.java
示例19: 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);
}
开发者ID:google,项目名称:guice,代码行数:27,代码来源:ProxyFactoryTest.java
示例20: testMultipleInterceptors
import com.google.inject.spi.InjectionPoint; //导入依赖的package包/类
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);
}
开发者ID:google,项目名称:guice,代码行数:17,代码来源:ProxyFactoryTest.java
注:本文中的com.google.inject.spi.InjectionPoint类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论