void (ChainContext context, String... argumentValues) { PsiMethodReferenceExpression methodRef = myMethodRef; PsiExpression qualifier = methodRef.getQualifierExpression(); if(qualifier != null) { String qualifierText = qualifier.getText(); if(!ExpressionUtils.isSafelyRecomputableExpression(qualifier)) { if (myQualifierType != null) { String nameCandidate = "expr"; SuggestedNameInfo info = JavaCodeStyleManager.getInstance(context.getProject()) .suggestVariableName(VariableKind.LOCAL_VARIABLE, null, null, myQualifierType, true); if (info.names.length > 0) { nameCandidate = info.names[0]; } String expr = context.declare(nameCandidate, myQualifierType.getCanonicalText(), qualifierText); PsiLambdaExpression lambdaExpression = (PsiLambdaExpression) context.createExpression("(" + myQualifierType.getCanonicalText() + " " + expr + ")->(" + myType.getCanonicalText() + ")" + expr + "::" + myMethodRef.getReferenceName()); PsiTypeCastExpression castExpr = (PsiTypeCastExpression)lambdaExpression.getBody(); LOG.assertTrue(castExpr != null); methodRef = (PsiMethodReferenceExpression)castExpr.getOperand(); LOG.assertTrue(methodRef != null); } } } PsiLambdaExpression lambda = LambdaRefactoringUtil.createLambda(methodRef, true); if(lambda == null) { throw new IllegalStateException("Unable to convert method reference to lambda: "+methodRef.getText()); } myExpression = LambdaUtil.extractSingleExpressionFromBody(lambda.getBody()); LOG.assertTrue(myExpression != null); EntryStream.zip(lambda.getParameterList().getParameters(), argumentValues) .forKeyValue((param, newName) -> { String oldName = param.getName(); myExpression = replaceVarReference(myExpression, oldName, newName, context); }); }