@Override public TypeConformanceResult doVisitTypeReference(JvmSynonymTypeReference left, JvmTypeReference right, TypeConformanceComputationArgument.Internal<JvmSynonymTypeReference> param) { List<JvmTypeReference> leftReferences = left.getReferences(); if (leftReferences.isEmpty()) return TypeConformanceResult.FAILED; for(JvmTypeReference reference: leftReferences) { TypeConformanceResult result = conformanceComputer.isConformant(reference, right, param); if (result.isConformant()) return result; } return TypeConformanceResult.FAILED; }
public boolean isConformant(JvmTypeReference left, JvmTypeReference right, boolean ignoreGenerics) { if (left == right && left != null) return true; TypeConformanceResult result = isConformant(left, right, new TypeConformanceComputationArgument(ignoreGenerics, false, true)); return result.isConformant(); }
public TypeConformanceResult doVisitMultiTypeReference(T left, JvmMultiTypeReference right, TypeConformanceComputationArgument.Internal<T> param) { for(JvmTypeReference reference: right.getReferences()) { TypeConformanceResult result = visit(reference, param); if (result.isConformant()) return result; } if (right.getReferences().isEmpty()) return TypeConformanceResult.SUCCESS; return TypeConformanceResult.FAILED; }
@Override public TypeConformanceResult doVisitTypeReference(JvmMultiTypeReference left, JvmTypeReference right, TypeConformanceComputationArgument.Internal<JvmMultiTypeReference> param) { for(JvmTypeReference component: left.getReferences()) { // TODO I think we should disable primitive widening / boxing here TypeConformanceResult result = conformanceComputer.isConformant(component, right, param); if (!result.isConformant()) return result; } if (!left.getReferences().isEmpty()) { return TypeConformanceResult.SUCCESS; } return TypeConformanceResult.FAILED; }
public TypeConformanceResult doVisitSynonymTypeReference(T left, JvmSynonymTypeReference right, TypeConformanceComputationArgument.Internal<T> param) { List<JvmTypeReference> rightComponents = right.getReferences(); if (rightComponents.isEmpty()) return TypeConformanceResult.FAILED; for(int i = 0; i < rightComponents.size(); i++) { TypeConformanceResult candidate = visit(rightComponents.get(i), param); if (candidate.isConformant()) { if (i == 0) return candidate; TypeConformanceResult result = TypeConformanceResult.merge(candidate, new TypeConformanceResult(TypeConformanceResult.Kind.SYNONYM)); result.setSynonymIndex(i); result.setConversion(rightComponents.get(0), rightComponents.get(i)); return result; } } return TypeConformanceResult.FAILED; }
@Override public TypeConformanceResult doVisitTypeReference(JvmWildcardTypeReference leftWildcard, JvmTypeReference right, TypeConformanceComputationArgument.Internal<JvmWildcardTypeReference> param) { if (param.asTypeArgument) { List<JvmTypeConstraint> constraints = leftWildcard.getConstraints(); if (!constraints.isEmpty()) { for(JvmTypeConstraint constraint: constraints) { if (constraint instanceof JvmUpperBound) { TypeConformanceResult result = conformanceComputer.isConformant(constraint.getTypeReference(), right, new TypeConformanceComputationArgument(false, false, false)); if (!result.isConformant()) { return result; } } else if (constraint instanceof JvmLowerBound) { TypeConformanceResult result = conformanceComputer.isConformant(right, constraint.getTypeReference(), new TypeConformanceComputationArgument(false, false, false)); if (!result.isConformant()) { return result; } } } return TypeConformanceResult.SUCCESS; } else { // no constraints found return TypeConformanceResult.SUCCESS; } } return TypeConformanceResult.FAILED; }
} else { TypeConformanceResult conformanceResult = conformanceComputer.isConformant(bestResolvedLower.reference, resolvedLower.reference, new TypeConformanceComputationArgument(false, false, true)); if (conformanceResult.isConformant() && conformanceResult.getKinds().contains(TypeConformanceResult.Kind.SUBTYPE)) bestResolvedLower = resolvedLower;
protected TypeConformanceResult areArgumentsConformant(JvmParameterizedTypeReference leftReference, JvmParameterizedTypeReference rightReference) { TypeArgumentContext leftArgumentContext = getBoundTypeParameters(leftReference); if (leftArgumentContext != null && !leftArgumentContext.isRawTypeContext()) { Collection<JvmTypeParameter> boundParameters = leftArgumentContext.getBoundParameters(); Set<Pair<JvmTypeReference, JvmTypeReference>> tested = Sets.newHashSet(); if (!boundParameters.isEmpty()) { TypeArgumentContext rightArgumentContext = getBoundTypeParameters(rightReference); if (rightArgumentContext == null) { return TypeConformanceResult.FAILED; } if (!rightArgumentContext.isRawTypeContext()) { for(JvmTypeParameter leftTypeParameter: boundParameters) { JvmTypeReference leftBound = leftArgumentContext.getBoundArgument(leftTypeParameter); JvmTypeReference rightBound = rightArgumentContext.getBoundArgument(leftTypeParameter); if (leftBound != rightBound && rightBound != null) { if (tested.add(Tuples.create(leftBound, rightBound))) { TypeConformanceResult result = conformanceComputer.isConformant(leftBound, rightBound, new TypeConformanceComputationArgument(false, true, false)); if (!result.isConformant()) { return result; } } } } } } } return TypeConformanceResult.SUCCESS; }
if (rightConstraint instanceof JvmUpperBound) { TypeConformanceResult result = conformanceComputer.isConformant(leftUpperBound, rightConstraint.getTypeReference(), new TypeConformanceComputationArgument(false, false, false)); if (!result.isConformant()) { return result; lowerBoundSeen = true; TypeConformanceResult result = conformanceComputer.isConformant(rightConstraint.getTypeReference(), leftLowerBound, new TypeConformanceComputationArgument(false, false, false)); if (!result.isConformant()) { return TypeConformanceResult.FAILED;
if (potentialWrapper != rightReference) { TypeConformanceResult result = conformanceComputer.isConformant(leftReference, potentialWrapper, param); if (result.isConformant()) { return new TypeConformanceResult(TypeConformanceResult.Kind.BOXING); if (rightConstraint instanceof JvmUpperBound) { TypeConformanceResult candidate = conformanceComputer.isConformant(leftReference, rightConstraint.getTypeReference(), param); if (candidate.isConformant()) return candidate; } else {