if (toClass == null) return false;
if (toClass instanceof PsiTypeParameter) return isNarrowingReferenceConversionAllowed(fromType, obtainSafeSuperType((PsiTypeParameter)toClass));
//Done with type parameters
PsiManager manager = fromClass.getManager();
final LanguageLevel languageLevel = toClassType.getLanguageLevel();
if (!fromClass.isInterface()) {
if (toClass.isInterface()) {
return !fromClass.hasModifierProperty(PsiModifier.FINAL) &&
checkSuperTypesWithDifferentTypeArguments(toResult, fromClass, manager,
fromResult.getSubstitutor(),
new THashSet<PsiClass>(),
languageLevel);
}
else {
if (manager.areElementsEquivalent(fromClass, toClass)) {
return !areDistinctParameterTypes(fromClassType, toClassType);
}
if (toClass.isInheritor(fromClass, true)) {
return checkSuperTypesWithDifferentTypeArguments(fromResult, toClass, manager, toResult.getSubstitutor(), new THashSet<PsiClass>(),
languageLevel);
}
else if (fromClass.isInheritor(toClass, true)) {
return checkSuperTypesWithDifferentTypeArguments(toResult, fromClass, manager, fromResult.getSubstitutor(), new THashSet<PsiClass>(),
languageLevel);
}
return false;
}
}
else {
if (!toClass.isInterface()) {
if (!toClass.hasModifierProperty(PsiModifier.FINAL)) {
return checkSuperTypesWithDifferentTypeArguments(fromResult, toClass, manager, toResult.getSubstitutor(), new THashSet<PsiClass>(),
languageLevel);
}
else {
if (!toClass.isInheritor(fromClass, true)) return false;
PsiSubstitutor toSubstitutor = getSuperClassSubstitutor(fromClass, toClass, toResult.getSubstitutor());
return !areDistinctArgumentTypes(fromClass, fromResult.getSubstitutor(), toSubstitutor);
}
}
else {
if (languageLevel.compareTo(LanguageLevel.JDK_1_5) < 0) {
//In jls2 check for method in both interfaces with the same signature but different return types.
Collection<HierarchicalMethodSignature> fromClassMethodSignatures = fromClass.getVisibleSignatures();
Collection<HierarchicalMethodSignature> toClassMethodSignatures = toClass.getVisibleSignatures();
for (HierarchicalMethodSignature fromMethodSignature : fromClassMethodSignatures) {