void (@NotNull PsiElement element, @NotNull Color color) { Runnable command; final Document document = PsiDocumentManager.getInstance(element.getProject()).getDocument(element.getContainingFile()); if (isIntLiteralInsideNewJBColorExpression(element)) { command = () -> replaceInt((PsiExpression)element, color.getRGB(), true, color.getAlpha() != 255); } else { PsiNewExpression expression = PsiTreeUtil.getParentOfType(element, PsiNewExpression.class); if (expression == null) return; PsiExpressionList argumentList = expression.getArgumentList(); assert argumentList != null; PsiExpression[] expr = argumentList.getExpressions(); PsiType[] expressionTypes = argumentList.getExpressionTypes(); ColorConstructors type = expressionTypes.length == 0 ? null : getConstructorType(expressionTypes.length, expressionTypes[0]); assert type != null; command = () -> { switch (type) { case INT -> { if (color.getAlpha() == 255) { replaceInt(expr[0], color.getRGB(), true); } else { PsiElementFactory factory = JavaPsiFacade.getElementFactory(argumentList.getProject()); argumentList.add(factory.createExpressionFromText("true", null)); replaceInt(expr[0], color.getRGB() | color.getAlpha() << 24, true, true); } } case INT_BOOL -> { if ("true".equals(expr[1].getText())) { replaceInt(expr[0], color.getRGB() | color.getAlpha() << 24, true, true); } else { if (color.getAlpha() == 255) { replaceInt(expr[0], color.getRGB(), true); } else { PsiElementFactory factory = JavaPsiFacade.getElementFactory(argumentList.getProject()); expr[1].replace(factory.createExpressionFromText("true", null)); replaceInt(expr[0], color.getRGB() | color.getAlpha() << 24, true, true); } } } case INT_x3, INT_x4 -> { replaceInt(expr[0], color.getRed()); replaceInt(expr[1], color.getGreen()); replaceInt(expr[2], color.getBlue()); if (type == ColorConstructors.INT_x4) { replaceInt(expr[3], color.getAlpha()); } else if (color.getAlpha() != 255) { PsiElementFactory factory = JavaPsiFacade.getElementFactory(argumentList.getProject()); String text = String.valueOf(color.getAlpha()); argumentList.add(factory.createExpressionFromText(text, null)); } } case FLOAT_x3, FLOAT_x4 -> { float[] rgba = color.getColorComponents(null); replaceFloat(expr[0], rgba[0]); replaceFloat(expr[1], rgba[1]); replaceFloat(expr[2], rgba[2]); if (type == ColorConstructors.FLOAT_x4) { replaceFloat(expr[3], rgba.length == 4 ? rgba[3] : 0f); } else if (color.getAlpha() != 255) { PsiElementFactory factory = JavaPsiFacade.getElementFactory(argumentList.getProject()); String text = String.valueOf(color.getAlpha()); argumentList.add(factory.createExpressionFromText(text + "f", null)); } } } }; } CommandProcessor.getInstance() .executeCommand(element.getProject(), command, JavaBundle.message("change.color.command.text"), null, document); }