<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.roots.impl;

import com.intellij.openapi.module.Module;
import com.intellij.openapi.roots.OrderEntry;
import com.intellij.openapi.roots.OrderRootType;
import com.intellij.openapi.roots.RootPolicy;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.ArrayFactory;
import com.intellij.util.ArrayUtil;
import com.intellij.util.BitUtil;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.TestOnly;

import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public final class DirectoryInfo {
  public static final int MAX_ROOT_TYPE_ID = (1 << (Byte.SIZE - 2)) - 1;
  private final Module module; // module to which content it belongs or null
  private final VirtualFile libraryClassRoot; // class root in library
  private final VirtualFile contentRoot;
  private final VirtualFile sourceRoot;

  private static final byte MODULE_SOURCE_FLAG = 1; // set if files in this directory belongs to sources of the module (if field 'module' is not null)
  private static final byte LIBRARY_SOURCE_FLAG = 2; // set if it's a directory with sources of some library
  private final byte sourceRootTypeData;//two least significant bits are used for MODULE_SOURCE_FLAG and LIBRARY_SOURCE_FLAG, the remaining bits store module root type id (source/tests/resources/...)

  /**
   * orderEntry to (classes of) which a directory belongs
   * MUST BE SORTED WITH {@link #BY_OWNER_MODULE}
   */
  private final OrderEntry[] orderEntries;

  public static DirectoryInfo createNew() {
    return new DirectoryInfo(null, null, null, null, (byte)0, null);
  }

  private DirectoryInfo(Module module,
                        VirtualFile contentRoot,
                        VirtualFile sourceRoot,
                        VirtualFile libraryClassRoot,
                        byte sourceRootTypeData,
                        OrderEntry[] orderEntries) {
    this.module = module;
    this.libraryClassRoot = libraryClassRoot;
    this.contentRoot = contentRoot;
    this.sourceRoot = sourceRoot;
    this.sourceRootTypeData = sourceRootTypeData;
    this.orderEntries = orderEntries;
  }

  @Override
  public boolean equals(Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;

    DirectoryInfo info = (DirectoryInfo)o;

    return sourceRootTypeData == info.sourceRootTypeData &&
           Comparing.equal(contentRoot, info.contentRoot) &&
           Comparing.equal(libraryClassRoot, info.libraryClassRoot) &&
           Comparing.equal(module, info.module) &&
           Arrays.equals(orderEntries, info.orderEntries) &&
           Comparing.equal(sourceRoot, info.sourceRoot);
  }

  @Override
  public int hashCode() {
    int result = module != null ? module.hashCode() : 0;
    result = 31 * result + (libraryClassRoot != null ? libraryClassRoot.hashCode() : 0);
    result = 31 * result + (contentRoot != null ? contentRoot.hashCode() : 0);
    result = 31 * result + (sourceRoot != null ? sourceRoot.hashCode() : 0);
    result = 31 * result + (int)sourceRootTypeData;
    return result;
  }

  @SuppressWarnings({"HardCodedStringLiteral"})
  public String toString() {
    return "DirectoryInfo{" +
           "module=" + getModule() +
           ", isInModuleSource=" + isInModuleSource() +
           ", rootTypeId=" + getSourceRootTypeId() +
           ", isInLibrarySource=" + isInLibrarySource() +
           ", libraryClassRoot=" + getLibraryClassRoot() +
           ", contentRoot=" + getContentRoot() +
           ", sourceRoot=" + getSourceRoot() +
           "}";
  }

  @NotNull
  public OrderEntry[] getOrderEntries() {
    OrderEntry[] entries = orderEntries;
    return entries == null ? OrderEntry.EMPTY_ARRAY : entries;
  }

  @Nullable
  OrderEntry findOrderEntryWithOwnerModule(@NotNull Module ownerModule) {
    OrderEntry[] entries = orderEntries;
    if (entries == null) {
      return null;
    }
    if (entries.length < 10) {
      for (OrderEntry entry : entries) {<commit_msg>display order entries in DirectoryInfo.toString<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.roots.impl;

import com.intellij.openapi.module.Module;
import com.intellij.openapi.roots.OrderEntry;
import com.intellij.openapi.roots.OrderRootType;
import com.intellij.openapi.roots.RootPolicy;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.ArrayFactory;
import com.intellij.util.ArrayUtil;
import com.intellij.util.BitUtil;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.TestOnly;

import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public final class DirectoryInfo {
  public static final int MAX_ROOT_TYPE_ID = (1 << (Byte.SIZE - 2)) - 1;
  private final Module module; // module to which content it belongs or null
  private final VirtualFile libraryClassRoot; // class root in library
  private final VirtualFile contentRoot;
  private final VirtualFile sourceRoot;

  private static final byte MODULE_SOURCE_FLAG = 1; // set if files in this directory belongs to sources of the module (if field 'module' is not null)
  private static final byte LIBRARY_SOURCE_FLAG = 2; // set if it's a directory with sources of some library
  private final byte sourceRootTypeData;//two least significant bits are used for MODULE_SOURCE_FLAG and LIBRARY_SOURCE_FLAG, the remaining bits store module root type id (source/tests/resources/...)

  /**
   * orderEntry to (classes of) which a directory belongs
   * MUST BE SORTED WITH {@link #BY_OWNER_MODULE}
   */
  private final OrderEntry[] orderEntries;

  public static DirectoryInfo createNew() {
    return new DirectoryInfo(null, null, null, null, (byte)0, null);
  }

  private DirectoryInfo(Module module,
                        VirtualFile contentRoot,
                        VirtualFile sourceRoot,
                        VirtualFile libraryClassRoot,
                        byte sourceRootTypeData,
                        OrderEntry[] orderEntries) {
    this.module = module;
    this.libraryClassRoot = libraryClassRoot;
    this.contentRoot = contentRoot;
    this.sourceRoot = sourceRoot;
    this.sourceRootTypeData = sourceRootTypeData;
    this.orderEntries = orderEntries;
  }

  @Override
  public boolean equals(Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;

    DirectoryInfo info = (DirectoryInfo)o;

    return sourceRootTypeData == info.sourceRootTypeData &&
           Comparing.equal(contentRoot, info.contentRoot) &&
           Comparing.equal(libraryClassRoot, info.libraryClassRoot) &&
           Comparing.equal(module, info.module) &&
           Arrays.equals(orderEntries, info.orderEntries) &&
           Comparing.equal(sourceRoot, info.sourceRoot);
  }

  @Override
  public int hashCode() {
    int result = module != null ? module.hashCode() : 0;
    result = 31 * result + (libraryClassRoot != null ? libraryClassRoot.hashCode() : 0);
    result = 31 * result + (contentRoot != null ? contentRoot.hashCode() : 0);
    result = 31 * result + (sourceRoot != null ? sourceRoot.hashCode() : 0);
    result = 31 * result + (int)sourceRootTypeData;
    return result;
  }

  @SuppressWarnings({"HardCodedStringLiteral"})
  public String toString() {
    return "DirectoryInfo{" +
           "module=" + getModule() +
           ", isInModuleSource=" + isInModuleSource() +
           ", rootTypeId=" + getSourceRootTypeId() +
           ", isInLibrarySource=" + isInLibrarySource() +
           ", libraryClassRoot=" + getLibraryClassRoot() +
           ", contentRoot=" + getContentRoot() +
           ", sourceRoot=" + getSourceRoot() +
           ", orderEntries=" + Arrays.toString(orderEntries) +
           "}";
  }

  @NotNull
  public OrderEntry[] getOrderEntries() {
    OrderEntry[] entries = orderEntries;
    return entries == null ? OrderEntry.EMPTY_ARRAY : entries;
  }

  @Nullable
  OrderEntry findOrderEntryWithOwnerModule(@NotNull Module ownerModule) {
    OrderEntry[] entries = orderEntries;
    if (entries == null) {
      return null;
    }
    if (entries.length < 10) {
      for (OrderEntry entry : entries) {
{'fraction_non_alphanumeric': 0.09754594927610638, 'fraction_numerical': 0.006571516582811377, 'mean_word_length': 3.3775280898876403, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4157453', 'n_tokens_mistral': 2757, 'n_tokens_neox': 2653, 'n_words': 804}