ModCommand (@NotNull ActionContext actionContext) { List<NumberConverter> converters = getConverters(actionContext.file()); if (converters.isEmpty()) return ModCommand.nop(); NumberConversionContext context = getContext(actionContext); if (context == null) return ModCommand.nop(); Number number = context.myNumber; String text = context.myText; class Conversion implements ModCommandAction { final NumberConverter myConverter; final String myResult; Conversion(NumberConverter converter, String result) { myConverter = converter; myResult = result; } @Override public @NotNull ModCommand perform(@NotNull ActionContext ctx) { PsiElement element = context.getElement(); if (element == null) return ModCommand.nop(); return ModCommand.psiUpdate(element, e -> replace(e, myResult)); } @Override public @Nullable Presentation getPresentation(@NotNull ActionContext ctx) { if (context.getElement() == null) return null; return Presentation.of(toString()); } @Override public @NlsSafe String toString() { return StringUtil.capitalize(myConverter.toString()) + " (" + myResult + ")"; } @Override public @NotNull String getFamilyName() { return myConverter.toString(); } } List<Conversion> list = getConverters(actionContext.file()).stream() .map(converter -> new Conversion(converter, converter.getConvertedText(text, number))) .filter(conversion -> conversion.myResult != null) .collect(Collectors.toList()); return new ModChooseAction(LangBundle.message("intention.name.convert.number.to.title"), list); }