@Override protected List<LightweightTypeReference> getSuperTypes(TypeParameterSubstitutor<?> substitutor) { if (isUnbounded()) { return Collections.singletonList(getUpperBoundSubstitute()); } List<LightweightTypeReference> nonNullUpperBounds = expose(getUpperBounds()); List<LightweightTypeReference> result = Lists.newArrayListWithCapacity(nonNullUpperBounds.size()); for(LightweightTypeReference upperBound: nonNullUpperBounds) { result.add(substitutor.substitute(upperBound)); } return result; }
@Override protected List<JvmType> doVisitWildcardTypeReference(WildcardTypeReference reference, ResourceSet resourceSet) { if (reference.isUnbounded()) { return createObjectReference(resourceSet); } List<LightweightTypeReference> upperBounds = reference.getUpperBounds(); if (upperBounds.isEmpty()) { throw new IllegalStateException("UpperBounds may not be empty"); } return collectRawTypes(upperBounds, resourceSet); }
@Override protected Boolean doVisitParameterizedTypeReference(ParameterizedTypeReference reference) { for(LightweightTypeReference argument: reference.getTypeArguments()) { if (argument.isWildcard()) { if (!((WildcardTypeReference)argument).isUnbounded()) { return Boolean.TRUE; } } else { return Boolean.TRUE; } } return Boolean.FALSE; }
@Override /* @Nullable */ public LightweightTypeReference getSuperType(Class<?> rawType) { if (isUnbounded()) { if (Object.class.equals(rawType)) { return internalFindTopLevelType(rawType); } return null; } List<LightweightTypeReference> nonNullUpperBounds = expose(getUpperBounds()); for(LightweightTypeReference upperBound: nonNullUpperBounds) { LightweightTypeReference result = upperBound.getSuperType(rawType); if (result != null) return result; } return null; }
@Override public LightweightTypeReference getUpperBoundSubstitute() { if (isUnbounded()) { return getOwner().newReferenceToObject(); } List<LightweightTypeReference> upperBounds = getUpperBounds(); if (upperBounds.size() == 1) { LightweightTypeReference result = upperBounds.get(0); return result; } CompoundTypeReference result = getOwner().newCompoundTypeReference(false); for(LightweightTypeReference upperBound: upperBounds) { result.addComponent(upperBound); } return result; }
@Override /* @Nullable */ public LightweightTypeReference getSuperType(JvmType rawType) { if (isUnbounded()) { if (Object.class.getName().equals(rawType.getIdentifier())) { return getOwner().newParameterizedTypeReference(rawType); } return null; } List<LightweightTypeReference> nonNullUpperBounds = expose(getUpperBounds()); for(LightweightTypeReference upperBound: nonNullUpperBounds) { LightweightTypeReference result = upperBound.getSuperType(rawType); if (result != null) return result; } return null; }
@Override protected LightweightTypeReference doVisitWildcardTypeReference(WildcardTypeReference reference, ResourceSet resourceSet) { if (reference.isUnbounded()) { return reference.getUpperBoundSubstitute(); } if (reference.getUpperBounds().size() == 1) { return reference.getUpperBoundSubstitute().accept(this, resourceSet); } CompoundTypeReference result = reference.getOwner().newCompoundTypeReference(false); enhanceCompoundReference(reference.getUpperBounds(), result, resourceSet); return result; }