private static List<PsiLocalVariable> collectVariables(@NotNull PsiDeconstructionPattern pattern,
                                                         @NotNull PsiLocalVariable variable,
                                                         @NotNull PsiElement context,
                                                         @NotNull List<PsiLocalVariable> result) {
    PsiClassType classType = ObjectUtils.tryCast(pattern.getTypeElement().getType(), PsiClassType.class);
    if (classType == null) return Collections.emptyList();
    PsiClass aClass = classType.resolve();
    if (aClass == null) return Collections.emptyList();
    PsiRecordComponent[] components = aClass.getRecordComponents();
    PsiPattern[] deconstructionComponents = pattern.getDeconstructionList().getDeconstructionComponents();
    if (components.length != deconstructionComponents.length) return Collections.emptyList();
    for (int i = 0; i < deconstructionComponents.length; i++) {
      PsiPattern deconstructionComponent = deconstructionComponents[i];
      PsiPatternVariable patternVariable = JavaPsiPatternUtil.getPatternVariable(deconstructionComponent);
      if (patternVariable == null && !(deconstructionComponent instanceof PsiDeconstructionPattern)) return Collections.emptyList();
      PsiType type = JavaPsiPatternUtil.getPatternType(deconstructionComponent);
      if (type == null) return Collections.emptyList();
      String declarationStatementText = type.getPresentableText() + " ";
      if (patternVariable != null) {
        declarationStatementText += patternVariable.getName() + "=";
      }
      else {
        VariableNameGenerator generator = new VariableNameGenerator(context, VariableKind.LOCAL_VARIABLE);
        String newVarName = generator.byType(type).generate(true);
        declarationStatementText += newVarName + "=";
      }
      if (!type.isAssignableFrom(components[i].getType())) {
        declarationStatementText += "(" + type.getPresentableText() + ")";
      }
      declarationStatementText += variable.getName() + "." + components[i].getName() + "();";
      PsiLocalVariable newVariable = createVariable(declarationStatementText, pattern);
      context.add(newVariable);
      result.add(newVariable);
      if (deconstructionComponent instanceof PsiDeconstructionPattern deconstructionPattern) {
        collectVariables(deconstructionPattern, newVariable, context, result);
      }
    }
    return result;
  }
private static List<PsiLocalVariable> collectVariables(@NotNull PsiDeconstructionPattern pattern,
                                                         @NotNull PsiLocalVariable variable,
                                                         @NotNull PsiElement context,
                                                         @NotNull List<PsiLocalVariable> result)