private static boolean canTypesBeEquivalent(PsiType type1, PsiType type2) {
    if (type1 == null || type2 == null) return false;
    if (!type2.isAssignableFrom(type1)) {
      if (type1 instanceof PsiImmediateClassType && type2 instanceof PsiImmediateClassType) {
        final PsiClass psiClass1 = ((PsiImmediateClassType)type1).resolve();
        final PsiClass psiClass2 = ((PsiImmediateClassType)type2).resolve();
        if (!(psiClass1 instanceof PsiAnonymousClass anonymousClass1 &&
              psiClass2 instanceof PsiAnonymousClass anonymousClass2 &&
              anonymousClass1.getBaseClassType().equals(anonymousClass2.getBaseClassType())
        )) {
          return false;
        }
      }
      else {
        return false;
      }
    }
    return true;
  }
private static boolean canTypesBeEquivalent(PsiType type1, PsiType type2)