void autoRenameCallback(ActionContext context) {

        Object obj = context.getContextObject();
        if (obj instanceof ProgramNode) {
            ProgramNode node = (ProgramNode) obj;

			CompoundCmd<Program> cmd = new CompoundCmd<>("Auto Rename Fragment(s)");
            SymbolTable symTable = currentProgram.getSymbolTable();

            // Find selected Fragments
            TreePath[] selectedPaths = node.getTree().getSelectionPaths();
            boolean ignoreDuplicateNames = (selectedPaths.length > 1);
            for (int i = 0; i < selectedPaths.length; i++) {
                ProgramNode n = (ProgramNode) selectedPaths[i].getLastPathComponent();
                if (!n.isFragment())
                    continue;

                // Rename Fragment using minimum address label	
                ProgramFragment f = n.getFragment();
                Address a = f.getMinAddress();
                if (a == null)
                    continue; // empty Fragment
                Symbol s = symTable.getPrimarySymbol(a);
                if (s != null) {
                    cmd.add(new RenameCmd(f.getTreeName(), false, f.getName(), s.getName(), 
                    	ignoreDuplicateNames));
                }
            }

            if (cmd.size() > 0 && !tool.execute(cmd, currentProgram)) {
                tool.setStatusInfo("Error renaming fragment: " + cmd.getStatusMsg());
            }
        }
    }
Perform Fragment Auto-Rename on selected Fragments.
Rename is performed on all selected Fragments within Program Tree.
Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/module/AutoRenamePlugin.java