private void checkForReplace(int rowIndex, DataType datatype, int length)
			throws InvalidDataTypeException {
		DataTypeComponent dtc = getComponent(rowIndex);
		if (dtc == null) {
			throw new InvalidDataTypeException("Invalid component selection");
		}
		if (!(viewComposite instanceof Structure struct)) {
			return;
		}
		if (struct.isPackingEnabled()) {
			return;
		}
		if (isAtEnd(rowIndex)) {
			return;
		}

		// Does the new data type fit by replacing the component at index.

		// Get the current data type at the index.
		int currentCompSize = dtc.getLength();
		int newCompSize = length;
		int sizeDiff = newCompSize - currentCompSize;

		if (sizeDiff <= 0) {
			return;
		}

		int undefinedSpaceAvail = getNumUndefinedBytesAfter(dtc);
		if (sizeDiff > undefinedSpaceAvail) {
			int spaceNeeded = sizeDiff - undefinedSpaceAvail;
			String msg =
				newCompSize + " byte replacement at 0x" + Integer.toHexString(dtc.getOffset());
			if (struct.getDefinedComponentAtOrAfterOffset(dtc.getOffset() + 1) == null) {
				// suggest growing structure
				int suggestedSize = getLength() + spaceNeeded;
				throw new InvalidDataTypeException(
					msg + " requires structure length of " + suggestedSize + "-bytes.");
			}
			// suggest insert bytes (NOTE: in the future a conflict removal/grow could be offered)
			throw new InvalidDataTypeException(
				msg + " requires " + spaceNeeded + " additional undefined bytes.");
		}
	}
Check to see if the specified data type fits in place of the data type
at the specified index of the data structure.<BR>
If the new data type is smaller, then it can replace the current one.<BR>
If the new data type is larger, then replace if we have enough
undefined bytes following the specified index.

@param rowIndex index of the row (component).
@param datatype the type
@param length component length
@throws InvalidDataTypeException if check fails
Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/CompEditorModel.java