void autoLabelRenameCallback(ListingActionContext context) {

        // Get selected fragment
    	ProgramLocation location = context.getLocation();
        if (location instanceof LabelFieldLocation && currentProgram != null) {

            LabelFieldLocation labelField = (LabelFieldLocation) location;
            String label = labelField.getName();
            String treeName = treeService.getViewedTreeName();
            ProgramFragment fragment = currentProgram.getListing().getFragment(treeName, labelField.getAddress());
            if (!label.equals(fragment.getName())) {
                RenameCmd cmd = new RenameCmd(treeName, false, fragment.getName(), label);
                if (!tool.execute(cmd, currentProgram)) {
                    tool.setStatusInfo("Error renaming fragment: " + cmd.getStatusMsg());
                }
            }
        }
    }
Perform Fragment Rename based upon the active LabelFieldLocation object.
Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/module/AutoRenamePlugin.java