本文整理汇总了Java中com.google.inject.internal.Annotations类的典型用法代码示例。如果您正苦于以下问题:Java Annotations类的具体用法?Java Annotations怎么用?Java Annotations使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Annotations类属于com.google.inject.internal包,在下文中一共展示了Annotations类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: resolve
import com.google.inject.internal.Annotations; //导入依赖的package包/类
@Override
public Object resolve(Injectee injectee, ServiceHandle<?> serviceHandle) {
if (injectee.getRequiredType() instanceof Class) {
TypeLiteral<?> typeLiteral = TypeLiteral.get(injectee.getRequiredType());
Errors errors = new Errors(injectee.getParent());
Key<?> key;
try {
key = Annotations.getKey(typeLiteral, (Member) injectee.getParent(),
injectee.getParent().getDeclaredAnnotations(), errors);
} catch (ErrorsException e) {
errors.merge(e.getErrors());
throw new ConfigurationException(errors.getMessages());
}
return injector.getInstance(key);
}
throw new IllegalStateException("Can't process injection point: " + injectee.getRequiredType());
}
示例2: testDuplicateKeys
import com.google.inject.internal.Annotations; //导入依赖的package包/类
public void testDuplicateKeys() {
try {
Guice.createInjector(
new AbstractModule() {
@Override
protected void configure() {
bind(DoubleToneCarFactory.class)
.toProvider(FactoryProvider.newFactory(DoubleToneCarFactory.class, Maxima.class));
}
});
fail();
} catch (CreationException expected) {
assertContains(
expected.getMessage(),
"A binding to "
+ Color.class.getName()
+ " annotated with @"
+ Assisted.class.getName()
+ "(value="
+ Annotations.memberValueString("paint")
+ ") was already configured at");
}
}
示例3: checkForMisplacedBindingAnnotations
import com.google.inject.internal.Annotations; //导入依赖的package包/类
/** Returns true if the binding annotation is in the wrong place. */
private static boolean checkForMisplacedBindingAnnotations(Member member, Errors errors) {
Annotation misplacedBindingAnnotation =
Annotations.findBindingAnnotation(
errors, member, ((AnnotatedElement) member).getAnnotations());
if (misplacedBindingAnnotation == null) {
return false;
}
// don't warn about misplaced binding annotations on methods when there's a field with the same
// name. In Scala, fields always get accessor methods (that we need to ignore). See bug 242.
if (member instanceof Method) {
try {
if (member.getDeclaringClass().getDeclaredField(member.getName()) != null) {
return false;
}
} catch (NoSuchFieldException ignore) {
}
}
errors.misplacedBindingAnnotation(member, misplacedBindingAnnotation);
return true;
}
示例4: testNoImplicitBindingIsCreatedForAnnotatedKeys
import com.google.inject.internal.Annotations; //导入依赖的package包/类
public void testNoImplicitBindingIsCreatedForAnnotatedKeys() {
try {
Guice.createInjector().getInstance(Key.get(I.class, Names.named("i")));
fail();
} catch (ConfigurationException expected) {
Asserts.assertContains(
expected.getMessage(),
"1) No implementation for " + I.class.getName(),
"annotated with @"
+ Named.class.getName()
+ "(value="
+ Annotations.memberValueString("i")
+ ") was bound.",
"while locating " + I.class.getName(),
" annotated with @"
+ Named.class.getName()
+ "(value="
+ Annotations.memberValueString("i")
+ ")");
}
}
示例5: assertDuplicateBinding
import com.google.inject.internal.Annotations; //导入依赖的package包/类
private static void assertDuplicateBinding(Module a, Module b, boolean fails) {
try {
Guice.createInjector(a, b);
if (fails) {
fail("should have thrown CreationException");
}
} catch (CreationException e) {
if (fails) {
assertContains(
e.getMessage(),
"A binding to java.lang.String annotated with @com.google.inject.name.Named(value="
+ Annotations.memberValueString("foo")
+ ") was already configured");
} else {
throw e;
}
}
}
示例6: checkForMisplacedBindingAnnotations
import com.google.inject.internal.Annotations; //导入依赖的package包/类
/**
* Returns true if the binding annotation is in the wrong place.
*/
private static boolean checkForMisplacedBindingAnnotations(Member member, Errors errors) {
Annotation misplacedBindingAnnotation = Annotations.findBindingAnnotation(
errors, member, ((AnnotatedElement) member).getAnnotations());
if (misplacedBindingAnnotation == null) {
return false;
}
// don't warn about misplaced binding annotations on methods when there's a field with the same
// name. In Scala, fields always get accessor methods (that we need to ignore). See bug 242.
if (member instanceof Method) {
try {
if (member.getDeclaringClass().getDeclaredField(member.getName()) != null) {
return false;
}
} catch (NoSuchFieldException ignore) {
}
}
errors.misplacedBindingAnnotation(member, misplacedBindingAnnotation);
return true;
}
示例7: applyScopeAnnotation
import com.google.inject.internal.Annotations; //导入依赖的package包/类
@SuppressWarnings("PMD.UnusedPrivateMethod")
private static void applyScopeAnnotation(final ClassPool classPool, final AnnotationsAttribute annotations,
final AnnotatedElement source,
final Class<? extends java.lang.annotation.Annotation> scope)
throws Exception {
if (scope != null) {
Preconditions.checkState(Annotations.isScopeAnnotation(scope),
"Provided annotation %s is not scope annotation", scope.getSimpleName());
for (java.lang.annotation.Annotation ann : source.getAnnotations()) {
Preconditions.checkArgument(!(ann instanceof ScopeAnnotation),
"Duplicate scope definition: scope is specified as %s and also defined "
+ "in @ScopeAnnotation.", scope.getSimpleName());
}
annotations.addAnnotation(new Annotation(annotations.getConstPool(), classPool.get(scope.getName())));
}
}
示例8: configure
import com.google.inject.internal.Annotations; //导入依赖的package包/类
@Override
protected void configure()
{
final Errors errors = new Errors(testClass);
for (FrameworkField field : fields)
{
try
{
final Field f = field.getField();
final Key key = Annotations.getKey(TypeLiteral.get(f.getGenericType()), f, field.getAnnotations(), errors);
bindMock(key, f.getType(), "Automock[" + field.getName() + "] " + key);
}
catch (ErrorsException e)
{
// Add it to the error list and hold them all until the end
errors.merge(e.getErrors());
}
}
errors.throwConfigurationExceptionIfErrorsExist();
}
示例9: InjectableMethod
import com.google.inject.internal.Annotations; //导入依赖的package包/类
private <D> InjectableMethod(@Nullable TypeLiteral<D> targetType, @Nullable D target, Method method, @Nullable T result) {
final Errors errors = new Errors(method);
if(Members.isStatic(method)) {
checkArgument(target == null);
} else {
checkArgument(target != null);
}
targetType = targetType(targetType, target, method);
checkArgument(method.getDeclaringClass().isAssignableFrom(targetType.getRawType()));
this.method = method;
this.dependencies = ImmutableSet.copyOf(InjectionPoint.forMethod(method, targetType).getDependencies());
if(result != null) {
this.result = result;
this.providedKey = Keys.forInstance(result);
} else {
final TypeLiteral<T> returnType = (TypeLiteral<T>) targetType.getReturnType(method);
if(!Void.class.equals(returnType.getRawType())) {
final Annotation qualifier = Annotations.findBindingAnnotation(errors, method, method.getAnnotations());
this.result = null;
this.providedKey = Keys.get(returnType, qualifier);
} else {
this.result = (T) this;
this.providedKey = Keys.forInstance(this.result);
}
}
this.scope = Annotations.findScopeAnnotation(errors, method.getAnnotations());
MethodHandle handle = MethodHandleUtils.privateUnreflect(method);
if(target != null) {
handle = handle.bindTo(target);
}
this.handle = handle;
}
示例10: doStart
import com.google.inject.internal.Annotations; //导入依赖的package包/类
@Override
protected void doStart() throws Exception
{
// Please do not remove
// This kludge is about ensuring these annotations are parsed to prevent
// a deadlock
Annotations.isRetainedAtRuntime(Assisted.class);
Annotations.isRetainedAtRuntime(AssistedInject.class);
Annotations.isRetainedAtRuntime(BindingAnnotation.class);
// End kludge
privatePluginService = (PrivatePluginService) AbstractPluginService.get();
getManager().getRegistry().registerListener(this);
setupBeanLocators();
}
示例11: makeProxyGuice
import com.google.inject.internal.Annotations; //导入依赖的package包/类
private static Object makeProxyGuice ( String method, Object iter, Class<?>... types ) throws Exception {
Method meth = Annotations.class.getDeclaredMethod("generateAnnotationImpl", Class.class); //$NON-NLS-1$
meth.setAccessible(true);
Object o = meth.invoke(null, Override.class);
InvocationHandler inv = Proxy.getInvocationHandler(o);
Map<String, Object> values = new HashMap<>();
values.put(method, iter);
Reflections.setFieldValue(inv, "val$members", values);
return Proxy.newProxyInstance(MockProxies.class.getClassLoader(), types, inv);
}
示例12: strategyFor
import com.google.inject.internal.Annotations; //导入依赖的package包/类
/**
* Gets the strategy for an annotation.
*/
static AnnotationStrategy strategyFor(Annotation annotation) {
checkNotNull(annotation, "annotation");
Class<? extends Annotation> annotationType = annotation
.annotationType();
ensureRetainedAtRuntime(annotationType);
ensureIsBindingAnnotation(annotationType);
if (Annotations.isMarker(annotationType)) {
return new AnnotationTypeStrategy(annotationType, annotation);
}
return new AnnotationInstanceStrategy(
Annotations.canonicalizeIfNamed(annotation));
}
示例13: Providers
import com.google.inject.internal.Annotations; //导入依赖的package包/类
Providers(@Nullable T providersInstance, Class<T> providerClass) {
this.providersInstance = providersInstance;
this.providersClass = providerClass;
this.source = StackTraceElements.forType(providersClass);
this.type = TypeToken.of(providersClass);
this.errors = new Errors(source);
this.scopeAnnotation = Annotations.findScopeAnnotation(errors, providersClass);
this.providers = introspectProviders();
}
示例14: providerFor
import com.google.inject.internal.Annotations; //导入依赖的package包/类
private EventualProvider<?> providerFor(Invokable<T, ?> method, Errors methodErrors) {
Annotation[] annotations = method.getAnnotations();
verifyMethodAccessibility(methodErrors, method, source);
@Nullable Annotation bindingAnnotation =
Annotations.findBindingAnnotation(methodErrors, method, annotations);
verifyAbsenseOfScopeAnnotation(methodErrors, annotations, source);
List<Dependency<ListenableFuture<?>>> dependencies =
Lists.newArrayListWithCapacity(method.getParameters().size());
for (Parameter parameter : method.getParameters()) {
dependencies.add(extractDependency(methodErrors, parameter));
}
Key<ListenableFuture<?>> bindingKey;
boolean exposedBinding = method.isAnnotationPresent(Exposed.class);
if (isVoid(method)) {
bindingKey = futureKey(TypeToken.of(Boolean.class), new BlackholedAnnotation());
exposedBinding = false;
} else {
bindingKey = futureKey(method.getReturnType(), bindingAnnotation);
}
return new EventualProvider<>(
method,
exposedBinding,
dependencies,
bindingKey,
scopeAnnotation,
source);
}
示例15: verifyAbsenseOfScopeAnnotation
import com.google.inject.internal.Annotations; //导入依赖的package包/类
private void verifyAbsenseOfScopeAnnotation(Errors methodErrors, Annotation[] annotations, Object source) {
@Nullable Class<? extends Annotation> methodScopeAnnotation =
Annotations.findScopeAnnotation(methodErrors, annotations);
if (methodScopeAnnotation != null) {
methodErrors.addMessage(
"Misplaced scope annotation @%s on method @%s %s."
+ "\n\tScope annotation will only be inherited from enclosing class %s",
methodScopeAnnotation.getSimpleName(),
Eventually.Provides.class.getSimpleName(),
source,
providersClass.getSimpleName());
}
}