Signature(TypeLiteral<?> typeLiteral, Method method) { this.name = method.getName(); // We need to 'resolve' the parameters against the actual class type in case this method uses // type parameters. This is so we can detect overrides of generic superclass methods where // the subclass specifies the type parameter. javac implements these kinds of overrides via // bridge methods, but we don't want to give errors on bridge methods (but rather the target // of the bridge). List<TypeLiteral<?>> resolvedParameterTypes = typeLiteral.getParameterTypes(method); this.parameters = new Class<?>[resolvedParameterTypes.size()]; int i = 0; for (TypeLiteral<?> type : resolvedParameterTypes) { parameters[i] = type.getRawType(); } this.hashCode = name.hashCode() + 31 * Arrays.hashCode(parameters); }
private ImmutableList<Dependency<?>> forMember( Member member, TypeLiteral<?> type, Annotation[][] paramterAnnotations) { Errors errors = new Errors(member); List<Dependency<?>> dependencies = Lists.newArrayList(); int index = 0; for (TypeLiteral<?> parameterType : type.getParameterTypes(member)) { try { Annotation[] parameterAnnotations = paramterAnnotations[index]; Key<?> key = Annotations.getKey(parameterType, member, parameterAnnotations, errors); dependencies.add(newDependency(key, Nullability.allowsNull(parameterAnnotations), index)); index++; } catch (ConfigurationException e) { errors.merge(e.getErrorMessages()); } catch (ErrorsException e) { errors.merge(e.getErrors()); } } errors.throwConfigurationExceptionIfErrorsExist(); return ImmutableList.copyOf(dependencies); }
protected Class<?> getParameterType(TypeLiteral<?> type, Method method, int i) { Class<?>[] parameterTypes = method.getParameterTypes(); List<TypeLiteral<?>> list = type.getParameterTypes(method); TypeLiteral<?> typeLiteral = list.get(i); Class<?> paramType = typeLiteral.getRawType(); if (paramType == Object.class || paramType.isArray() && paramType.getComponentType() == Object.class) { // if the TypeLiteral ninja doesn't work, lets fall back to the actual type paramType = parameterTypes[i]; } return paramType; }
Signature(TypeLiteral<?> typeLiteral, Method method) { this.name = method.getName(); // We need to 'resolve' the parameters against the actual class type in case this method uses // type parameters. This is so we can detect overrides of generic superclass methods where // the subclass specifies the type parameter. javac implements these kinds of overrides via // bridge methods, but we don't want to give errors on bridge methods (but rather the target // of the bridge). List<TypeLiteral<?>> resolvedParameterTypes = typeLiteral.getParameterTypes(method); this.parameters = new Class<?>[resolvedParameterTypes.size()]; int i = 0; for (TypeLiteral<?> type : resolvedParameterTypes) { parameters[i] = type.getRawType(); } this.hashCode = name.hashCode() + 31 * Arrays.hashCode(parameters); }
Signature(TypeLiteral<?> typeLiteral, Method method) { this.name = method.getName(); // We need to 'resolve' the parameters against the actual class type in case this method uses // type parameters. This is so we can detect overrides of generic superclass methods where // the subclass specifies the type parameter. javac implements these kinds of overrides via // bridge methods, but we don't want to give errors on bridge methods (but rather the target // of the bridge). List<TypeLiteral<?>> resolvedParameterTypes = typeLiteral.getParameterTypes(method); this.parameters = new Class<?>[resolvedParameterTypes.size()]; int i = 0; for (TypeLiteral<?> type : resolvedParameterTypes) { parameters[i] = type.getRawType(); } this.hashCode = name.hashCode() + 31 * Arrays.hashCode(parameters); }
Signature(Method method) { this.name = method.getName(); // We need to 'resolve' the parameters against the actual class type in case this method uses // type parameters. This is so we can detect overrides of generic superclass methods where // the subclass specifies the type parameter. javac implements these kinds of overrides via // bridge methods, but we don't want to give errors on bridge methods (but rather the target // of the bridge). List<TypeLiteral<?>> resolvedParameterTypes = typeLiteral.getParameterTypes(method); this.parameters = new Class<?>[resolvedParameterTypes.size()]; int i = 0; for (TypeLiteral<?> type : resolvedParameterTypes) { parameters[i] = type.getRawType(); } this.hashCode = name.hashCode() + 31 * Arrays.hashCode(parameters); }
public static List<Key<?>> getParameterKeys(TypeLiteral<?> type, Method method) { Annotation[][] parameterAnnotations = method.getParameterAnnotations(); List<TypeLiteral<?>> parameterTypes = type.getParameterTypes(method); List<Key<?>> keys = new ArrayList<Key<?>>(parameterTypes.size()); for (int i = 0; i < parameterTypes.size(); i++) keys.add(buildKey(parameterTypes.get(i), parameterAnnotations[i])); return keys; }
public static List<Key<?>> getParameterKeys(TypeLiteral<?> type, Method method) { Annotation[][] parameterAnnotations = method.getParameterAnnotations(); List<TypeLiteral<?>> parameterTypes = type.getParameterTypes(method); List<Key<?>> keys = new ArrayList<Key<?>>(parameterTypes.size()); for (int i = 0; i < parameterTypes.size(); i++) keys.add(buildKey(parameterTypes.get(i), parameterAnnotations[i])); return keys; }
public static List<Key<?>> getParameterKeys(TypeLiteral<?> type, Method method) { Annotation[][] parameterAnnotations = method.getParameterAnnotations(); List<TypeLiteral<?>> parameterTypes = type.getParameterTypes(method); List<Key<?>> keys = new ArrayList<Key<?>>(parameterTypes.size()); for (int i = 0; i < parameterTypes.size(); i++) keys.add(buildKey(parameterTypes.get(i), parameterAnnotations[i])); return keys; }
/** The default method to create a value for the named member of the requested type */ protected abstract Object provide(A annotation, Member member, TypeLiteral<?> requiredType, Class<?> memberType, Annotation[] annotations); }
/** * Returns this method's parameter types, if appropriate parametrized with * the declaring class's type parameters. * * @return parameter types */ public List<TypeLiteral<?>> getParameterTypes() { if (parameterTypes == null) { parameterTypes = getDeclaringType().getParameterTypes(getMember()); } return parameterTypes; }
/** * Matching logic for {@literal @}{@link Inject} constructor and method * parameters. * * This returns true if all assisted parameters required by the constructor * are provided by the factory method. */ private boolean injectConstructorHasMatchingParams(TypeLiteral<?> type, Constructor<?> constructor, List<Key<?>> paramList, Errors errors) throws ErrorsException { List<TypeLiteral<?>> params = type.getParameterTypes(constructor); Annotation[][] paramAnnotations = constructor.getParameterAnnotations(); int p = 0; for (TypeLiteral<?> param : params) { Key<?> paramKey = getKey(param, constructor, paramAnnotations[p++], errors); if(paramKey.getAnnotationType() == Assisted.class && !paramList.contains(paramKey)) { return false; } } return true; }
public static List<Key<?>> getMethodKeys(Method method, Errors errors) { Annotation allParameterAnnotations[][] = method.getParameterAnnotations(); List<Key<?>> result = new ArrayList<Key<?>>(allParameterAnnotations.length); Iterator<Annotation[]> annotationsIterator = Arrays.asList(allParameterAnnotations).iterator(); TypeLiteral<?> type = TypeLiteral.get(method.getDeclaringClass()); for (TypeLiteral<?> parameterType : type.getParameterTypes(method)) { try { Annotation[] parameterAnnotations = annotationsIterator.next(); result.add(Annotations.getKey(parameterType, method, parameterAnnotations, errors)); } catch (ConfigurationException e) { errors.merge(e.getErrorMessages()); } catch (ErrorsException e) { errors.merge(e.getErrors()); } } return result; } }
public static List<Key<?>> getMethodKeys(Method method, Errors errors) { Annotation allParameterAnnotations[][] = method.getParameterAnnotations(); List<Key<?>> result = new ArrayList<Key<?>>(allParameterAnnotations.length); Iterator<Annotation[]> annotationsIterator = Arrays.asList(allParameterAnnotations).iterator(); TypeLiteral<?> type = TypeLiteral.get(method.getDeclaringClass()); for (TypeLiteral<?> parameterType : type.getParameterTypes(method)) { try { Annotation[] parameterAnnotations = annotationsIterator.next(); result.add(Annotations.getKey(parameterType, method, parameterAnnotations, errors)); } catch (ConfigurationException e) { errors.merge(e.getErrorMessages()); } catch (ErrorsException e) { errors.merge(e.getErrors()); } } return result; } }
private ImmutableList<Dependency<?>> forMember(Member member, TypeLiteral<?> type, Annotation[][] paramterAnnotations) { Errors errors = new Errors(member); Iterator<Annotation[]> annotationsIterator = Arrays.asList(paramterAnnotations).iterator(); List<Dependency<?>> dependencies = Lists.newArrayList(); int index = 0; for (TypeLiteral<?> parameterType : type.getParameterTypes(member)) { try { Annotation[] parameterAnnotations = annotationsIterator.next(); Key<?> key = Annotations.getKey(parameterType, member, parameterAnnotations, errors); dependencies.add(newDependency(key, Nullability.allowsNull(parameterAnnotations), index)); index++; } catch (ConfigurationException e) { errors.merge(e.getErrorMessages()); } catch (ErrorsException e) { errors.merge(e.getErrors()); } } errors.throwConfigurationExceptionIfErrorsExist(); return ImmutableList.copyOf(dependencies); }
private ImmutableList<Dependency<?>> forMember( Member member, TypeLiteral<?> type, Annotation[][] paramterAnnotations) { Errors errors = new Errors(member); List<Dependency<?>> dependencies = Lists.newArrayList(); int index = 0; for (TypeLiteral<?> parameterType : type.getParameterTypes(member)) { try { Annotation[] parameterAnnotations = paramterAnnotations[index]; Key<?> key = Annotations.getKey(parameterType, member, parameterAnnotations, errors); dependencies.add(newDependency(key, Nullability.allowsNull(parameterAnnotations), index)); index++; } catch (ConfigurationException e) { errors.merge(e.getErrorMessages()); } catch (ErrorsException e) { errors.merge(e.getErrors()); } } errors.throwConfigurationExceptionIfErrorsExist(); return ImmutableList.copyOf(dependencies); }
private ImmutableList<Dependency<?>> forMember( Member member, TypeLiteral<?> type, Annotation[][] paramterAnnotations) { Errors errors = new Errors(member); List<Dependency<?>> dependencies = Lists.newArrayList(); int index = 0; for (TypeLiteral<?> parameterType : type.getParameterTypes(member)) { try { Annotation[] parameterAnnotations = paramterAnnotations[index]; Key<?> key = Annotations.getKey(parameterType, member, parameterAnnotations, errors); dependencies.add(newDependency(key, Nullability.allowsNull(parameterAnnotations), index)); index++; } catch (ConfigurationException e) { errors.merge(e.getErrorMessages()); } catch (ErrorsException e) { errors.merge(e.getErrors()); } } errors.throwConfigurationExceptionIfErrorsExist(); return ImmutableList.copyOf(dependencies); }
private ImmutableList<Dependency<?>> forMember(Member member, TypeLiteral<?> type, Annotation[][] paramterAnnotations) { Errors errors = new Errors(member); Iterator<Annotation[]> annotationsIterator = Arrays.asList(paramterAnnotations).iterator(); List<Dependency<?>> dependencies = Lists.newArrayList(); int index = 0; for (TypeLiteral<?> parameterType : type.getParameterTypes(member)) { try { Annotation[] parameterAnnotations = annotationsIterator.next(); Key<?> key = Annotations.getKey(parameterType, member, parameterAnnotations, errors); dependencies.add(newDependency(key, Nullability.allowsNull(parameterAnnotations), index)); index++; } catch (ConfigurationException e) { errors.merge(e.getErrorMessages()); } catch (ErrorsException e) { errors.merge(e.getErrors()); } } errors.throwConfigurationExceptionIfErrorsExist(); return ImmutableList.copyOf(dependencies); }
private ImmutableList<Dependency<?>> forMember(Member member, TypeLiteral<?> type, Annotation[][] paramterAnnotations) { Errors errors = new Errors(member); Iterator<Annotation[]> annotationsIterator = Arrays.asList(paramterAnnotations).iterator(); List<Dependency<?>> dependencies = Lists.newArrayList(); int index = 0; for (TypeLiteral<?> parameterType : type.getParameterTypes(member)) { try { Annotation[] parameterAnnotations = annotationsIterator.next(); Key<?> key = Annotations.getKey(parameterType, member, parameterAnnotations, errors); dependencies.add(newDependency(key, Nullability.allowsNull(parameterAnnotations), index)); index++; } catch (ConfigurationException e) { errors.merge(e.getErrorMessages()); } catch (ErrorsException e) { errors.merge(e.getErrors()); } } errors.throwConfigurationExceptionIfErrorsExist(); return ImmutableList.copyOf(dependencies); }
private Key<?> getKey(ParameterInfo parameter) { try { // Get TypeLiteral for this parameter TypeLiteral<?> declaringType = TypeLiteral.get(parameter.getDeclaringClass()); List<TypeLiteral<?>> parameterTypes = declaringType.getParameterTypes(parameter.getConstructor()); TypeLiteral<?> parameterType = parameterTypes.get(parameter.getParameterIndex()); // Create Key object for this parameter Errors errors = new Errors(parameter.getConstructor()); return Annotations.getKey( parameterType, parameter.getConstructor(), parameter.getParameterAnnotations(), errors); } catch (ErrorsException e) { throw new MgnlInstantiationException(e.getMessage(), e); } } }