private static boolean canBeUnnamed(PsiVariable variable) {
    if (!PsiUtil.isAvailable(JavaFeature.UNNAMED_PATTERNS_AND_VARIABLES, variable)) return false;
    if (variable instanceof PsiPatternVariable || variable instanceof PsiResourceVariable) return true;
    if (variable instanceof PsiLocalVariable) {
      return variable.getParent() instanceof PsiDeclarationStatement decl && decl.getParent() instanceof PsiCodeBlock;
    }
    if (variable instanceof PsiParameter parameter) {
      return !(parameter.getDeclarationScope() instanceof PsiMethod);
    }
    return false;
  }
private static boolean canBeUnnamed(PsiVariable variable)