public static void getVariableRefs(Variable var, List<Reference> xrefs, List<Reference> offcuts,
			int max) {

		Address addr = var.getMinAddress();
		if (addr == null) {
			return;
		}

		Program program = var.getFunction().getProgram();
		ReferenceManager refMgr = program.getReferenceManager();
		Reference[] refs = refMgr.getReferencesTo(var);
		int total = 0;
		for (Reference vref : refs) {
			if (total++ - max == 0) {
				break;
			}

			if (addr.equals(vref.getToAddress())) {
				xrefs.add(vref);
			}
			else {
				offcuts.add(vref);
			}
		}
	}
Populates the provided lists with the direct and offcut xrefs to the specified variable

@param var     variable to get references
@param xrefs   list to put direct references in
@param offcuts list to put offcut references in
@param max max number of xrefs to get, or -1 to get all references
Ghidra/Features/Base/src/main/java/ghidra/app/util/XReferenceUtils.java