@Override public LightweightTypeReference doVisitUnboundTypeReference(UnboundTypeReference reference, ConstraintVisitingInfo param) { return copy(reference); }
@Override protected LightweightTypeReference getUnmappedSubstitute(ParameterizedTypeReference reference, JvmTypeParameter type, ConstraintVisitingInfo visiting) { List<JvmTypeParameter> declaredTypeParameters = getOwner().getDeclaredTypeParameters(); if (declaredTypeParameters.contains(type)) { return reference.copyInto(getOwner()); } LightweightTypeReference result = createUnboundTypeReference(type); if (result == null) { result = new TypeParameterByConstraintSubstitutor(getTypeParameterMapping(), getOwner()).substitute(type); } return result; }
for (JvmTypeParameter typeParameter : typeParameters) { LightweightTypeReference typeParameterReference = owner.newParameterizedTypeReference(typeParameter); LightweightTypeReference substituted = substitutor.substitute(typeParameterReference); result.addTypeArgument(substituted); substitutor.enhanceMapping(definedMapping); LightweightTypeReference lightweight = owner.toLightweightTypeReference(parameter.getParameterType()); LightweightTypeReference lowerBound = lightweight.getLowerBoundSubstitute(); LightweightTypeReference substituted = substitutor.substitute(lowerBound); result.addParameterType(substituted); LightweightTypeReference substituted = substitutor.substitute(returnType); result.setReturnType(substituted); return result;
@Override /* @Nullable */ protected LightweightTypeReference getBoundTypeArgument(ParameterizedTypeReference reference, JvmTypeParameter type, ConstraintVisitingInfo visiting) { if (getOwner().getDeclaredTypeParameters().contains(type)) { return null; } return super.getBoundTypeArgument(reference, type, visiting); }
protected void initClosureType(FunctionTypeReference result, boolean isProcedure) { ITypeReferenceOwner owner = result.getOwner(); TypeParameterByUnboundSubstitutor substitutor = new TypeParameterByUnboundSubstitutor(Collections.<JvmTypeParameter, LightweightMergedBoundTypeArgument>emptyMap(), owner) { @Override protected UnboundTypeReference createUnboundTypeReference(JvmTypeParameter type) { UnboundTypeReference result = getExpectation().createUnboundTypeReference(getClosure(), type); return result; } }; JvmGenericType type = (JvmGenericType) result.getType(); List<JvmTypeParameter> typeParameters = type.getTypeParameters(); int max = type.getTypeParameters().size(); if (!isProcedure) max--; for(int i = 0; i < max; i++) { JvmTypeParameter typeParameter = typeParameters.get(i); LightweightTypeReference parameterType = owner.newParameterizedTypeReference(typeParameter); LightweightTypeReference substituted = substitutor.substitute(parameterType); result.addTypeArgument(substituted); } if (!isProcedure) { JvmTypeParameter typeParameter = typeParameters.get(max); LightweightTypeReference parameterType = owner.toLightweightTypeReference(typeParameter); LightweightTypeReference substituted = substitutor.substitute(parameterType); result.addTypeArgument(substituted); } }
@Override /* @Nullable */ protected LightweightMergedBoundTypeArgument getBoundTypeArgument(JvmTypeParameter typeParameter, ConstraintVisitingInfo info) { LightweightMergedBoundTypeArgument result = super.getBoundTypeArgument(typeParameter, info); if (result != null) { LightweightTypeReference typeReference = result.getTypeReference(); if (result.getVariance() == VarianceInfo.INVARIANT) { if (typeReference.isWildcard() && typeReference.getLowerBoundSubstitute().isAny() && typeReference.getUpperBoundSubstitute().isType(Object.class)) { // assume unbound wildcard - use the constraints of the respective type parameter if (!typeParameter.getConstraints().isEmpty()) { JvmTypeConstraint constraint = typeParameter.getConstraints().get(0); if (constraint instanceof JvmUpperBound) { LightweightTypeReference reference = getOwner().toLightweightTypeReference(constraint.getTypeReference()); return new LightweightMergedBoundTypeArgument(reference, VarianceInfo.OUT); } } } } if (declaratorParameterMapping.containsKey(typeParameter) && typeReference.isWildcard()) { wasCapturedWildcard = true; } } return result; }