private boolean isStructDataTypeCompatibleWithExistingData(Structure structDT,
			Data existingData) {
		DataType existingDataDT = existingData.getBaseDataType();
		if (existingDataDT instanceof Structure) {
			return existingDataDT.isEquivalent(structDT);
		}

		// existing data wasn't a structure, test each location the proposed structure would overwrite
		Address address = existingData.getAddress();
		for (DataTypeComponent dtc : structDT.getDefinedComponents()) {
			Address memberAddress = address.add(dtc.getOffset());
			Data data = listing.getDataAt(memberAddress);
			if (data != null && !isDataTypeCompatibleWithExistingData(dtc.getDataType(), data)) {
				return false;
			}
		}
		boolean isTruncating = structDT.getLength() < existingData.getLength();
		return !isTruncating || allowTruncating;
	}
Logic to test if a Data instance is replaceable with a data type.
Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/dwarf/DWARFDataInstanceHelper.java