void (@NotNull PsiElement element, @NotNull Color color) { Runnable command = null; if (element instanceof PsiNewExpression expr) { PsiExpressionList argumentList = expr.getArgumentList(); assert argumentList != null; command = () -> replaceConstructorArgs(color, argumentList); } if (element instanceof PsiMethodCallExpression methodCall) { PsiReferenceExpression methodExpression = methodCall.getMethodExpression(); String methodName = methodExpression.getReferenceName(); if (COLOR.equals(methodName) || GRAY.equals(methodName)) { command = () -> replaceColor(methodCall, getScaledRgbCallText(color)); } else if (RGB.equals(methodName) || GRAY_RGB.equals(methodName)) { command = () -> replaceColor(methodCall, getRgbCallText(color)); } else if (HSB.equals(methodName)) { command = () -> replaceColor(methodCall, getHsbCallText(color)); } } if (command != null) { Document document = PsiDocumentManager.getInstance(element.getProject()).getDocument(element.getContainingFile()); CommandProcessor.getInstance() .executeCommand(element.getProject(), command, JavaBundle.message("change.color.command.text"), null, document); } }