protected boolean isDeclaredTypeParameter(JvmTypeParameter typeParameter) { return getOwner().getDeclaredTypeParameters().contains(typeParameter); }
protected LightweightTypeReference getObjectReference() { return getOwner().newReferenceToObject(); }
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 public LightweightTypeReference doVisitParameterizedTypeReference(ParameterizedTypeReference reference, ConstraintVisitingInfo visiting) { if (reference.isResolved() && reference.isOwnedBy(getOwner())) return reference; JvmType type = reference.getType(); LightweightTypeReference result = boundTypeArgument.getTypeReference().accept(this, visiting); if (boundTypeArgument.getVariance() == VarianceInfo.OUT) { WildcardTypeReference wildcard = getOwner().newWildcardTypeReference(); wildcard.addUpperBound(result.getInvariantBoundSubstitute()); result = wildcard; } else if (boundTypeArgument.getVariance() == VarianceInfo.IN) { WildcardTypeReference wildcard = getOwner().newWildcardTypeReference(); wildcard.addUpperBound(getObjectReference()); wildcard.setLowerBound(result.getInvariantBoundSubstitute());
@Override public LightweightTypeReference substitute(LightweightTypeReference original) { if (original instanceof ArrayTypeReference) { LightweightTypeReference componentType = original.getComponentType(); if (componentType instanceof UnboundTypeReference) { LightweightTypeReference substitutedComponentType = substitute(componentType); return getOwner().newArrayTypeReference(substitutedComponentType); } } if (original instanceof UnboundTypeReference) { ConstraintVisitingInfo visitingInfo = createVisiting(); JvmTypeParameter typeParameter = ((UnboundTypeReference) original).getTypeParameter(); JvmTypeParameterDeclarator declarator = typeParameter.getDeclarator(); visitingInfo.pushInfo(declarator, declarator.getTypeParameters().indexOf(typeParameter)); LightweightTypeReference result = visitTypeArgument(original, visitingInfo); return result; } else { LightweightTypeReference result = original.accept(this, createVisiting()); return result; } }