private void addProgramTreeGroupsRecursively(Set<Group> set, Group group, TaskMonitor monitor) {
		set.add(group);
		if (group instanceof ProgramModule module) {
			Group[] children = module.getChildren();
			for (Group child : children) {
				addProgramTreeGroupsRecursively(set, child, monitor);
			}
		}
	}
Check all the modules and fragments in the tree
Ghidra/Features/Base/src/main/java/ghidra/features/base/replace/handler/ProgramTreeSearchAndReplaceHandler.java