} else if (functionType.getParameterTypes().contains(parameterReference)) { WildcardTypeReference wildcard = owner.newWildcardExtendsObject(); wildcard.setLowerBound(parameterReference); parameterReferences.add(wildcard); } else {
return mostSpecialTypeIfAllWildcards; WildcardTypeReference result = owner.newWildcardExtendsObject(); result.setLowerBound(mostSpecialTypeIfAllWildcards); return result;
@Override protected LocalTypeSubstitutor.SubstitutionResult doVisitWildcardTypeReference(WildcardTypeReference reference, VarianceInfo varianceInfo) { WildcardTypeReference result = owner.newWildcardTypeReference(); LightweightTypeReference lowerBound = reference.getLowerBound(); boolean didSubstitute = false; if (lowerBound != null) { SubstitutionResult visited = lowerBound.accept(this, VarianceInfo.IN); result.setLowerBound(visited.typeReference); didSubstitute = didSubstitute || visited.didSubstitute; } for(LightweightTypeReference upperBound: reference.getUpperBounds()) { SubstitutionResult visited = upperBound.accept(this, VarianceInfo.OUT); result.addUpperBound(visited.typeReference); didSubstitute = didSubstitute || visited.didSubstitute; } if (result.getUpperBounds().isEmpty()) { throw new IllegalStateException("UpperBounds may not be empty"); } return new SubstitutionResult(result, didSubstitute); }
@Override protected LightweightTypeReference doVisitWildcardTypeReference(WildcardTypeReference reference, Set<JvmTypeParameter> visiting) { if (reference.isResolved() && reference.isOwnedBy(getOwner())) return reference; WildcardTypeReference result = getOwner().newWildcardTypeReference(); LightweightTypeReference lowerBound = reference.getLowerBound(); if (lowerBound != null) { LightweightTypeReference visited = visitTypeArgument(lowerBound, visiting, true); if (visited.isWildcard()) { LightweightTypeReference substitute = visited.getInvariantBoundSubstitute(); result.setLowerBound(substitute); } else { result.setLowerBound(visited); } } for(LightweightTypeReference upperBound: reference.getUpperBounds()) { LightweightTypeReference visitedArgument = visitTypeArgument(upperBound, visiting); LightweightTypeReference upperBoundSubstitute = visitedArgument.getUpperBoundSubstitute(); result.addUpperBound(upperBoundSubstitute); } if (result.getUpperBounds().isEmpty()) { throw new IllegalStateException("UpperBounds may not be empty"); } return result; } };
/** * Creates a new wildcard type reference with the given type as the lower bound and {@link Object} as upper bound. * * For example: * <pre>wildcardSuper(typeRef(CharSequence))</pre> * would create a type reference representing * <pre>? super CharSequence</pre> * * @param superBound * the super bound of the wildcard * @return the newly created wildcard type reference */ public JvmTypeReference wildcardSuper(JvmTypeReference superBound) { WildcardTypeReference wildcardTypeReference = typeReferenceOwner.newWildcardTypeReference(); wildcardTypeReference.addUpperBound(typeReferenceOwner.toLightweightTypeReference(typeRef(Object.class))); wildcardTypeReference.setLowerBound(typeReferenceOwner.toLightweightTypeReference(superBound)); return wildcardTypeReference.toTypeReference(); }
@Override protected WildcardTypeReference doCopyInto(ITypeReferenceOwner owner) { WildcardTypeReference result = owner.newWildcardTypeReference(); if (upperBounds != null && !upperBounds.isEmpty()) { for(LightweightTypeReference upperBound: upperBounds) { LightweightTypeReference copiedUpperBound = upperBound.copyInto(owner).getInvariantBoundSubstitute(); if (!(copiedUpperBound.isPrimitive() || copiedUpperBound.isPrimitiveVoid())) { result.addUpperBound(copiedUpperBound); } } } if (lowerBound != null) { LightweightTypeReference copiedLowerBound = lowerBound.copyInto(owner).getInvariantBoundSubstitute(); if (!(copiedLowerBound.isPrimitive() || copiedLowerBound.isPrimitiveVoid())) { result.setLowerBound(copiedLowerBound); } } return result; }
return result; } else { result.setLowerBound(lowerBoundSubstitute); result.setLowerBound(visited.copyInto(result.getOwner()));
result.addUpperBound(visit(constraint.getTypeReference()).getWrapperTypeIfPrimitive()); } else if (result.getLowerBound() == null) { result.setLowerBound(visit(constraint.getTypeReference()).getWrapperTypeIfPrimitive());
WildcardTypeReference wildcard = getOwner().newWildcardTypeReference(); wildcard.addUpperBound(getObjectReference()); wildcard.setLowerBound(result.getInvariantBoundSubstitute()); result = wildcard;
result.addParameterType(parameterType); final WildcardTypeReference typeArgument = this.getOwner().newWildcardTypeReference(); typeArgument.setLowerBound(parameterType); typeArgument.addUpperBound(this.getJavaLangObjectTypeReference()); result.addTypeArgument(typeArgument);