public boolean isConformant(JvmTypeReference left, JvmTypeReference right) { return isConformant(left, right, false); }
protected boolean conformsToAll(JvmTypeReference type, final List<JvmTypeReference> types) { boolean conform = true; for (int i = 0; conform && i < types.size(); i++) { conform = isConformant(type, types.get(i)); } return conform; }
@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(); }
@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; }
@Override public TypeConformanceResult doVisitGenericArrayTypeReference(JvmGenericArrayTypeReference left, JvmGenericArrayTypeReference right, TypeConformanceComputationArgument.Internal<JvmGenericArrayTypeReference> param) { JvmTypeReference leftComponent = left.getComponentType(); JvmTypeReference rightComponent = right.getComponentType(); return conformanceComputer.isConformant(leftComponent, rightComponent, new TypeConformanceComputationArgument(param.rawType, param.asTypeArgument, false)); }
@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; }
boolean conformant = true; for(ResolveInfo lower: lowers) { if (!getConformanceComputer().isConformant(info.reference, lower.reference)) { conformant = false; break; boolean useWildcard = true; for(ResolveInfo lowerResolve: lowers) { if (!conformanceComputer.isConformant(lowerResolve.reference, reference)) { useWildcard = false; break; bestResolvedLower = resolvedLower; } 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; if (!uppers.isEmpty()) { JvmTypeReference upper = conformanceComputer.getCommonSuperType(uppers); if (conformanceComputer.isConformant(bestResolvedLower.reference, upper)) reference = upper; else if (!uppers.isEmpty()) { JvmTypeReference upper = conformanceComputer.getCommonSuperType(uppers); if (conformanceComputer.isConformant(reference, upper)) reference = upper;
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; }
result = getTypeParametersForSupertype(all, rawType, types); for(JvmTypeReference alreadyCollected: referencesWithSameDistance) { if (isConformant(result, alreadyCollected, true)) { classSeen = classSeen || isClass(rawType); continue outer;
for(JvmTypeConstraint rightConstraint: rightConstraints) { if (rightConstraint instanceof JvmUpperBound) { TypeConformanceResult result = conformanceComputer.isConformant(leftUpperBound, rightConstraint.getTypeReference(), new TypeConformanceComputationArgument(false, false, false)); if (!result.isConformant()) { return result; } else if (rightConstraint instanceof JvmLowerBound) { lowerBoundSeen = true; TypeConformanceResult result = conformanceComputer.isConformant(rightConstraint.getTypeReference(), leftLowerBound, new TypeConformanceComputationArgument(false, false, false)); if (!result.isConformant()) { return TypeConformanceResult.FAILED;
JvmTypeReference potentialWrapper = conformanceComputer.getPrimitives().asWrapperTypeIfPrimitive(rightReference); if (potentialWrapper != rightReference) { TypeConformanceResult result = conformanceComputer.isConformant(leftReference, potentialWrapper, param); if (result.isConformant()) { return new TypeConformanceResult(TypeConformanceResult.Kind.BOXING); for(JvmTypeConstraint rightConstraint: rightConstraints) { if (rightConstraint instanceof JvmUpperBound) { TypeConformanceResult candidate = conformanceComputer.isConformant(leftReference, rightConstraint.getTypeReference(), param); if (candidate.isConformant()) return candidate;