if (conformsToAll(type, types)) return type; if (isPrimitiveVoid(type)) { if (containsPrimitiveOrAnyReferences(types)) { List<JvmTypeReference> withoutPrimitives = replacePrimitivesAndRemoveAnyReferences(types); if (withoutPrimitives.equals(types)) return null; return getCommonSuperType(withoutPrimitives); initializeDistance(firstType, all, cumulatedDistance); cumulateDistance(tail, all, cumulatedDistance); return getFirstForRawType(all, firstRawType); inplaceSortByDistanceAndName(candidates); if (classSeen) break; result = getTypeParametersForSupertype(all, rawType, types); for(JvmTypeReference alreadyCollected: referencesWithSameDistance) { if (isConformant(result, alreadyCollected, true)) { classSeen = classSeen || isClass(rawType); continue outer; result = getTypeParametersForSupertype(all, rawType, types); if (result != null) { boolean isClass = isClass(rawType); classSeen = classSeen || isClass;
protected JvmType findContext(JvmTypeReference firstType) { if (firstType instanceof JvmGenericArrayTypeReference) { return findContext(((JvmGenericArrayTypeReference) firstType).getComponentType()); } return firstType.getType(); }
protected Primitive primitiveKind(JvmPrimitiveType primitiveType) { return conformanceComputer.getPrimitives().primitiveKind(primitiveType); }
JvmTypeReference potentialPrimitive = conformanceComputer.getPrimitives().asPrimitiveIfWrapperType(rightReference); if (potentialPrimitive != rightReference) { if (leftType == potentialPrimitive.getType() || isWideningConversion((JvmPrimitiveType)leftType, (JvmPrimitiveType) potentialPrimitive.getType())) { 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); if (conformanceComputer.getTypeReferences().is(leftReference, Object.class)) return TypeConformanceResult.SUBTYPE; for(JvmTypeConstraint rightConstraint: rightConstraints) { if (rightConstraint instanceof JvmUpperBound) { TypeConformanceResult candidate = conformanceComputer.isConformant(leftReference, rightConstraint.getTypeReference(), param); if (candidate.isConformant()) return candidate; if (conformanceComputer.getSuperTypeCollector().isSuperType((JvmDeclaredType)rightType, (JvmDeclaredType)leftType)) { if (param.rawType) return TypeConformanceResult.SUBTYPE;
return getFirstForRawType(all, rawType); JvmTypeReference parameterSuperType = getCommonParameterSuperType(parameterReferences, initiallyRequested); if (parameterSuperType == null) { return null; JvmTypeReference componentTypeReference = getTypeParametersForSupertype( decorated, componentType,
boolean conformant = true; for(ResolveInfo lower: lowers) { if (!getConformanceComputer().isConformant(info.reference, lower.reference)) { conformant = false; break; JvmTypeReference reference = null; if (!uppers.isEmpty() && upperIndex < lowerIndex) { reference = conformanceComputer.getCommonSuperType(uppers); if (uppers.size() == 1 && boundToList.get(upperIndex).kind == ResolveInfoKind.WC_UPPER) { 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 (bestResolvedLower.kind != ResolveInfoKind.WC_LOWER) { if (!uppers.isEmpty()) { JvmTypeReference upper = conformanceComputer.getCommonSuperType(uppers); if (conformanceComputer.isConformant(bestResolvedLower.reference, upper)) reference = upper; else
protected TypeArgumentContext getBoundTypeParameters(JvmParameterizedTypeReference reference) { return conformanceComputer.getTypeArgumentContextProvider().getReceiverContext(reference); }
public JvmTypeReference getCommonParameterSuperType(final List<JvmTypeReference> types, List<JvmTypeReference> initiallyRequested) { Function<JvmTypeReference, String> getCanonicalName = new Function<JvmTypeReference, String>() { public String apply(JvmTypeReference from) { return from.getIdentifier(); } }; Set<String> allNames = Sets.newHashSet(Iterables.transform(types, getCanonicalName)); if (allNames.size() == 1) return types.get(0); if (types.size() == initiallyRequested.size()) { Set<String> initiallyRequestedNames = Sets.newHashSet(Iterables.transform(initiallyRequested, getCanonicalName)); if (initiallyRequestedNames.equals(allNames)) { // recursion - return object wildcard JvmTypeReference objectTypeReference = typeReferences.getTypeForName(Object.class, types.get(0).getType()); return typeReferences.wildCardExtends(objectTypeReference); } } JvmTypeReference superType = getCommonSuperType(types); if (superType instanceof JvmWildcardTypeReference) return superType; JvmWildcardTypeReference wildcardTypeReference = factory.createJvmWildcardTypeReference(); if (superType != null) { JvmUpperBound upperBound = factory.createJvmUpperBound(); upperBound.setTypeReference(EcoreUtil2.clone(superType)); wildcardTypeReference.getConstraints().add(upperBound); } return wildcardTypeReference; }
protected void initializeDistance(final JvmTypeReference firstType, Multimap<JvmType, JvmTypeReference> all, Multiset<JvmType> cumulatedDistance) { ITypeArgumentContext firstContext = getTypeArgumentContextProvider().getTypeArgumentContext( new TypeArgumentContextProvider.ReceiverRequest(firstType)); MaxDistanceRawTypeAcceptor acceptor = new MaxDistanceRawTypeAcceptor( cumulatedDistance, all, new ArgumentResolver(firstContext)); acceptor.accept(firstType, 0); superTypeCollector.collectSuperTypes(firstType, acceptor); }
JvmTypeReference commonVarArgType = getConformanceComputer().getCommonSuperType(actualVarArgTypes); resolveAgainstActualType(varArgComponentType, commonVarArgType, result, true, paramCount);