<commit_before>/*
 * Copyright (c) 2000-2005 by JetBrains s.r.o. All Rights Reserved.
 * Use is subject to license terms.
 */
package com.intellij.codeInsight.completion;

import com.intellij.codeInsight.lookup.LookupElement;
import com.intellij.codeInsight.lookup.LookupItem;
import com.intellij.codeInsight.lookup.MutableLookupElement;
import com.intellij.codeInsight.ExpectedTypeInfo;
import com.intellij.psi.*;
import com.intellij.psi.statistics.JavaStatisticsManager;
import com.intellij.psi.statistics.StatisticsInfo;
import com.intellij.openapi.util.text.StringUtil;
import org.jetbrains.annotations.NonNls;

/**
 * @author peter
 */
public class JavaCompletionStatistician extends CompletionStatistician{
  @NonNls public static final String CLASS_NAME_COMPLETION_PREFIX = "classNameCompletion#";

  public StatisticsInfo serialize(final LookupElement element, final CompletionLocation location) {
    if (!(element instanceof MutableLookupElement)) return null;

    final Object o = ((MutableLookupElement)element).getObject();

    if (o instanceof PsiLocalVariable || o instanceof PsiParameter || o instanceof PsiThisExpression) {
      return StatisticsInfo.EMPTY;
    }

    PsiType qualifierType = JavaCompletionUtil.getQualifierType((LookupItem) element);
    if (qualifierType == null) {
      final ExpectedTypeInfo[] infos = JavaCompletionUtil.EXPECTED_TYPES.getValue(location);<commit_msg>don't collect statistics when primitive type is expected, it's of no use there<commit_after>/*
 * Copyright (c) 2000-2005 by JetBrains s.r.o. All Rights Reserved.
 * Use is subject to license terms.
 */
package com.intellij.codeInsight.completion;

import com.intellij.codeInsight.ExpectedTypeInfo;
import com.intellij.codeInsight.lookup.LookupElement;
import com.intellij.codeInsight.lookup.LookupItem;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.util.Condition;
import com.intellij.psi.*;
import com.intellij.psi.statistics.JavaStatisticsManager;
import com.intellij.psi.statistics.StatisticsInfo;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NonNls;

/**
 * @author peter
 */
public class JavaCompletionStatistician extends CompletionStatistician{
  @NonNls public static final String CLASS_NAME_COMPLETION_PREFIX = "classNameCompletion#";

  public StatisticsInfo serialize(final LookupElement element, final CompletionLocation location) {
    final Object o = element.getObject();

    if (o instanceof PsiLocalVariable || o instanceof PsiParameter || o instanceof PsiThisExpression) {
      return StatisticsInfo.EMPTY;
    }

    final ExpectedTypeInfo[] infos = JavaCompletionUtil.EXPECTED_TYPES.getValue(location);
    if (infos != null && infos.length > 0) {
      final boolean primitivesOnly = ContainerUtil.and(infos, new Condition<ExpectedTypeInfo>() {
        public boolean value(final ExpectedTypeInfo info) {
          return info.getType() instanceof PsiPrimitiveType;
        }
      });
      if (primitivesOnly) {
        return StatisticsInfo.EMPTY; //collecting statistics on primitive types usually has only negative effects
      }
    }

    if (!(element instanceof LookupItem)) return null;

    PsiType qualifierType = JavaCompletionUtil.getQualifierType((LookupItem) element);
    if (qualifierType == null) {
{'fraction_non_alphanumeric': 0.0897049969897652, 'fraction_numerical': 0.005117399157134257, 'mean_word_length': 4.976618705035971, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 5, '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': '1093144', 'n_tokens_mistral': 956, 'n_tokens_neox': 934, 'n_words': 229}