final ResolvedType responseType = TYPE_RESOLVER .resolve(method.getInvocable().getResponseType()); final Class<?> erasedType = !responseType.getTypeBindings().isEmpty() ? responseType.getTypeBindings().getBoundType(0).getErasedType() : responseType.getErasedType();
private static boolean typeBindingsAreOfSameSize(ResolvedType toMatch, ResolvedType wildcardType) { TypeBindings wildcardTypeBindings = wildcardType.getTypeBindings(); TypeBindings bindingsToMatch = toMatch.getTypeBindings(); return bindingsToMatch.size() == wildcardTypeBindings.size(); }
private static boolean typeBindingsAreOfSameSize(ResolvedType toMatch, ResolvedType wildcardType) { TypeBindings wildcardTypeBindings = wildcardType.getTypeBindings(); TypeBindings bindingsToMatch = toMatch.getTypeBindings(); return bindingsToMatch.size() == wildcardTypeBindings.size(); }
private static boolean typeBindingsAreOfSameSize(ResolvedType toMatch, ResolvedType wildcardType) { TypeBindings wildcardTypeBindings = wildcardType.getTypeBindings(); TypeBindings bindingsToMatch = toMatch.getTypeBindings(); return bindingsToMatch.size() == wildcardTypeBindings.size(); }
@Override public ResolvedType alternateFor(ResolvedType type) { return type.getTypeBindings().getBoundType(boundTypeIndex); }
@Override public boolean appliesTo(ResolvedType type) { return type.getErasedType() == genericType && !type.getTypeBindings().isEmpty() && boundTypeIndex <= type.getTypeBindings().size() - 1; }
public static boolean hasWildcards(ResolvedType type) { return any(type.getTypeBindings().getTypeParameters(), thatAreWildcards()); }
public static boolean hasWildcards(ResolvedType type) { return any(type.getTypeBindings().getTypeParameters(), thatAreWildcards()); }
public static boolean hasWildcards(ResolvedType type) { return any(type.getTypeBindings().getTypeParameters(), thatAreWildcards()); }
/** * Factory method for resolving given generic type, defined by using sub-class * instance of {@link GenericType} */ private ResolvedType _fromGenericType(ClassStack context, GenericType<?> generic, TypeBindings typeBindings) { /* To allow multiple levels of inheritance (just in case someone * wants to go to town with inheritance of GenericType), * we better resolve the whole thing; then dig out * type parameterization... */ ResolvedType type = _fromClass(context, generic.getClass(), typeBindings); ResolvedType genType = type.findSupertype(GenericType.class); if (genType == null) { // sanity check; shouldn't occur throw new IllegalArgumentException("Unparameterized GenericType instance ("+generic.getClass().getName()+")"); } TypeBindings b = genType.getTypeBindings(); ResolvedType[] params = b.typeParameterArray(); if (params.length == 0) { throw new IllegalArgumentException("Unparameterized GenericType instance ("+generic.getClass().getName()+")"); } return params[0]; }
/** * Factory method for resolving given generic type, defined by using sub-class * instance of {@link GenericType} */ private ResolvedType _fromGenericType(ClassStack context, GenericType<?> generic, TypeBindings typeBindings) { /* To allow multiple levels of inheritance (just in case someone * wants to go to town with inheritance of GenericType), * we better resolve the whole thing; then dig out * type parameterization... */ ResolvedType type = _fromClass(context, generic.getClass(), typeBindings); ResolvedType genType = type.findSupertype(GenericType.class); if (genType == null) { // sanity check; shouldn't occur throw new IllegalArgumentException("Unparameterized GenericType instance ("+generic.getClass().getName()+")"); } TypeBindings b = genType.getTypeBindings(); ResolvedType[] params = b.typeParameterArray(); if (params.length == 0) { throw new IllegalArgumentException("Unparameterized GenericType instance ("+generic.getClass().getName()+")"); } return params[0]; }
private static List<ResolvedType> breadthFirstSearch(ResolvedType replacingType, ResolvedType wildcardType) { TypeBindings wildcardTypeBindings = wildcardType.getTypeBindings(); TypeBindings bindingsToMatch = replacingType.getTypeBindings(); Preconditions.checkArgument(typeBindingsAreOfSameSize(wildcardType, replacingType)); List<ResolvedType> bindings = newArrayList(); for (int index = 0; index < bindingsToMatch.size(); index++) { if (WildcardType.class.equals(wildcardTypeBindings.getBoundType(index).getErasedType())) { bindings.add(bindingsToMatch.getBoundType(index)); } else { bindings.addAll(breadthFirstSearch(bindingsToMatch.getBoundType(index), wildcardTypeBindings.getBoundType(index))); } } return bindings; } }
private static List<ResolvedType> breadthFirstSearch(ResolvedType replacingType, ResolvedType wildcardType) { TypeBindings wildcardTypeBindings = wildcardType.getTypeBindings(); TypeBindings bindingsToMatch = replacingType.getTypeBindings(); Preconditions.checkArgument(typeBindingsAreOfSameSize(wildcardType, replacingType)); List<ResolvedType> bindings = newArrayList(); for(int index = 0; index < bindingsToMatch.size(); index++) { if (WildcardType.class.equals(wildcardTypeBindings.getBoundType(index).getErasedType())) { bindings.add(bindingsToMatch.getBoundType(index)); } else { bindings.addAll(breadthFirstSearch(bindingsToMatch.getBoundType(index), wildcardTypeBindings.getBoundType(index))); } } return bindings; } }
private static List<ResolvedType> breadthFirstSearch(ResolvedType replacingType, ResolvedType wildcardType) { TypeBindings wildcardTypeBindings = wildcardType.getTypeBindings(); TypeBindings bindingsToMatch = replacingType.getTypeBindings(); //TODO - this fails when a controller method return type is a non paramaterized ResponseEntity Preconditions.checkArgument(typeBindingsAreOfSameSize(wildcardType, replacingType)); List<ResolvedType> bindings = newArrayList(); for (int index = 0; index < bindingsToMatch.size(); index++) { if (isWildcardType(wildcardTypeBindings.getBoundType(index))) { bindings.add(bindingsToMatch.getBoundType(index)); } else { bindings.addAll(breadthFirstSearch(bindingsToMatch.getBoundType(index), wildcardTypeBindings.getBoundType(index))); } } return bindings; } }
public static boolean wildcardMatch(ResolvedType toMatch, ResolvedType wildcardType) { if (!toMatch.getErasedType().equals(wildcardType.getErasedType())) { return false; } TypeBindings wildcardTypeBindings = wildcardType.getTypeBindings(); TypeBindings bindingsToMatch = toMatch.getTypeBindings(); for (int index = 0; index < bindingsToMatch.size(); index++) { ResolvedType wildcardTypeBindingsBoundType = wildcardTypeBindings.getBoundType(index); ResolvedType bindingsToMatchBoundType = bindingsToMatch.getBoundType(index); if (!wildcardTypeBindingsBoundType.getErasedType().equals(WildcardType.class) && !wildcardMatch(bindingsToMatchBoundType, wildcardTypeBindingsBoundType)) { return false; } } return true; }
public static boolean wildcardMatch(ResolvedType toMatch, ResolvedType wildcardType) { if (!toMatch.getErasedType().equals(wildcardType.getErasedType())) { return false; } if (!typeBindingsAreOfSameSize(wildcardType, toMatch)) { return false; } TypeBindings wildcardTypeBindings = wildcardType.getTypeBindings(); TypeBindings bindingsToMatch = toMatch.getTypeBindings(); for (int index = 0; index < bindingsToMatch.size(); index++) { ResolvedType wildcardTypeBindingsBoundType = wildcardTypeBindings.getBoundType(index); ResolvedType bindingsToMatchBoundType = bindingsToMatch.getBoundType(index); if (!wildcardTypeBindingsBoundType.getErasedType().equals(WildcardType.class) && !wildcardMatch(bindingsToMatchBoundType, wildcardTypeBindingsBoundType)) { return false; } } return true; }
public static boolean wildcardMatch(ResolvedType toMatch, ResolvedType wildcardType) { if (!toMatch.getErasedType().equals(wildcardType.getErasedType())) { return false; } if (!typeBindingsAreOfSameSize(wildcardType, toMatch)) { return false; } TypeBindings wildcardTypeBindings = wildcardType.getTypeBindings(); TypeBindings bindingsToMatch = toMatch.getTypeBindings(); for(int index = 0; index < bindingsToMatch.size(); index++) { ResolvedType wildcardTypeBindingsBoundType = wildcardTypeBindings.getBoundType(index); ResolvedType bindingsToMatchBoundType = bindingsToMatch.getBoundType(index); if (!wildcardTypeBindingsBoundType.getErasedType().equals(WildcardType.class) && !wildcardMatch(bindingsToMatchBoundType, wildcardTypeBindingsBoundType)) { return false; } } return true; }
/** * Method for resolving individual field completely */ protected ResolvedField resolveField(RawField raw) { final ResolvedType context = raw.getDeclaringType(); Field field = raw.getRawMember(); ResolvedType type = _typeResolver.resolve(context.getTypeBindings(), field.getGenericType()); // And then annotations Annotations anns = new Annotations(); for (Annotation ann : field.getAnnotations()) { if (_annotationHandler.includeFieldAnnotation(ann)) { anns.add(ann); } } return new ResolvedField(context, anns, field, type); }
/** * Method for resolving individual field completely */ protected ResolvedField resolveField(RawField raw) { final ResolvedType context = raw.getDeclaringType(); Field field = raw.getRawMember(); ResolvedType type = _typeResolver.resolve(context.getTypeBindings(), field.getGenericType()); // And then annotations Annotations anns = new Annotations(); for (Annotation ann : field.getAnnotations()) { if (_annotationHandler.includeFieldAnnotation(ann)) { anns.add(ann); } } return new ResolvedField(context, anns, field, type); }
public SingleValueResultReturnThing(ResolvedMethod method) { if (method.getRawMember().isAnnotationPresent(SingleValueResult.class)) { SingleValueResult svr = method.getRawMember().getAnnotation(SingleValueResult.class); // try to guess generic type if(SingleValueResult.Default.class == svr.value()){ TypeBindings typeBindings = method.getReturnType().getTypeBindings(); if(typeBindings.size() == 1){ this.returnType = typeBindings.getBoundType(0).getErasedType(); }else{ throw new IllegalArgumentException("Ambiguous generic information. SingleValueResult type could not be fetched."); } }else{ this.returnType = svr.value(); } this.containerType = method.getReturnType().getErasedType(); } else { this.returnType = method.getReturnType().getErasedType(); this.containerType = null; } }