private void cleanTree(ProgramModule module) throws NotEmptyException {
		if (module == null || moduleSet.contains(module)) {
			return;
		}
		moduleSet.add(module);

		if (module.getNumChildren() == 0) {
			return;
		}
		/// for each child, if fragment and empty delete the child
		/// otherwise, clean the child
		/// if module has no children, delete it
		Group[] children = module.getChildren();
		for (Group child : children) {
			if (child instanceof ProgramModule) {
				ProgramModule childModule = (ProgramModule) child;
				cleanTree(childModule);
				if (childModule.getNumChildren() == 0) {
					module.removeChild(childModule.getName());
				}
			}
			else {
				ProgramFragment fragment = (ProgramFragment) child;
				if (fragment.isEmpty()) {
					module.removeChild(fragment.getName());
				}
			}
		}
		if (module.getParents().length != 0) {
			try {
				String numKidsPrefix = "   [";
				String currentName = module.getName();
				int prefix = currentName.indexOf(numKidsPrefix);
				String baseName = (prefix < 0) ? currentName : currentName.substring(0, prefix);
				module.setName(baseName + numKidsPrefix + module.getNumChildren() + "]");
			}
			catch (DuplicateNameException e) {
				// ignore
			}
		}
	}
Method cleanTree.
Removes all empty fragments and empty modules

@param module the root branch to be cleaned.  Can be branch or entire tree.
@throws NotEmptyException if attempting to remove a module or fragment that is not empty
Ghidra/Features/Base/src/main/java/ghidra/app/cmd/module/ModuleAlgorithmCmd.java