CauseItem (MemoryStateChange history, PsiCallExpression call, ContractReturnValue contractReturnValue) { PsiMethod method = call.resolveMethod(); if (method == null) return null; List<? extends MethodContract> contracts = JavaMethodContractUtil.getMethodCallContracts(method, call); if (contracts.isEmpty()) return null; MethodContract contract = contracts.get(0); PsiElement anchor = getCallAnchor(call); if (anchor == null) return null; if (contracts.size() == 1 && contract.isTrivial() && contractReturnValue.isSuperValueOf(contract.getReturnValue())) { String message = JavaAnalysisBundle.message("dfa.find.cause.contract.trivial", getContractKind(call), JavaElementKind.fromElement(method).lessDescriptive().subject(), method.getName(), contract.getReturnValue()); return new CauseItem(message, anchor); } List<? extends MethodContract> nonIntersecting = MethodContract.toNonIntersectingContracts(contracts); if (nonIntersecting != null) { Condition<MethodContract> condition = contractReturnValue instanceof ContractReturnValue.ParameterReturnValue ? mc -> contractReturnValue.equals(mc.getReturnValue()) : mc -> contractReturnValue.isSuperValueOf(mc.getReturnValue()); MethodContract onlyContract = ContainerUtil.getOnlyItem(ContainerUtil.filter(nonIntersecting, condition)); if (onlyContract != null) { return fromSingleContract(history, call, method, onlyContract); } } List<MethodContract> unsureContracts = new ArrayList<>(); for (MethodContract c : contracts) { ThreeState applies = contractApplies(call, c); switch (applies) { case NO -> { } case UNSURE -> unsureContracts.add(c); case YES -> { if (unsureContracts.isEmpty() && contractReturnValue.isSuperValueOf(c.getReturnValue())) { return fromSingleContract(history, call, method, c); } } } } if (unsureContracts.size() == 1) { MethodContract c = unsureContracts.get(0); if (contractReturnValue.isSuperValueOf(c.getReturnValue())) { return fromSingleContract(history, call, method, c); } } return null; }