List<Operation> (@NotNull PsiMethodCallExpression lastCall, boolean hasTerminalCall) { List<Operation> operations = new ArrayList<>(); for (PsiMethodCallExpression call = lastCall; call != null; call = MethodCallUtils.getQualifierMethodCall(call)) { PsiMethod method = call.resolveMethod(); if (method == null || !isOptionalMethod(method)) return null; PsiType type = call == lastCall && hasTerminalCall ? call.getType() : OptionalUtil.getOptionalElementType(call.getType()); if (type == null) return null; String name = call.getMethodExpression().getReferenceName(); if (name == null) return null; PsiExpression[] args = call.getArgumentList().getExpressions(); Operation operation = convertToOperation(name, type, args); if (operation == null) return null; operations.add(operation); } Collections.reverse(operations); return operations; }