public static Structure createStructureDataTypeInStrucuture(Program program, Address address,
			int[] fromPath, int[] toPath, String structureName, boolean makeUniqueName) {

		if (structureName == null) {
			throw new IllegalArgumentException("Structure name cannot " + "be null.");
		}

		Listing listing = program.getListing();

		Data data = listing.getDataContaining(address);
		Data comp1 = data.getComponent(fromPath);
		Data comp2 = data.getComponent(toPath);
		if ((comp1 == null) || (comp2 == null)) {
			throw new IllegalArgumentException("Invalid selection");
		}

		int dataLength = (comp2.getParentOffset() + comp2.getLength()) - comp1.getParentOffset();
		if (dataLength <= 0) {
			throw new IllegalArgumentException("Data length must be positive, not " + dataLength);
		}

		// make sure there is a valid parent structure
		Data firstComponent = data.getComponent(fromPath);
		DataType parentDataType = firstComponent.getParent().getBaseDataType();
		if (!(parentDataType instanceof Structure)) {
			throw new IllegalArgumentException("New structure is not in a structure");
		}

		// create the context
		DataTypeProviderContext providerContext = new ProgramStructureProviderContext(program,
			data.getMinAddress(), (Structure) parentDataType, comp1.getParentOffset());

		String name = structureName;
		if (makeUniqueName) {
			name = providerContext.getUniqueName(name);
		}

		Structure newStructure = new StructureDataType(name, 0, program.getDataTypeManager());

		initializeStructureFromContext(newStructure, providerContext, dataLength);

		return newStructure;
	}
Creates a {@link StructureDataType} instance, which is inside of
another structure, based upon the information provided.  The instance
will not be placed in memory.

@param  program The program to which the structure will belong.
@param  address The address of the structure.
@param  fromPath The path to the first element in the parent structure
        that will be in the new structure.
@param  toPath The path to the last element in the parent structure
        that will be in the new structure.
@param  structureName the name of the structure to create
@param  makeUniqueName True indicates that the provided name should be
        altered as necessary in order to make it unique in the program.
@return A new structure not yet added to memory.
@throws IllegalArgumentException for the following conditions:
        <ul>
             <li>if <code>structureName</code> is <code>null</code></li>
             <li>if the component at <code>fromPath</code> or the component
                 at <code>toPath</code> are null</li>
             <li>if there is not data to add to the structure</li>
             <li>if the parent data type is not a structure</li>
        </ul>
Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/StructureFactory.java