public boolean updateReference(ExternalReference editRef, CodeUnit fromCodeUnit, String extName,
			String path, Address addr, String label) {

		Program p = fromCodeUnit.getProgram();

		ExternalLocation oldExtLoc = editRef.getExternalLocation();
		String oldExtName = oldExtLoc.getLibraryName();

		CompoundCmd<Program> cmd = new CompoundCmd<>("Update External Reference");

		// TODO: Add RefType entry to External Reference editor panel (assume unchanged to avoid merge conflict)

		// Update performed as ADD since only a single ref will be permitted
		buildAddExtRefCmd(cmd, p, fromCodeUnit.getMinAddress(), editRef.getOperandIndex(), extName,
			path, addr, label, editRef.getReferenceType());

		if (tool.execute(cmd, p)) {
			if (!p.getReferenceManager().getReferencesTo(
				oldExtLoc.getExternalSpaceAddress()).hasNext() &&
				OptionDialog.YES_OPTION == OptionDialog.showYesNoDialog(tool.getActiveWindow(),
					"Delete Unused External Location?",
					"Remove unused external location symbol '" + oldExtLoc.toString() + "'?")) {
				deleteExternalLocation(p, oldExtLoc);

				if (!p.getExternalManager().getExternalLocations(oldExtName).hasNext() &&
					OptionDialog.YES_OPTION == OptionDialog.showYesNoDialog(tool.getActiveWindow(),
						"Delete Unused Library Name?",
						"Remove unused library symbol '" + oldExtName + "'?")) {
					RemoveExternalNameCmd rmCmd = new RemoveExternalNameCmd(oldExtName);
					tool.execute(rmCmd, p);
				}
			}
			return true;
		}
		return false;
	}
Add memory reference

@param fromCodeUnit
@param opIndex
@param toAddr
@param isOffsetRef
@param offset
@param refType
@return true if add was successful
Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/references/ReferencesPlugin.java