@Override public boolean equals(Object o) { if (o == this) return true; if (o == null || o.getClass() != getClass()) return false; TypeBindings other = (TypeBindings) o; int len = _types.length; if (len != other.size()) { return false; } ResolvedType[] otherTypes = other._types; for (int i = 0; i < len; ++i) { if (!otherTypes[i].equals(_types[i])) { return false; } } return true; }
@Override public boolean equals(Object o) { if (o == this) return true; if (o == null || o.getClass() != getClass()) return false; TypeBindings other = (TypeBindings) o; int len = _types.length; if (len != other.size()) { return false; } ResolvedType[] otherTypes = other._types; for (int i = 0; i < len; ++i) { if (!otherTypes[i].equals(_types[i])) { return false; } } return true; }
protected StringBuilder _appendClassDescription(StringBuilder sb) { sb.append(_erasedType.getName()); int count = _typeBindings.size(); if (count > 0) { sb.append('<'); for (int i = 0; i < count; ++i) { if (i > 0) { sb.append(','); } sb = _typeBindings.getBoundType(i).appendBriefDescription(sb); } sb.append('>'); } return sb; }
protected StringBuilder _appendClassDescription(StringBuilder sb) { sb.append(_erasedType.getName()); int count = _typeBindings.size(); if (count > 0) { sb.append('<'); for (int i = 0; i < count; ++i) { if (i > 0) { sb.append(','); } sb = _typeBindings.getBoundType(i).appendBriefDescription(sb); } sb.append('>'); } return sb; }
protected StringBuilder _appendClassSignature(StringBuilder sb) { sb.append('L'); sb = _appendClassName(sb); int count = _typeBindings.size(); if (count > 0) { sb.append('<'); for (int i = 0; i < count; ++i) { sb = _typeBindings.getBoundType(i).appendErasedSignature(sb); } sb.append('>'); } sb.append(';'); return sb; }
protected StringBuilder _appendClassSignature(StringBuilder sb) { sb.append('L'); sb = _appendClassName(sb); int count = _typeBindings.size(); if (count > 0) { sb.append('<'); for (int i = 0; i < count; ++i) { sb = _typeBindings.getBoundType(i).appendErasedSignature(sb); } sb.append('>'); } sb.append(';'); return sb; }
private static ResolvedType breadthFirstReplace(Iterator<ResolvedType> replaceableIterator, ResolvedType wildcardType) { if (WildcardType.class.equals(wildcardType.getErasedType())) { if (replaceableIterator.hasNext()) { return replaceableIterator.next(); } else { throw new IllegalStateException("Expecting the same number of wildcard types as the replaceables"); } } TypeBindings wildcardTypeBindings = wildcardType.getTypeBindings(); List<Type> bindings = newArrayList(); for(int index = 0; index < wildcardTypeBindings.size(); index++) { if (WildcardType.class.equals(wildcardTypeBindings.getBoundType(index).getErasedType())) { if (replaceableIterator.hasNext()) { bindings.add(replaceableIterator.next()); } else { throw new IllegalStateException("Count of wildcards to candidates do not match"); } } else { bindings.add(breadthFirstReplace(replaceableIterator, wildcardTypeBindings.getBoundType(index))); } } return new TypeResolver().resolve(wildcardType.getErasedType(), toArray(bindings, Type.class)); }
private static ResolvedType breadthFirstReplace(Iterator<ResolvedType> replaceableIterator, ResolvedType wildcardType) { if (WildcardType.class.equals(wildcardType.getErasedType())) { if (replaceableIterator.hasNext()) { return replaceableIterator.next(); } else { throw new IllegalStateException("Expecting the same number of wildcard types as the replaceables"); } } TypeBindings wildcardTypeBindings = wildcardType.getTypeBindings(); List<Type> bindings = newArrayList(); for (int index = 0; index < wildcardTypeBindings.size(); index++) { if (WildcardType.class.equals(wildcardTypeBindings.getBoundType(index).getErasedType())) { if (replaceableIterator.hasNext()) { bindings.add(replaceableIterator.next()); } else { throw new IllegalStateException("Count of wildcards to candidates do not match"); } } else { bindings.add(breadthFirstReplace(replaceableIterator, wildcardTypeBindings.getBoundType(index))); } } return new TypeResolver().resolve(wildcardType.getErasedType(), toArray(bindings, Type.class)); }
private static ResolvedType breadthFirstReplace(Iterator<ResolvedType> replaceableIterator, ResolvedType wildcardType) { if (isWildcardType(wildcardType)) { if (replaceableIterator.hasNext()) { return replaceableIterator.next(); } else { throw new IllegalStateException("Expecting the same number of wildcard types as the replaceables"); } } TypeBindings wildcardTypeBindings = wildcardType.getTypeBindings(); List<Type> bindings = newArrayList(); for (int index = 0; index < wildcardTypeBindings.size(); index++) { if (isWildcardType(wildcardTypeBindings.getBoundType(index))) { if (replaceableIterator.hasNext()) { bindings.add(replaceableIterator.next()); } else { throw new IllegalStateException("Count of wildcards to candidates do not match"); } } else { bindings.add(breadthFirstReplace(replaceableIterator, wildcardTypeBindings.getBoundType(index))); } } return new TypeResolver().resolve(wildcardType.getErasedType(), toArray(bindings, Type.class)); }
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; } }
@Override public boolean appliesTo(ResolvedType type) { return type.getErasedType() == genericType && !type.getTypeBindings().isEmpty() && boundTypeIndex <= type.getTypeBindings().size() - 1; }
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; }
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; } }