public StackComponentWrapper setOffset(int ordinal, int newOffset)
			throws InvalidInputException, IndexOutOfBoundsException {
		final StackComponentWrapper comp = getComponent(ordinal);
		final int oldOffset = comp.getOffset();
		final int compLength = comp.getLength();
		if (newOffset == oldOffset) {
			return comp;
		}

		if ((oldOffset >= parameterOffset) && (newOffset < parameterOffset) ||
			(oldOffset < parameterOffset) && ((newOffset + compLength - 1) >= parameterOffset)) {
			throw new InvalidInputException(
				"Cannot move a stack variable/parameter across the parameter offset.");
		}

		if ((oldOffset >= 0) && (newOffset < 0) ||
			(oldOffset < 0) && ((newOffset + compLength - 1) >= 0)) {
			throw new InvalidInputException(
				"Cannot move a stack variable/parameter across the 0-offset point.");
		}

		StackComponentWrapper existing = getComponentContaining(newOffset);
		if (existing == null) {
			throw new InvalidInputException(
				getHexString(newOffset, true) + " is not an offset in this stack frame.");
		}

		if (!existing.isUndefined() && existing.getOffset() != comp.getOffset()) {
			throw new InvalidInputException("There is already another stack variable at offset " +
				getHexString(newOffset, true) + ".");
		}

		final DataType dt = comp.getDataType();
		final String fieldName = comp.getFieldName();
		final String comment = comp.getComment();

		clearComponent(ordinal);

		int mrl = getMaxLength(newOffset);
		if ((mrl != -1) && (compLength > mrl)) {
			doReplaceAtOffset(oldOffset, dt, compLength, fieldName, comment); // restore component
			throw new InvalidInputException(
				dt.getDisplayName() + " doesn't fit at offset " + getHexString(newOffset, true) +
					". It needs " + compLength + " bytes, but " + mrl + " bytes are available.");
		}

		StackComponentWrapper newComp =
			doReplaceAtOffset(newOffset, dt, compLength, fieldName, comment);
		return newComp;
	}
Effectively moves a component for a defined stack variable if it will fit where it is being
moved to in the stack frame.

@param ordinal the ordinal of the component to move by changing its offset.
@param newOffset the offset to move the variable to.
@return the component representing the stack variable at the new offset.
@throws InvalidInputException if it can't be moved.
@throws IndexOutOfBoundsException if the ordinal is out of bounds
Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/stackeditor/StackFrameDataType.java