PsiType (PsiType currentType, PsiType castType) { if (currentType != null) { if (castType != null) { if (TypeConversionUtil.isAssignable(castType, currentType)) { return castType; } if (!TypeConversionUtil.isAssignable(currentType, castType)) { for (PsiType superType : castType.getSuperTypes()) { if (TypeConversionUtil.isAssignable(superType, currentType)) { return superType; } } return null; } } } else { return castType; } return currentType; }