ModCommand (@NotNull ActionContext context, @NotNull PsiIdentifier element) { final PsiJavaCodeReferenceElement refExpr = (PsiJavaCodeReferenceElement)element.getParent(); ThreeState expandAll = myExpandAll == ThreeState.UNSURE && refExpr.getParent() instanceof PsiImportStaticStatement ? ThreeState.YES : myExpandAll; return switch (expandAll) { case YES -> ModCommand.psiUpdate(refExpr, refExprCopy -> { PsiImportStaticStatement staticImport = getImportStaticStatement(refExprCopy); List<PsiJavaCodeReferenceElement> expressionToExpand = collectReferencesThrough( refExprCopy.getContainingFile(), refExprCopy, staticImport); replaceAllAndDeleteImport(expressionToExpand, refExprCopy, staticImport); }); case NO -> ModCommand.psiUpdate(refExpr, refExprCopy -> expand(refExprCopy, getImportStaticStatement(refExprCopy))); case UNSURE -> { final PsiImportStaticStatement staticImport = Objects.requireNonNull(getImportStaticStatement(refExpr)); List<PsiJavaCodeReferenceElement> expressionToExpand = collectReferencesThrough(context.file(), refExpr, staticImport); if (expressionToExpand.isEmpty()) { yield ModCommand.psiUpdate(context, updater -> { PsiImportStaticStatement staticImportCopy = updater.getWritable(staticImport); PsiJavaCodeReferenceElement refExprCopy = updater.getWritable(refExpr); expand(refExprCopy, staticImportCopy); staticImportCopy.delete(); }); } yield new ModChooseAction(JavaBundle.message("multiple.usages.of.static.import.found"), List.of(new ExpandStaticImportAction(false), new ExpandStaticImportAction(true))); } }; }