static boolean addDataTypeToStructure(Structure structure, int offset, DataType dataType,
			String fieldName, TaskMonitor monitor) throws CancelledException {

		if (structure.isPackingEnabled()) {
			throw new IllegalArgumentException(
				"Packed structures are not supported by this method");
		}

		if (!canAdd(structure, offset, dataType.getLength(), true, monitor)) {
			return false;
		}

		if (structure.isZeroLength() || offset >= structure.getLength()) {
			structure.insertAtOffset(offset, dataType, -1, fieldName, null);
		}
		else {
			// if not enough room, grow the structure
			int roomForData = structure.getLength() - (offset + dataType.getLength());
			if (roomForData < 0) {
				structure.growStructure(-roomForData);
			}
			structure.replaceAtOffset(offset, dataType, -1, fieldName, null);
		}
		return true;
	}
Method to add a field to the given structure. If the structure already has data 
at the given offset, don't replace. If there is undefined data there then replace 
it with the data type. If the structure empty, insert the data type at the given offset. 
If the structure is not big enough and not-empty, grow it so there is room to replace.
See {@link #canAdd(Structure, int, int, boolean, TaskMonitor)} for ensuring operation will be 
successful.
@param structure the given structure
@param offset the offset to add a field
@param dataType the data type to add to the field at the given offset
@param fieldName the name of field
@param monitor task monitor
@return true if the structure was updated or false if the data could not be added
@throws IllegalArgumentException if issue inserting or replacing data type into structure
@throws CancelledException if cancelled
Ghidra/Features/Decompiler/ghidra_scripts/classrecovery/EditStructureUtils.java