<commit_before>package org.jetbrains.plugins.scala.caches;

import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiField;
import com.intellij.psi.PsiMethod;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.search.PsiShortNamesCache;
import com.intellij.psi.stubs.StubIndex;
import com.intellij.psi.util.PsiUtilBase;
import com.intellij.util.containers.HashSet;
import com.intellij.util.indexing.FileBasedIndex;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.plugins.scala.lang.psi.api.ScalaFile;
import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.ScTypeDefinition;
import org.jetbrains.plugins.scala.lang.psi.stubs.index.ScalaIndexKeys;

import java.util.ArrayList;
import java.util.Collection;

/**
 * @author ilyas
 */
public class ScalaShortNamesCache extends PsiShortNamesCache {
  private Logger LOG = Logger.getInstance("#org.jetbrains.plugins.scala.caches.ScalaShortNamesCache");

  Project myProject;

  public ScalaShortNamesCache(Project project) {
    myProject = project;
  }

  @NotNull
  public PsiClass[] getClassesByName(@NotNull @NonNls String name, @NotNull GlobalSearchScope scope) {
    final Collection<? extends PsiClass> plainClasses = StubIndex.getInstance().get(ScalaIndexKeys.SHORT_NAME_KEY(), name, myProject, scope);
    return plainClasses.toArray(new PsiClass[plainClasses.size()]);
  }

  @Nullable
  public PsiClass getClassByFQName(@NotNull @NonNls String name, @NotNull GlobalSearchScope scope) {
    final Collection<? extends PsiElement> classes = StubIndex.getInstance().get(ScalaIndexKeys.FQN_KEY(), name.hashCode(), myProject, scope);
    for (PsiElement element : classes) {
      if (!(element instanceof PsiClass)) {
        VirtualFile faultyContainer = PsiUtilBase.getVirtualFile(element);
        LOG.error("Wrong Psi in Psi list: " + faultyContainer);
        if (faultyContainer != null && faultyContainer.isValid()) {
          FileBasedIndex.getInstance().requestReindex(faultyContainer);
        }
        return null;
      }
      PsiClass clazz = (PsiClass) element;
      if (name.equals(clazz.getQualifiedName())) {
        if (clazz.getContainingFile() instanceof ScalaFile) {
          ScalaFile file = (ScalaFile) clazz.getContainingFile();
          if (file.isScriptFile(true)) continue;
        }
        return clazz;
      }
    }
    return null;
  }

  @NotNull
  public PsiClass[] getClassesByFQName(@NotNull @NonNls String fqn, @NotNull GlobalSearchScope scope) {
    final Collection<PsiClass> classes = StubIndex.getInstance().get(ScalaIndexKeys.FQN_KEY(), fqn.hashCode(), myProject, scope);
    ArrayList<PsiClass> list = new ArrayList<PsiClass>();
    for (PsiClass psiClass : classes) {
      if (fqn.equals(psiClass.getQualifiedName())) {
        list.add(psiClass);
      }
    }
    return list.toArray(new PsiClass[list.size()]);
  }

  public ScTypeDefinition getPackageObjectByName(@NotNull @NonNls String fqn, @NotNull GlobalSearchScope scope) {
    final Collection<PsiClass> classes = StubIndex.getInstance().get(ScalaIndexKeys.PACKAGE_OBJECT_KEY(), fqn.hashCode(), myProject, scope);
    ArrayList<ScTypeDefinition> list = new ArrayList<ScTypeDefinition>();
    for (PsiClass psiClass : classes) {
      if (fqn.equals(psiClass.getQualifiedName())) {
        if (psiClass instanceof ScTypeDefinition) {
          return ((ScTypeDefinition) psiClass);<commit_msg>one more ClassCast exception killed (to reindex file)<commit_after>package org.jetbrains.plugins.scala.caches;

import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiField;
import com.intellij.psi.PsiMethod;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.search.PsiShortNamesCache;
import com.intellij.psi.stubs.StubIndex;
import com.intellij.psi.util.PsiUtilBase;
import com.intellij.util.containers.HashSet;
import com.intellij.util.indexing.FileBasedIndex;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.plugins.scala.lang.psi.api.ScalaFile;
import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.ScTypeDefinition;
import org.jetbrains.plugins.scala.lang.psi.stubs.index.ScalaIndexKeys;

import java.util.ArrayList;
import java.util.Collection;

/**
 * @author ilyas
 */
public class ScalaShortNamesCache extends PsiShortNamesCache {
  private Logger LOG = Logger.getInstance("#org.jetbrains.plugins.scala.caches.ScalaShortNamesCache");

  Project myProject;

  public ScalaShortNamesCache(Project project) {
    myProject = project;
  }

  @NotNull
  public PsiClass[] getClassesByName(@NotNull @NonNls String name, @NotNull GlobalSearchScope scope) {
    final Collection<? extends PsiClass> plainClasses = StubIndex.getInstance().get(ScalaIndexKeys.SHORT_NAME_KEY(), name, myProject, scope);
    return plainClasses.toArray(new PsiClass[plainClasses.size()]);
  }

  @Nullable
  public PsiClass getClassByFQName(@NotNull @NonNls String name, @NotNull GlobalSearchScope scope) {
    final Collection<? extends PsiElement> classes = StubIndex.getInstance().get(ScalaIndexKeys.FQN_KEY(), name.hashCode(), myProject, scope);
    for (PsiElement element : classes) {
      if (!(element instanceof PsiClass)) {
        VirtualFile faultyContainer = PsiUtilBase.getVirtualFile(element);
        LOG.error("Wrong Psi in Psi list: " + faultyContainer);
        if (faultyContainer != null && faultyContainer.isValid()) {
          FileBasedIndex.getInstance().requestReindex(faultyContainer);
        }
        return null;
      }
      PsiClass clazz = (PsiClass) element;
      if (name.equals(clazz.getQualifiedName())) {
        if (clazz.getContainingFile() instanceof ScalaFile) {
          ScalaFile file = (ScalaFile) clazz.getContainingFile();
          if (file.isScriptFile(true)) continue;
        }
        return clazz;
      }
    }
    return null;
  }

  @NotNull
  public PsiClass[] getClassesByFQName(@NotNull @NonNls String fqn, @NotNull GlobalSearchScope scope) {
    final Collection<? extends PsiElement> classes = StubIndex.getInstance().get(ScalaIndexKeys.FQN_KEY(), fqn.hashCode(), myProject, scope);
    ArrayList<PsiClass> list = new ArrayList<PsiClass>();
    for (PsiElement element : classes) {
      if (!(element instanceof PsiClass)) {
        VirtualFile faultyContainer = PsiUtilBase.getVirtualFile(element);
        LOG.error("Wrong Psi in Psi list: " + faultyContainer);
        if (faultyContainer != null && faultyContainer.isValid()) {
          FileBasedIndex.getInstance().requestReindex(faultyContainer);
        }
        return null;
      }
      PsiClass psiClass = (PsiClass) element;
      if (fqn.equals(psiClass.getQualifiedName())) {
        list.add(psiClass);
      }
    }
    return list.toArray(new PsiClass[list.size()]);
  }

  public ScTypeDefinition getPackageObjectByName(@NotNull @NonNls String fqn, @NotNull GlobalSearchScope scope) {
    final Collection<PsiClass> classes = StubIndex.getInstance().get(ScalaIndexKeys.PACKAGE_OBJECT_KEY(), fqn.hashCode(), myProject, scope);
    ArrayList<ScTypeDefinition> list = new ArrayList<ScTypeDefinition>();
    for (PsiClass psiClass : classes) {
      if (fqn.equals(psiClass.getQualifiedName())) {
        if (psiClass instanceof ScTypeDefinition) {
          return ((ScTypeDefinition) psiClass);
{'fraction_non_alphanumeric': 0.11098265895953757, 'fraction_numerical': 0.0, 'mean_word_length': 4.4409503843466105, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '6271839', 'n_tokens_mistral': 2396, 'n_tokens_neox': 2329, 'n_words': 456}