@Override public LightweightTypeReference getLowerBoundSubstitute() { if (lowerBound != null) return lowerBound; return getOwner().newAnyTypeReference(); }
public void addUpperBound(LightweightTypeReference upperBound) { if (upperBound == null) { throw new NullPointerException("upperBound may not be null"); } if (!upperBound.isOwnedBy(getOwner())) { throw new IllegalArgumentException("upperBound is not valid in current context"); } if (upperBound instanceof WildcardTypeReference) { throw new IllegalArgumentException("Wildcards are not supported as upper bounds"); } if (upperBound.isPrimitive() || upperBound.isPrimitiveVoid()) { throw new IllegalArgumentException("Constraints may not be primitives"); } if (upperBounds == null) upperBounds = Lists.newArrayListWithCapacity(2); upperBounds.add(upperBound); resolved = resolved && upperBound.isResolved(); }
@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; }
public void setLowerBound(LightweightTypeReference lowerBound) { if (lowerBound == null) { throw new NullPointerException("lowerBound may not be null"); } if (!lowerBound.isOwnedBy(getOwner())) { throw new IllegalArgumentException("lowerBound is not valid in current context"); } if (lowerBound instanceof WildcardTypeReference) { throw new IllegalArgumentException("Wildcards are not supported as lower bounds"); } if (lowerBound.isPrimitive() || lowerBound.isPrimitiveVoid()) { throw new IllegalArgumentException("Constraints may not be primitives"); } if (this.lowerBound != null && this.lowerBound != lowerBound) { throw new IllegalStateException("only one lower bound is supported"); } this.lowerBound = lowerBound; resolved = resolved && lowerBound.isResolved(); }
@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; }
result.setLowerBound(visited.copyInto(result.getOwner()));