void (@NotNull PsiPatternVariable variable) { PsiPattern deconstructionComponent = variable.getPattern(); if (deconstructionComponent.getParent() instanceof PsiDeconstructionList deconstructionList && deconstructionList.getParent() instanceof PsiDeconstructionPattern deconstruction) { PsiTypeElement typeElement = variable.getTypeElement(); if (!typeElement.isInferredType()) { @NotNull PsiPattern @NotNull [] patterns = deconstructionList.getDeconstructionComponents(); int index = ArrayUtil.indexOf(patterns, deconstructionComponent); // We need a copy of the entire pattern, not just the pattern variable, as we will // replace the variable type with 'var' inside the 'doCheck' method by calling the // 'IntroduceVariableUtil#expandDiamondsAndReplaceExplicitTypeWithVar' method. // Without the record pattern as context, we will not be able to get the type of // the deconstruction component variable when calling the 'getNormalizedType' method. PsiDeconstructionPattern deconstructionCopy = (PsiDeconstructionPattern)deconstruction.copy(); PsiPattern componentCopy = deconstructionCopy.getDeconstructionList().getDeconstructionComponents()[index]; doCheck(variable, Objects.requireNonNull(JavaPsiPatternUtil.getPatternVariable(componentCopy)), typeElement); } } }