@Override
	public DataTypeComponent replace(int rowIndex, DataType datatype, int length)
			throws UsrException {

		if (isEditingField()) {
			endFieldEditing();
		}

		if (rowIndex == getNumComponents()) {
			// Insert if at blank last line.
			return insert(rowIndex, datatype, length);
		}

		// Get the current data type at the index.
		DataTypeComponent oldDtc = getComponent(rowIndex);
		if (oldDtc == null) {
			return null;
		}

		checkIsAllowableDataType(datatype);

		int oldCompSize = oldDtc.getLength();
		int newCompSize = length;
		int sizeDiff = newCompSize - oldCompSize;

		// New one is larger so check to make sure it will fit.
		if (!isAtEnd(rowIndex) && sizeDiff > 0) {
			checkForReplace(rowIndex, datatype, newCompSize);
		}

		// Replace the component at index.
		DataTypeComponent dtc =
			replace(rowIndex, datatype, newCompSize, oldDtc.getFieldName(), oldDtc.getComment());

		fixSelection();
		selectionChanged();
		return dtc;
	}
Replace the structure components from the start index to the end index
(inclusive) with as many of the specified data type as will fit.
Pad any left over bytes as undefined bytes.

@param startRowIndex index of the first row (component) to replace.
@param endRowIndex index of the last row (component) to replace.
@param datatype the new data type
@param length the length of the range
@param monitor the task monitor
@return true if the replacement worked

@throws InvalidDataTypeException if the structure being edited is part
        of the data type being inserted
@throws InsufficientBytesException if there aren't enough bytes in the specified range
@throws CancelledException if the work is cancelled
Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/CompEditorModel.java