CandidateInfo (@NotNull CandidateInfo resolveResult, @NotNull PsiDeconstructionPattern pattern, @NotNull PsiClass recordClass, @Nullable PsiType type) { // JLS 18.5.5 if (type == null) return resolveResult; type = JavaVarTypeUtil.getUpwardProjection(type); Project project = recordClass.getProject(); PsiElementFactory factory = JavaPsiFacade.getElementFactory(project); PsiClassType recordRawType = factory.createType(recordClass); if (!recordRawType.isConvertibleFrom(type) || JavaGenericsUtil.isUncheckedCast(recordRawType, type)) { return resolveResult; } PsiTypeParameter[] parameters = recordClass.getTypeParameters(); InferenceSession session = new InferenceSession(parameters, PsiSubstitutor.EMPTY, PsiManagerEx.getInstanceEx(project), pattern); if (!addConstraints(recordClass, type, factory, session)) { return resolveResult; } PsiSubstitutor substitutor = session.infer(); return new PatternCandidateInfo(resolveResult, substitutor, ContainerUtil.getFirstItem(session.getIncompatibleErrorMessages())); }