protected LightweightTypeReference getDeclaredUpperBound(JvmTypeParameter typeParameter, ConstraintVisitingInfo visiting) { if (!typeParameter.getConstraints().isEmpty()) { JvmTypeConstraint constraint = typeParameter.getConstraints().get(0); if (constraint instanceof JvmUpperBound) { LightweightTypeReference reference = getOwner().toLightweightTypeReference(constraint.getTypeReference()); if (visiting.getCurrentDeclarator() != reference.getType()) { return visitTypeArgument(reference, visiting); } WildcardTypeReference result = getOwner().newWildcardTypeReference(); result.addUpperBound(getObjectReference()); return result; } } return null; }
@Override protected LightweightTypeReference doVisitUnboundTypeReference(UnboundTypeReference reference, ConstraintVisitingInfo visiting) { if (!handle.equals(reference.getHandle())) { return reference; } JvmTypeParameter typeParameter = reference.getTypeParameter(); if (!visiting.tryVisit(typeParameter)) { LightweightTypeReference mappedReference = getDeclaredUpperBound(typeParameter, visiting); getTypeParameterMapping().put(typeParameter, new LightweightMergedBoundTypeArgument(mappedReference, VarianceInfo.INVARIANT)); if (mappedReference != null) return mappedReference; return getObjectReference(); } try { LightweightMergedBoundTypeArgument boundTypeArgument = getTypeParameterMapping().get(typeParameter); if (boundTypeArgument != null && boundTypeArgument.getTypeReference() != reference) { LightweightTypeReference result = boundTypeArgument.getTypeReference().accept(this, visiting); return result; } else { LightweightTypeReference mappedReference = getDeclaredUpperBound(visiting.getCurrentDeclarator(), visiting.getCurrentIndex(), visiting); getTypeParameterMapping().put(typeParameter, new LightweightMergedBoundTypeArgument(mappedReference, VarianceInfo.INVARIANT)); return mappedReference; } } finally { visiting.didVisit(typeParameter); } }
@Override /* @Nullable */ protected LightweightTypeReference getDeclaredUpperBound(JvmTypeParameter typeParameter, ConstraintVisitingInfo visiting) { if (!typeParameter.getConstraints().isEmpty() && ((DeclaredConstraintVisitingInfo)visiting).tryVisitDeclaredUpperBoundsOf(typeParameter)) { try { JvmTypeConstraint constraint = typeParameter.getConstraints().get(0); if (constraint instanceof JvmUpperBound) { LightweightTypeReference reference = getOwner().toLightweightTypeReference(constraint.getTypeReference()); if (visiting.getCurrentDeclarator() != reference.getType()) { return reference.accept(this, visiting); } WildcardTypeReference result = getOwner().newWildcardTypeReference(); result.addUpperBound(getObjectReference()); return result; } } finally { ((DeclaredConstraintVisitingInfo)visiting).didVisitDeclaredUpperBoundsOf(typeParameter); } } return null; }
@Override protected LightweightTypeReference doVisitUnboundTypeReference(UnboundTypeReference reference, ConstraintVisitingInfo visiting) { JvmTypeParameter typeParameter = reference.getTypeParameter(); if (!visiting.tryVisit(typeParameter)) { LightweightTypeReference mappedReference = getDeclaredUpperBound(typeParameter, visiting); getTypeParameterMapping().put(typeParameter, new LightweightMergedBoundTypeArgument(mappedReference, VarianceInfo.INVARIANT)); if (mappedReference != null) return mappedReference; return getObjectReference(); } try { LightweightMergedBoundTypeArgument boundTypeArgument = getTypeParameterMapping().get(typeParameter); if (boundTypeArgument != null && boundTypeArgument.getTypeReference() != reference) { LightweightTypeReference result = boundTypeArgument.getTypeReference().accept(this, visiting); return result; } else { JvmTypeParameterDeclarator currentDeclarator = visiting.getCurrentDeclarator(); LightweightTypeReference mappedReference = currentDeclarator != null ? getDeclaredUpperBound(currentDeclarator, visiting.getCurrentIndex(), visiting) : getDeclaredUpperBound(typeParameter, visiting); if (mappedReference == null) mappedReference = getObjectReference(); getTypeParameterMapping().put(typeParameter, new LightweightMergedBoundTypeArgument(mappedReference, VarianceInfo.INVARIANT)); return mappedReference; } } finally { visiting.didVisit(typeParameter); } }
if (!visiting.tryVisit(typeParameter)) { if (!isDeclaredTypeParameter(typeParameter)) { if (visiting.getCurrentDeclarator() != null) { LightweightTypeReference mappedReference = getDeclaredUpperBound(visiting.getCurrentDeclarator(), visiting.getCurrentIndex(), visiting); getTypeParameterMapping().put((JvmTypeParameter)type, new LightweightMergedBoundTypeArgument(mappedReference, VarianceInfo.INVARIANT)); return mappedReference;