private static void replaceLibraryByAdded(@NotNull ModifiableRootModel model, int toReplace) {
    OrderEntry[] entries = model.getOrderEntries();
    LibraryOrderEntry newEntry = (LibraryOrderEntry)entries[entries.length - 1];
    LibraryOrderEntry libraryEntry = (LibraryOrderEntry)entries[toReplace];
    boolean exported = libraryEntry.isExported();
    DependencyScope scope = libraryEntry.getScope();
    model.removeOrderEntry(libraryEntry);
    newEntry.setExported(exported);
    newEntry.setScope(scope);
    final OrderEntry[] newEntries = new OrderEntry[entries.length-1];
    System.arraycopy(entries, 0, newEntries, 0, toReplace);
    newEntries[toReplace] = newEntry;
    System.arraycopy(entries, toReplace + 1, newEntries, toReplace + 1, entries.length - toReplace - 2);
    model.rearrangeOrderEntries(newEntries);
  }
private static void replaceLibraryByAdded(@NotNull ModifiableRootModel model, int toReplace)