<commit_before>
package com.intellij.codeInsight.completion;

import com.intellij.codeInsight.ExpectedTypeInfo;
import com.intellij.codeInsight.ExpectedTypeInfoImpl;
import com.intellij.codeInsight.lookup.LookupItem;
import com.intellij.codeInsight.lookup.LookupItemPreferencePolicy;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.psi.*;
import com.intellij.psi.codeStyle.CodeStyleManager;
import com.intellij.psi.codeStyle.NameUtil;
import com.intellij.psi.codeStyle.VariableKind;
import com.intellij.psi.statistics.StatisticsManager;
import com.intellij.util.containers.HashMap;

import java.util.Map;

class CompletionPreferencePolicy implements LookupItemPreferencePolicy{
  private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.completion.CompletionPreferencePolicy");

  private final PsiManager myManager;
  private final ExpectedTypeInfo[] myExpectedInfos;

  private Map<LookupItem, Integer> myItemToIndexMap = new HashMap<LookupItem, Integer>();
  private Map<PsiType, PsiType> myNormalizedItems = new HashMap<PsiType, PsiType>();

  private CodeStyleManager myCodeStyleManager;
  private String myPrefix;

  public void setPrefix(String prefix) {
    myPrefix = prefix;
  }

  public CompletionPreferencePolicy(PsiManager manager, LookupItem[] allItems, ExpectedTypeInfo[] expectedInfos, String prefix) {
    myPrefix = prefix;
    myManager = manager;
    myCodeStyleManager = CodeStyleManager.getInstance(myManager.getProject());
    if(expectedInfos != null){
      final Map<PsiType, ExpectedTypeInfo> map = new java.util.HashMap<PsiType, ExpectedTypeInfo>(expectedInfos.length);
      for (int i = 0; i < expectedInfos.length; i++) {
        final ExpectedTypeInfo expectedInfo = expectedInfos[i];
        if(!map.containsKey(expectedInfo.getType())){
          map.put(expectedInfo.getType(), expectedInfo);
        }
      }
      myExpectedInfos = map.values().toArray(new ExpectedTypeInfo[map.size()]);
    }
    else myExpectedInfos = null;
    synchronized(myItemToIndexMap){
      for(int i = 0; i < allItems.length; i++){
        myItemToIndexMap.put(allItems[i], new Integer(i + 1));
      }
    }
  }


  public void itemSelected(LookupItem item) {
    final Object o = item.getObject();
    if (o instanceof PsiMember){
      final PsiType qualifierType = CompletionUtil.getQualifierType(item);
      if (qualifierType != null){
        StatisticsManager.getInstance().incMemberUseCount(qualifierType, (PsiMember)o);
      }
    }

  }

  public int compare(final LookupItem item1, final LookupItem item2) {
    if (item1 == item2) return 0;

    Object o1 = item1.getObject();<commit_msg>camel humps in completion<commit_after>
package com.intellij.codeInsight.completion;

import com.intellij.codeInsight.ExpectedTypeInfo;
import com.intellij.codeInsight.ExpectedTypeInfoImpl;
import com.intellij.codeInsight.lookup.LookupItem;
import com.intellij.codeInsight.lookup.LookupItemPreferencePolicy;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.psi.*;
import com.intellij.psi.codeStyle.CodeStyleManager;
import com.intellij.psi.codeStyle.NameUtil;
import com.intellij.psi.codeStyle.VariableKind;
import com.intellij.psi.statistics.StatisticsManager;
import com.intellij.util.containers.HashMap;

import java.util.Map;

class CompletionPreferencePolicy implements LookupItemPreferencePolicy{
  private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.completion.CompletionPreferencePolicy");

  private final PsiManager myManager;
  private final ExpectedTypeInfo[] myExpectedInfos;

  private Map<LookupItem, Integer> myItemToIndexMap = new HashMap<LookupItem, Integer>();
  private Map<PsiType, PsiType> myNormalizedItems = new HashMap<PsiType, PsiType>();

  private CodeStyleManager myCodeStyleManager;
  private String myPrefix;

  public void setPrefix(String prefix) {
    myPrefix = prefix;
  }

  public CompletionPreferencePolicy(PsiManager manager, LookupItem[] allItems, ExpectedTypeInfo[] expectedInfos, String prefix) {
    myPrefix = prefix;
    myManager = manager;
    myCodeStyleManager = CodeStyleManager.getInstance(myManager.getProject());
    if(expectedInfos != null){
      final Map<PsiType, ExpectedTypeInfo> map = new java.util.HashMap<PsiType, ExpectedTypeInfo>(expectedInfos.length);
      for (int i = 0; i < expectedInfos.length; i++) {
        final ExpectedTypeInfo expectedInfo = expectedInfos[i];
        if(!map.containsKey(expectedInfo.getType())){
          map.put(expectedInfo.getType(), expectedInfo);
        }
      }
      myExpectedInfos = map.values().toArray(new ExpectedTypeInfo[map.size()]);
    }
    else myExpectedInfos = null;
    synchronized(myItemToIndexMap){
      for(int i = 0; i < allItems.length; i++){
        myItemToIndexMap.put(allItems[i], new Integer(i + 1));
      }
    }
  }


  public void itemSelected(LookupItem item) {
    final Object o = item.getObject();
    if (o instanceof PsiMember){
      final PsiType qualifierType = CompletionUtil.getQualifierType(item);
      if (qualifierType != null){
        StatisticsManager.getInstance().incMemberUseCount(qualifierType, (PsiMember)o);
      }
    }

  }

  public int compare(final LookupItem item1, final LookupItem item2) {
    if (item1 == item2) return 0;
    if(item1.getLookupString().toLowerCase().startsWith(myPrefix.toLowerCase()) && !item2.getLookupString().toLowerCase().startsWith(myPrefix.toLowerCase()))
      return -1;
    if(!item1.getLookupString().toLowerCase().startsWith(myPrefix.toLowerCase()) && item2.getLookupString().toLowerCase().startsWith(myPrefix.toLowerCase()))
      return 1;
    Object o1 = item1.getObject();
{'fraction_non_alphanumeric': 0.10643912737508797, 'fraction_numerical': 0.004574243490499648, 'mean_word_length': 4.730846774193548, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 15, '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': '6204854', 'n_tokens_mistral': 1688, 'n_tokens_neox': 1703, 'n_words': 336}