TerminalBlock () { PsiLocalVariable collectionVariable = extractCollectionAdditionVariable(); if(collectionVariable == null) return this; for(int idx = myOperations.length-1; idx > 0; idx--) { Operation op = myOperations[idx]; if (op instanceof FilterOp filter) { PsiExpression condition = filter.getExpression(); if (BoolUtils.isNegation(condition)) { if (filter.isNegated()) continue; condition = BoolUtils.getNegated(condition); } else if (!filter.isNegated()) continue; if (!(condition instanceof PsiMethodCallExpression conditionCall)) continue; if (!ExpressionUtils.isReferenceTo(conditionCall.getMethodExpression().getQualifierExpression(), collectionVariable) || !isCallOf(conditionCall, CommonClassNames.JAVA_UTIL_COLLECTION, "contains")) { continue; } PsiExpression[] conditionArgs = conditionCall.getArgumentList().getExpressions(); if (conditionArgs.length == 1 && ExpressionUtils.isReferenceTo(conditionArgs[0], myVariable)) { return replace(op, new DistinctOp(myVariable)); } } else if (!(op instanceof LimitOp)) { break; } } return this; }