@Override protected TypeParameterSubstitutor<?> createTypeParameterSubstitutor( Map<JvmTypeParameter, LightweightMergedBoundTypeArgument> mapping) { return new UnboundTypeParameterPreservingSubstitutor(mapping, getOwner()); }
@Override /* @Nullable */ protected LightweightTypeReference getBoundTypeArgument(ParameterizedTypeReference reference, JvmTypeParameter type, Set<JvmTypeParameter> visiting) { if (isBoundTypeArgumentSkipped(type, super.getTypeParameterMapping(), getOwner())) { return null; } return super.getBoundTypeArgument(reference, type, visiting); }
@Override /* @Nullable */ protected LightweightTypeReference getBoundTypeArgument(ParameterizedTypeReference reference, JvmTypeParameter type, Set<JvmTypeParameter> visiting) { LightweightMergedBoundTypeArgument boundTypeArgument = getTypeParameterMapping().get(type); if (boundTypeArgument != null) { LightweightTypeReference boundReference = boundTypeArgument.getTypeReference(); if (boundReference != null && reference != boundReference) { if (boundReference instanceof UnboundTypeReference) return boundReference.copyInto(getOwner()); JvmType boundType = boundReference.getType(); if (boundType != type) { if (visiting.add(type)) { try { LightweightTypeReference result = boundReference.accept(this, visiting); return result; } finally { visiting.remove(type); } } else { return reference; } } } } return null; }
initializeMapping(declaredTypeParameter, typeParameterMapping); UnboundTypeParameterPreservingSubstitutor substitutor = new UnboundTypeParameterPreservingSubstitutor(typeParameterMapping, getState().getReferenceOwner()); substitutor.enhanceMapping(getDeclaratorParameterMapping()); LightweightTypeReference expectedType = expectation.getExpectedType(); if (expectedType != null) { LightweightTypeReference declaredFeatureType = getDeclaredType(getFeature()); LightweightTypeReference substitutedFeatureType = substitutor.substitute(declaredFeatureType); DeferredTypeParameterHintCollector collector = new DeferredTypeParameterHintCollector(state.getReferenceOwner()) { @Override
return new RawTypeSubstitutor(state.getReferenceOwner()); } else { UnboundTypeParameterPreservingSubstitutor substitutor = new UnboundTypeParameterPreservingSubstitutor(getDeclaratorParameterMapping(), state.getReferenceOwner()) { @Override substitutor.enhanceMapping(getTypeParameterMapping()); return substitutor;
protected void initializeConstraintMapping(JvmTypeParameter typeParameter, UnboundTypeParameterPreservingSubstitutor substitutor, UnboundTypeReference typeReference) { if (!typeReference.internalIsResolved()) { List<JvmTypeConstraint> constraints = typeParameter.getConstraints(); for(JvmTypeConstraint constraint: constraints) { JvmTypeReference constraintReference = constraint.getTypeReference(); if (constraintReference != null) { LightweightTypeReference substitute = substitutor.substitute(constraintReference); if (!substitute.isType(Object.class) && !substitute.isPrimitiveVoid()) { typeReference.acceptHint(substitute, BoundTypeArgumentSource.CONSTRAINT, constraint, VarianceInfo.OUT, VarianceInfo.OUT); } } } } }
@Override protected LightweightTypeReference doVisitUnboundTypeReference(UnboundTypeReference reference, Set<JvmTypeParameter> visiting) { return reference.copyInto(getOwner()); }
@Override protected LightweightTypeReference visitTypeArgument(LightweightTypeReference reference, Set<JvmTypeParameter> visiting, boolean lowerBound) { LightweightTypeReference result = super.visitTypeArgument(reference, visiting, lowerBound); if (lowerBound && result.getKind() == LightweightTypeReference.KIND_WILDCARD_TYPE_REFERENCE) { result = result.getUpperBoundSubstitute(); } return result; }
@Override public LightweightTypeReference doVisitUnboundTypeReference(UnboundTypeReference reference, Set<JvmTypeParameter> visiting) { if (reference.getHandle() == left.getHandle()) { if (right.getKind() == KIND_UNBOUND_TYPE_REFERENCE) { UnboundTypeReference rightUnbound = (UnboundTypeReference) right; List<LightweightBoundTypeArgument> rightHints = rightUnbound.getAllHints(); for(LightweightBoundTypeArgument rightHint: rightHints) { LightweightTypeReference rightHintReference = rightHint.getTypeReference(); if (rightHintReference != null && leftHintReference.getUniqueIdentifier().equals(rightHintReference.getUniqueIdentifier())) { return super.doVisitUnboundTypeReference(reference, visiting); } } } return rightTypeArgument.getTypeReference(); } return super.doVisitUnboundTypeReference(reference, visiting); } };
LightweightTypeReference constraintReference = unboundSubstitutor.substitute(leftHintReference); int constraintResult = doIsConformant(constraintReference, right, flags); if ((constraintResult & SUCCESS) == 0) {
@Override protected TypeParameterSubstitutor<?> createTypeParameterSubstitutor(Map<JvmTypeParameter, LightweightMergedBoundTypeArgument> mapping) { return new UnboundTypeParameterPreservingSubstitutor(mapping, getOwner()); }
List<LightweightTypeReference> parameterTypes = Lists.newArrayListWithCapacity(operation.getParameters().size()); for(JvmFormalParameter parameter: operation.getParameters()) { LightweightTypeReference lightweight = substitutor.substitute(owner.toLightweightTypeReference(parameter.getParameterType())); LightweightTypeReference lowerBound = lightweight.getLowerBoundSubstitute(); if (lowerBound instanceof AnyTypeReference) parameterTypes.add(lowerBound); LightweightTypeReference returnType = substitutor.substitute(declaredReturnType); FunctionTypeReference result = createFunctionTypeRef(owner, typeReference, parameterTypes, returnType.getUpperBoundSubstitute(), typeReference.getOuter()); return result;
@Override protected TypeParameterSubstitutor<?> createTypeParameterSubstitutor(Map<JvmTypeParameter, LightweightMergedBoundTypeArgument> mapping) { return new UnboundTypeParameterPreservingSubstitutor(mapping, getOwner()); }
protected TypeParameterSubstitutor<?> createSubstitutor() { DeclaratorTypeArgumentCollector collector = new DeclaratorTypeArgumentCollector() { @Override public Boolean doVisitArrayTypeReference(ArrayTypeReference reference, LightweightTraversalData data) { return reference.getComponentType().accept(this, data); } }; Map<JvmTypeParameter, LightweightMergedBoundTypeArgument> mapping = collector.getTypeParameterMapping(this); UnboundTypeParameterPreservingSubstitutor substitutor = new UnboundTypeParameterPreservingSubstitutor(mapping, getOwner()); return substitutor; }
@Override public LightweightTypeReference doVisitParameterizedTypeReference(ParameterizedTypeReference reference) { DeclaratorTypeArgumentCollector typeArgumentCollector = new ConstraintAwareTypeArgumentCollector(owner); Map<JvmTypeParameter, LightweightMergedBoundTypeArgument> typeParameterMapping = typeArgumentCollector.getTypeParameterMapping(reference); TypeParameterSubstitutor<?> substitutor = new UnboundTypeParameterPreservingSubstitutor(typeParameterMapping, owner); JvmGenericType iterable = (JvmGenericType) owner.getServices().getTypeReferences().findDeclaredType(Iterable.class, owner.getContextResourceSet()); if (iterable == null) { return owner.newReferenceToObject(); } LightweightTypeReference substituteMe = owner.newParameterizedTypeReference(iterable.getTypeParameters().get(0)); LightweightTypeReference substitutedArgument = substitutor.substitute(substituteMe).getUpperBoundSubstitute(); if (substitutedArgument.getType() instanceof JvmTypeParameter && !(owner.getDeclaredTypeParameters().contains(substitutedArgument.getType()))) { return substitutedArgument.getRawTypeReference(); } return substitutedArgument; }