<commit_before>/*
 * Copyright 2000-2009 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.intellij.openapi.vcs.changes.conflicts;

import com.intellij.openapi.application.Application;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.EditorFactory;
import com.intellij.openapi.editor.event.DocumentAdapter;
import com.intellij.openapi.editor.event.DocumentEvent;
import com.intellij.openapi.fileEditor.FileDocumentManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.vcs.FilePath;
import com.intellij.openapi.vcs.FileStatusManager;
import com.intellij.openapi.vcs.ZipperUpdater;
import com.intellij.openapi.vcs.changes.*;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.ui.EditorNotifications;
import com.intellij.util.NullableFunction;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.containers.hash.HashSet;
import com.intellij.util.xmlb.XmlSerializer;
import org.jdom.Element;
import org.jetbrains.annotations.NotNull;

import java.util.*;

/**
 * @author <NAME>
 */
public class ChangelistConflictTracker {

  private final Map<String, Conflict> myConflicts = Collections.synchronizedMap(new LinkedHashMap<String, Conflict>());

  private final Options myOptions = new Options();
  private final Project myProject;

  private final ChangeListManager myChangeListManager;
  private final EditorNotifications myEditorNotifications;
  private final ChangeListAdapter myChangeListListener;

  private final FileDocumentManager myDocumentManager;
  private final DocumentAdapter myDocumentListener;

  private final FileStatusManager myFileStatusManager;
  private final Set<VirtualFile> myCheckSet;
  private final Object myCheckSetLock;

  public ChangelistConflictTracker(@NotNull Project project,
                                   @NotNull ChangeListManager changeListManager,
                                   @NotNull FileStatusManager fileStatusManager,
                                   @NotNull EditorNotifications editorNotifications) {
    myProject = project;

    myChangeListManager = changeListManager;
    myEditorNotifications = editorNotifications;
    myDocumentManager = FileDocumentManager.getInstance();
    myFileStatusManager = fileStatusManager;
    myCheckSetLock = new Object();
    myCheckSet = new HashSet<VirtualFile>();

    final Application application = ApplicationManager.getApplication();
    final ZipperUpdater zipperUpdater = new ZipperUpdater(300, myProject);
    final Runnable runnable = new Runnable() {
      @Override
      public void run() {
        if (application.isDisposed() || myProject.isDisposed() || !myProject.isOpen()) return;
        final Set<VirtualFile> localSet;
        synchronized (myCheckSetLock) {
          localSet = new HashSet<VirtualFile>();
          localSet.addAll(myCheckSet);
          myCheckSet.clear();
        }
        checkFiles(localSet);
      }
    };
    myDocumentListener = new DocumentAdapter() {
      @Override
      public void documentChanged(DocumentEvent e) {
        if (!myOptions.TRACKING_ENABLED) {
          return;
        }<commit_msg>IDEA-97629 VCS: npe in ChangelistConflictTracker<commit_after>/*
 * Copyright 2000-2009 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.intellij.openapi.vcs.changes.conflicts;

import com.intellij.openapi.application.Application;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.EditorFactory;
import com.intellij.openapi.editor.event.DocumentAdapter;
import com.intellij.openapi.editor.event.DocumentEvent;
import com.intellij.openapi.fileEditor.FileDocumentManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.Computable;
import com.intellij.openapi.vcs.FilePath;
import com.intellij.openapi.vcs.FileStatusManager;
import com.intellij.openapi.vcs.ZipperUpdater;
import com.intellij.openapi.vcs.changes.*;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.ui.EditorNotifications;
import com.intellij.util.NullableFunction;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.containers.hash.HashSet;
import com.intellij.util.xmlb.XmlSerializer;
import org.jdom.Element;
import org.jetbrains.annotations.NotNull;

import java.util.*;

/**
 * @author <NAME>
 */
public class ChangelistConflictTracker {

  private final Map<String, Conflict> myConflicts = Collections.synchronizedMap(new LinkedHashMap<String, Conflict>());

  private final Options myOptions = new Options();
  private final Project myProject;

  private final ChangeListManager myChangeListManager;
  private final EditorNotifications myEditorNotifications;
  private final ChangeListAdapter myChangeListListener;

  private final FileDocumentManager myDocumentManager;
  private final DocumentAdapter myDocumentListener;

  private final FileStatusManager myFileStatusManager;
  private final Set<VirtualFile> myCheckSet;
  private final Object myCheckSetLock;

  public ChangelistConflictTracker(@NotNull Project project,
                                   @NotNull ChangeListManager changeListManager,
                                   @NotNull FileStatusManager fileStatusManager,
                                   @NotNull EditorNotifications editorNotifications) {
    myProject = project;

    myChangeListManager = changeListManager;
    myEditorNotifications = editorNotifications;
    myDocumentManager = FileDocumentManager.getInstance();
    myFileStatusManager = fileStatusManager;
    myCheckSetLock = new Object();
    myCheckSet = new HashSet<VirtualFile>();

    final Application application = ApplicationManager.getApplication();
    final ZipperUpdater zipperUpdater = new ZipperUpdater(300, myProject);
    final Runnable runnable = new Runnable() {
      @Override
      public void run() {
        if (Boolean.TRUE.equals(application.runReadAction(new Computable<Boolean>() {
          @Override
          public Boolean compute() {
            return (application.isDisposed() || myProject.isDisposed() || !myProject.isOpen());
          }
        }))) {
          return;
        }
        final Set<VirtualFile> localSet;
        synchronized (myCheckSetLock) {
          localSet = new HashSet<VirtualFile>();
          localSet.addAll(myCheckSet);
          myCheckSet.clear();
        }
        checkFiles(localSet);
      }
    };
    myDocumentListener = new DocumentAdapter() {
      @Override
      public void documentChanged(DocumentEvent e) {
        if (!myOptions.TRACKING_ENABLED) {
          return;
        }
{'fraction_non_alphanumeric': 0.08325996729971073, 'fraction_numerical': 0.004401962017356307, 'mean_word_length': 3.9268897149938042, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3528527', 'n_tokens_mistral': 2193, 'n_tokens_neox': 2146, 'n_words': 535}