void addMemoryReferences(Component c, AddressSetView set, CodeUnit cu, int opIndex,
			boolean alwaysConfirm) {

		if (set == null || set.isEmpty()) {
			return;
		}

		Address cuAddr = cu.getMinAddress();

		ReferenceManager refMgr = cu.getProgram().getReferenceManager();
		Reference ref = refMgr.getPrimaryReferenceFrom(cuAddr, opIndex);

		String nonMemType = null;
		if (ref != null) {
			if (ref.isStackReference()) {
				nonMemType = "Stack";
			}
			else if (ref.getToAddress().isRegisterAddress()) {
				nonMemType = "Register";
			}
			else if (ref.isExternalReference()) {
				nonMemType = "External";
			}
		}

		String setSize = null;
		long cnt = set.getNumAddresses();
		if (cnt > 100) {
			setSize = "large";
		}
		if (cnt > 200) {
			setSize = "very large";
		}

		RefType rt = RefTypeFactory.getDefaultMemoryRefType(cu, opIndex, null, false);

		if (alwaysConfirm || nonMemType != null || setSize != null) {
			String op = (opIndex == ReferenceManager.MNEMONIC ? "MNEMONIC" : ("OP-" + opIndex));
			String msg = "Add memory references from " + op + " at " + cu.getMinAddress() +
				" to all code units in your selection?\n" + "Reference Type: " + rt.toString();
			if (setSize != null) {
				msg = msg + "\n \nWarning! A " + setSize +
					" number of addresses have been selected!\n";
			}
			if (nonMemType != null) {
				msg =
					msg + "\n \nWarning! Existing " + nonMemType + " reference(s) will be deleted!";
			}
			int rc = OptionDialog.showOptionDialog(c, "Add Memory References", msg, "OK",
				OptionDialog.WARNING_MESSAGE);
			if (rc != OptionDialog.OPTION_ONE) {
				return;
			}
		}

		BackgroundCommand<Program> cmd =
			new AddMemRefsCmd(cuAddr, set, rt, SourceType.USER_DEFINED, opIndex);
		tool.executeBackgroundCommand(cmd, cu.getProgram());
	}
Check a memory address and warn the user if it has an issue.

@param c parent component or null
@param mem program memory
@param addr address to check
@param refOffset offset from addr
@return addr to be used or null if user cancels
Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/references/ReferencesPlugin.java