void (@NotNull PsiElement element) { final PsiMethodCallExpression call = (PsiMethodCallExpression)element; final PsiReferenceExpression methodExpression = call.getMethodExpression(); @NonNls final String methodName = methodExpression.getReferenceName(); if (methodName == null) { return; } @NonNls final StringBuilder newExpression = new StringBuilder(); final PsiElement qualifier = methodExpression.getQualifier(); if (qualifier == null) { final PsiMethod method = call.resolveMethod(); assert method != null; final PsiClass aClass = method.getContainingClass(); assert aClass != null; final String qualifiedName = aClass.getQualifiedName(); assert qualifiedName != null; final PsiClass containingClass = PsiTreeUtil.getParentOfType(element, PsiClass.class); if (!InheritanceUtil.isInheritor(containingClass, "junit.framework.Assert") && !ImportUtils.addStaticImport(qualifiedName, "assertEquals", element)) { newExpression.append(qualifiedName).append('.'); } } else { newExpression.append(qualifier.getText()).append('.'); } newExpression.append("assertEquals("); final String postfix = methodName.substring("assert".length()); final String literal = StringUtil.toLowerCase(postfix); final PsiExpressionList argumentList = call.getArgumentList(); final PsiExpression[] arguments = argumentList.getExpressions(); final CommentTracker commentTracker = new CommentTracker(); if (arguments.length > 1) { newExpression.append(commentTracker.text(arguments[0])).append(", "); } final PsiExpression lastArgument = arguments[arguments.length - 1]; if (lastArgument instanceof PsiBinaryExpression binaryExpression) { final IElementType tokenType = binaryExpression.getOperationTokenType(); if (("assertTrue".equals(methodName) && JavaTokenType.EQEQ.equals(tokenType)) || ("assertFalse".equals(methodName) && JavaTokenType.NE.equals(tokenType))) { final PsiExpression lhs = binaryExpression.getLOperand(); newExpression.append(commentTracker.text(lhs)).append(", "); final PsiExpression rhs = binaryExpression.getROperand(); if (rhs != null) { newExpression.append(commentTracker.text(rhs)); } } else { newExpression.append(literal).append(", ").append(commentTracker.text(lastArgument)); } } else { newExpression.append(literal).append(", ").append(commentTracker.text(lastArgument)); } newExpression.append(')'); PsiReplacementUtil.replaceExpression(call, newExpression.toString(), commentTracker); }