private int getSelectedVariableStorageSize(ListingActionContext context) {
		ProgramLocation loc = context.getLocation();

		if (loc instanceof VariableTypeFieldLocation) {
			Variable var = ((VariableTypeFieldLocation) loc).getVariable();
			Function func = var.getFunction();
			if ((var instanceof Parameter) && !func.hasCustomVariableStorage()) {
				return -1; // do not constrain size
			}

			VariableStorage storage = var.getVariableStorage();
			if (storage.isValid() && !storage.isStackStorage()) {
				return storage.size();
			}
		}

		return -1;
	}
Returns the storage size of the variable at the current cursor location in the
given listing/program.

@return -1 if the selected item in the listing is not a variable type
Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/function/ChooseDataTypeAction.java