PsiPatternVariable (@NotNull PsiExpression currentQualifier, @NotNull PsiDeconstructionPattern currentDeconstruction, @NotNull PsiMethodCallExpression call) { PsiElement parent = PsiUtil.skipParenthesizedExprUp(currentQualifier.getParent()); if (!(parent instanceof PsiReferenceExpression)) return null; PsiElement grandParent = parent.getParent(); if (grandParent instanceof PsiMethodCallExpression currentCall && currentCall.resolveMethod() instanceof LightRecordMethod recordMethod) { PsiClass aClass = recordMethod.getContainingClass(); PsiRecordComponent[] recordComponents = aClass.getRecordComponents(); PsiRecordComponent recordComponent = recordMethod.getRecordComponent(); int index = ArrayUtil.find(recordComponents, recordComponent); if (index < 0) return null; PsiPattern[] deconstructionComponents = currentDeconstruction.getDeconstructionList().getDeconstructionComponents(); if (index >= deconstructionComponents.length) return null; PsiPattern deconstructionComponent = deconstructionComponents[index]; PsiType componentType = JavaPsiPatternUtil.getPatternType(deconstructionComponent); if (componentType == null || !componentType.equals(recordComponent.getType())) return null; PsiPatternVariable variable = JavaPsiPatternUtil.getPatternVariable(deconstructionComponent); if (currentCall.equals(call)) return variable; if (deconstructionComponent instanceof PsiDeconstructionPattern deconstruction) { return findExistingPatternVariable(currentCall, deconstruction, call); } } return null; }