com.google.inject.internal.Annotations Java Examples

The following examples show how to use com.google.inject.internal.Annotations. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: InjectableMethod.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
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;
}
 
Example #2
Source File: MockProxies.java    From marshalsec with MIT License 5 votes vote down vote up
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);
}
 
Example #3
Source File: Injection.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
public static Optional<Class<? extends Annotation>> scopeAnnotation(Class<?> type) {
    return Optional.ofNullable(Annotations.findScopeAnnotation(new Errors(), type));
}
 
Example #4
Source File: Keys.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
public static Key<?> fieldType(TypeLiteral<?> owner, Field field, Errors errors) throws ErrorsException {
    return Annotations.getKey(owner.getFieldType(field), field, field.getAnnotations(), errors);
}
 
Example #5
Source File: Keys.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
public static <T> Key<T> returnType(Invokable<?, T> method, Errors errors) throws ErrorsException {
    return (Key<T>) Annotations.getKey(Types.toLiteral(method.getReturnType()), method, method.getAnnotations(), errors);
}
 
Example #6
Source File: Keys.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
public static <T> Key<T> returnType(TypeLiteral<?> decl, Method method, Errors errors) throws ErrorsException {
    return (Key<T>) Annotations.getKey(decl.getReturnType(method), method, method.getAnnotations(), errors);
}
 
Example #7
Source File: AbstractBindingBuilder.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public LinkedBindingBuilder<T> annotatedWith(Class<? extends Annotation> annotationType) {
    return annotatedWith(Annotations.generateAnnotation(annotationType));
}
 
Example #8
Source File: ConfigImpl.java    From dropwizard-guicey with MIT License 4 votes vote down vote up
@Override
public String toString() {
    return "@" + Config.class.getName() + "(value=" + Annotations.memberValueString(val) + ")";
}