private boolean pasteNode(ProgramDnDTree tree, ProgramNode destNode, ProgramNode nodeToPaste) {

		ProgramModule targetModule = destNode.getModule();
		ProgramModule module = nodeToPaste.getModule();
		ProgramFragment fragment = nodeToPaste.getFragment();

		if (module == null && fragment == null) {
			actionManager.clearCut(nodeToPaste);
			Msg.showError(this, null, "Paste from Clipboard Failed",
				"Could not paste " + nodeToPaste + " at " + targetModule.getName());
			return false;
		}

		boolean pasteOK = false;
		try {
			if (module != null) {
				pasteOK = pasteModule(tree, destNode, nodeToPaste, targetModule, module);
			}
			else {
				pasteOK = pasteFragment(tree, nodeToPaste, targetModule, fragment);
			}

			// don't match the expansion state unless the destination
			// node is already expanded
			if (tree.isExpanded(destNode.getTreePath())) {
				ProgramNode newnode = tree.getChild(destNode, nodeToPaste.getName());
				if (newnode != null) {
					tree.matchExpansionState(nodeToPaste, newnode);
				}
			}
			return pasteOK;

		}
		catch (CircularDependencyException e) {
			Msg.showError(this, null, "Paste from Clipboard Failed", e.getMessage());
		}
		catch (DuplicateGroupException e) {
			// handled below
		}
		catch (NotFoundException e) {
			Msg.showError(this, null, "Paste from Clipboard Failed", e.getMessage());
		}

		removeFromClipboard(tree, nodeToPaste);
		return false;
	}
Manage paste operations for the Program Tree.
Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/programtree/PasteManager.java