private static List<RootModelImpl> getSortedChangedModels(
      Collection<ModifiableRootModel> rootModels, ModifiableModuleModel moduleModel) {
    List<RootModelImpl> result = ContainerUtil.newArrayListWithCapacity(rootModels.size());

    for (ModifiableRootModel model : rootModels) {
      RootModelImpl rootModel = (RootModelImpl) model;
      if (rootModel.isChanged()) {
        result.add(rootModel);
      }
    }

    DFSTBuilder<RootModelImpl> builder = createDFSTBuilder(result, moduleModel);
    Collections.sort(result, builder.comparator());

    return result;
  }
 @NotNull
 public static List<String> getChildrenValueAttributes(
     @NotNull Element parent, @NotNull String childTagName) {
   List<Element> children = parent.getChildren(childTagName);
   if (children.isEmpty()) {
     return Collections.emptyList();
   }
   if (children.size() == 1) {
     String value = children.iterator().next().getAttributeValue(VALUE_ATTR_NAME);
     return value == null ? Collections.<String>emptyList() : Collections.singletonList(value);
   }
   List<String> values = ContainerUtil.newArrayListWithCapacity(children.size());
   for (Element child : children) {
     String value = child.getAttributeValue(VALUE_ATTR_NAME);
     if (value != null) {
       values.add(value);
     }
   }
   return values;
 }
  @NotNull
  private static List<VFileEvent> validateEvents(@NotNull List<VFileEvent> events) {
    final List<EventWrapper> deletionEvents = ContainerUtil.newArrayList();
    for (int i = 0, size = events.size(); i < size; i++) {
      final VFileEvent event = events.get(i);
      if (event instanceof VFileDeleteEvent && event.isValid()) {
        deletionEvents.add(new EventWrapper((VFileDeleteEvent) event, i));
      }
    }

    ContainerUtil.quickSort(deletionEvents, DEPTH_COMPARATOR);

    final TIntHashSet invalidIDs = new TIntHashSet(deletionEvents.size());
    final Set<VirtualFile> dirsToBeDeleted = new THashSet<VirtualFile>(deletionEvents.size());
    nextEvent:
    for (EventWrapper wrapper : deletionEvents) {
      final VirtualFile candidate = wrapper.event.getFile();
      VirtualFile parent = candidate;
      while (parent != null) {
        if (dirsToBeDeleted.contains(parent)) {
          invalidIDs.add(wrapper.id);
          continue nextEvent;
        }
        parent = parent.getParent();
      }

      if (candidate.isDirectory()) {
        dirsToBeDeleted.add(candidate);
      }
    }

    final List<VFileEvent> filtered =
        ContainerUtil.newArrayListWithCapacity(events.size() - invalidIDs.size());
    for (int i = 0, size = events.size(); i < size; i++) {
      final VFileEvent event = events.get(i);
      if (event.isValid() && !(event instanceof VFileDeleteEvent && invalidIDs.contains(i))) {
        filtered.add(event);
      }
    }
    return filtered;
  }
Esempio n. 4
0
  @NotNull
  private static FSRecords.NameId[] persistAllChildren(
      @NotNull final VirtualFile file, final int id, @NotNull FSRecords.NameId[] current) {
    final NewVirtualFileSystem fs = replaceWithNativeFS(getDelegate(file));

    String[] delegateNames = VfsUtil.filterNames(fs.list(file));
    if (delegateNames.length == 0 && current.length > 0) {
      return current;
    }

    Set<String> toAdd = ContainerUtil.newHashSet(delegateNames);
    for (FSRecords.NameId nameId : current) {
      toAdd.remove(nameId.name.toString());
    }

    final TIntArrayList childrenIds = new TIntArrayList(current.length + toAdd.size());
    final List<FSRecords.NameId> nameIds =
        ContainerUtil.newArrayListWithCapacity(current.length + toAdd.size());
    for (FSRecords.NameId nameId : current) {
      childrenIds.add(nameId.id);
      nameIds.add(nameId);
    }
    for (String newName : toAdd) {
      FakeVirtualFile child = new FakeVirtualFile(file, newName);
      FileAttributes attributes = fs.getAttributes(child);
      if (attributes != null) {
        int childId = createAndFillRecord(fs, child, id, attributes);
        childrenIds.add(childId);
        nameIds.add(new FSRecords.NameId(childId, FileNameCache.storeName(newName), newName));
      }
    }

    FSRecords.updateList(id, childrenIds.toNativeArray());
    setChildrenCached(id);

    return nameIds.toArray(new FSRecords.NameId[nameIds.size()]);
  }