private Set<Group> gatherProgramTreeGroups(Program program, String treeName,
			TaskMonitor monitor) throws CancelledException {
		monitor.checkCancelled();
		Listing listing = program.getListing();
		ProgramModule rootModule = listing.getRootModule(treeName);

		Set<Group> set = new HashSet<>();
		addProgramTreeGroupsRecursively(set, rootModule, monitor);

		// The root module name is the name of the program. Don't allow to change it here.
		set.remove(rootModule);
		return set;
	}
Check all the modules and fragments in the tree
Ghidra/Features/Base/src/main/java/ghidra/features/base/replace/handler/ProgramTreeSearchAndReplaceHandler.java