List<OperationRecord> (ChainVariable outVar, PsiMethodCallExpression terminalCall, boolean supportUnknownSources) { List<OperationRecord> operations = new ArrayList<>(); PsiMethodCallExpression currentCall = terminalCall; ChainVariable lastVar = outVar; Operation next = null; while(true) { Operation op = createOperationFromCall(lastVar, currentCall, supportUnknownSources); if(op == null) return null; if(next != null) { Operation combined = op.combineWithNext(next); if (combined != null) { op = combined; operations.remove(operations.size() - 1); } } OperationRecord or = new OperationRecord(); or.myOperation = op; or.myOutVar = lastVar; operations.add(or); if(op instanceof SourceOperation) { or.myInVar = ChainVariable.STUB; Collections.reverse(operations); return operations; } currentCall = MethodCallUtils.getQualifierMethodCall(currentCall); if(currentCall == null) return null; if(op.changesVariable()) { PsiType type = StreamApiUtil.getStreamElementType(currentCall.getType()); if(type == null) return null; lastVar = new ChainVariable(type); } or.myInVar = lastVar; next = op; } }