List<MethodContract> (@NotNull PsiMethod method, @Nullable PsiMethodCallExpression call) { PsiClass owner = method.getContainingClass(); if (owner == null) { return Collections.emptyList(); } PsiFile file = owner.getContainingFile(); if (file != null && InjectedLanguageManager.getInstance(owner.getProject()).isInjectedFragment(file)) { return Collections.emptyList(); } final int paramCount = method.getParameterList().getParametersCount(); String className = owner.getQualifiedName(); if (className == null) return Collections.emptyList(); if (method.isConstructor()) { if (className.equals("java.util.concurrent.ArrayBlockingQueue") && paramCount == 3) { return List.of(singleConditionContract(ContractValue.argument(0), RelationType.LT, ContractValue.argument(2).specialField(SpecialField.COLLECTION_SIZE), fail()), singleConditionContract(ContractValue.argument(0), RelationType.LE, ContractValue.constant(0, PsiTypes.intType()), fail())); } } ContractProvider provider = HARDCODED_CONTRACTS.mapFirst(method); if (provider != null) { List<MethodContract> contracts = provider.getContracts(call, paramCount); if (contracts != null) { return contracts; } } String methodName = method.getName(); if ("org.apache.commons.lang.Validate".equals(className) || "org.apache.commons.lang3.Validate".equals(className) || "org.springframework.util.Assert".equals(className)) { if (("isTrue".equals(methodName) || "state".equals(methodName)) && paramCount > 0) { ValueConstraint[] constraints = createConstraintArray(paramCount); constraints[0] = FALSE_VALUE; return Collections.singletonList(new StandardMethodContract(constraints, fail())); } if ("notNull".equals(methodName) && paramCount > 0) { ValueConstraint[] constraints = createConstraintArray(paramCount); constraints[0] = NULL_VALUE; StandardMethodContract contract = new StandardMethodContract(constraints, fail()); if (PsiTypes.voidType().equals(method.getReturnType())) { return Collections.singletonList(contract); } else { return Arrays.asList(contract, new StandardMethodContract(createConstraintArray(paramCount), returnParameter(0))); } } } else if (isJunit(className) || isTestng(className) || className.equals("org.hamcrest.MatcherAssert") || className.equals("org.hamcrest.junit.MatcherAssert")) { return handleTestFrameworks(method, paramCount, className, methodName, call); } else if (TypeUtils.isOptional(owner)) { if (OptionalUtil.OPTIONAL_GET.methodMatches(method) || "orElseThrow".equals(methodName)) { return Collections.singletonList(optionalAbsentContract(fail())); } else if ("isPresent".equals(methodName) && paramCount == 0) { return Arrays.asList(optionalAbsentContract(returnFalse()), trivialContract(returnTrue())); } else if ("isEmpty".equals(methodName) && paramCount == 0) { return Arrays.asList(optionalAbsentContract(returnTrue()), trivialContract(returnFalse())); } } else if (MethodUtils.isEquals(method)) { return Collections.singletonList(new StandardMethodContract(new ValueConstraint[]{NULL_VALUE}, returnFalse())); } return Collections.emptyList(); }