String (ChainVariable inVar, String map) { if(myMerger == null) { return "if("+map+".put("+myKeyExtractor.getText()+","+myValueExtractor.getText()+")!=null) {\n"+ "throw new java.lang.IllegalStateException(\"Duplicate key\");\n}\n"; } if(myMerger instanceof PsiLambdaExpression lambda) { PsiParameter[] parameters = lambda.getParameterList().getParameters(); if(parameters.length == 2) { PsiExpression body = LambdaUtil.extractSingleExpressionFromBody(lambda.getBody()); if (body instanceof PsiReferenceExpression ref && ref.getQualifierExpression() == null) { // cannot use isReferenceTo here as lambda could be detached from PsiFile if (Objects.equals(parameters[0].getName(), ref.getReferenceName())) { // like (a, b) -> a return map + ".putIfAbsent(" + myKeyExtractor.getText() + "," + myValueExtractor.getText() + ");\n"; } else if (Objects.equals(parameters[1].getName(), ref.getReferenceName())) { // like (a, b) -> b return map + ".put(" + myKeyExtractor.getText() + "," + myValueExtractor.getText() + ");\n"; } } } } return map+".merge("+myKeyExtractor.getText()+","+myValueExtractor.getText()+","+myMerger.getText()+");\n"; }