<commit_before>package com.intellij.codeInsight.hint.api.impls;

import com.intellij.codeInsight.hint.api.*;
import com.intellij.codeInsight.lookup.LookupItem;
import com.intellij.psi.*;
import com.intellij.psi.util.PsiUtil;
import com.intellij.pom.java.LanguageLevel;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.util.Function;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;

import java.util.Arrays;

/**
 * Created by IntelliJ IDEA.
 * User: Maxim.Mossienko
 * Date: Feb 1, 2006
 * Time: 3:16:09 PM
 * To change this template use File | Settings | File Templates.
 */
public class ReferenceParameterInfoHandler implements ParameterInfoHandler<PsiReferenceParameterList,PsiTypeParameter> {
  public Object[] getParametersForLookup(final LookupItem item, final ParameterInfoContext context) {
    return null;
  }

  public Object[] getParametersForDocumentation(final PsiTypeParameter p, final ParameterInfoContext context) {
    return new Object[] {p};
  }

  public boolean couldShowInLookup() {
    return false;
  }

  public PsiReferenceParameterList findElementForParameterInfo(final CreateParameterInfoContext context) {
    final PsiReferenceParameterList referenceParameterList =
      ParameterInfoUtils.findParentOfType(context.getFile(), context.getOffset(), PsiReferenceParameterList.class);

    if (referenceParameterList != null) {
      if (!(referenceParameterList.getParent() instanceof PsiJavaCodeReferenceElement)) return null;
      final PsiJavaCodeReferenceElement ref = ((PsiJavaCodeReferenceElement)referenceParameterList.getParent());
      final PsiElement psiElement = ref.resolve();
      if (!(psiElement instanceof PsiTypeParameterListOwner)) return null;

      final PsiTypeParameter[] typeParams = ((PsiTypeParameterListOwner)psiElement).getTypeParameters();
      if (typeParams.length == 0) return null;

      context.setItemsToShow(typeParams);
      return referenceParameterList;
    }

    return null;
  }

  public void showParameterInfo(final PsiReferenceParameterList element, final CreateParameterInfoContext context) {
    context.showHint(element, element.getTextRange().getStartOffset() + 1, this);
  }

  public PsiReferenceParameterList findElementForUpdatingParameterInfo(final UpdateParameterInfoContext context) {
    return ParameterInfoUtils.findParentOfType(context.getFile(), context.getOffset(), PsiReferenceParameterList.class);
  }

  public void updateParameterInfo(final PsiReferenceParameterList o, final UpdateParameterInfoContext context) {
    int index = ParameterInfoUtils.getCurrentParameterIndex(o.getNode(), context.getOffset(), JavaTokenType.COMMA);
    context.setCurrentParameter(index);
    context.setHighlightedParameter((PsiElement)context.getObjectsToView()[index]);
  }

  @NotNull
  public String getParameterCloseChars() {
    return ",>";
  }

  public boolean tracksParameterIndex() {
    return true;
  }

  public void updateUI(PsiTypeParameter o, ParameterInfoUIContext context) {
    updateTypeParameter(o, context);
  }
<commit_msg>[#2668] AIOOBE: ReferenceParameterInfoHandler.updateParameterInfo (IDEADEV-8498)<commit_after>package com.intellij.codeInsight.hint.api.impls;

import com.intellij.codeInsight.hint.api.*;
import com.intellij.codeInsight.lookup.LookupItem;
import com.intellij.psi.*;
import com.intellij.psi.util.PsiUtil;
import com.intellij.pom.java.LanguageLevel;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.util.Function;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;

import java.util.Arrays;

/**
 * Created by IntelliJ IDEA.
 * User: Maxim.Mossienko
 * Date: Feb 1, 2006
 * Time: 3:16:09 PM
 * To change this template use File | Settings | File Templates.
 */
public class ReferenceParameterInfoHandler implements ParameterInfoHandler<PsiReferenceParameterList,PsiTypeParameter> {
  public Object[] getParametersForLookup(final LookupItem item, final ParameterInfoContext context) {
    return null;
  }

  public Object[] getParametersForDocumentation(final PsiTypeParameter p, final ParameterInfoContext context) {
    return new Object[] {p};
  }

  public boolean couldShowInLookup() {
    return false;
  }

  public PsiReferenceParameterList findElementForParameterInfo(final CreateParameterInfoContext context) {
    final PsiReferenceParameterList referenceParameterList =
      ParameterInfoUtils.findParentOfType(context.getFile(), context.getOffset(), PsiReferenceParameterList.class);

    if (referenceParameterList != null) {
      if (!(referenceParameterList.getParent() instanceof PsiJavaCodeReferenceElement)) return null;
      final PsiJavaCodeReferenceElement ref = ((PsiJavaCodeReferenceElement)referenceParameterList.getParent());
      final PsiElement psiElement = ref.resolve();
      if (!(psiElement instanceof PsiTypeParameterListOwner)) return null;

      final PsiTypeParameter[] typeParams = ((PsiTypeParameterListOwner)psiElement).getTypeParameters();
      if (typeParams.length == 0) return null;

      context.setItemsToShow(typeParams);
      return referenceParameterList;
    }

    return null;
  }

  public void showParameterInfo(final PsiReferenceParameterList element, final CreateParameterInfoContext context) {
    context.showHint(element, element.getTextRange().getStartOffset() + 1, this);
  }

  public PsiReferenceParameterList findElementForUpdatingParameterInfo(final UpdateParameterInfoContext context) {
    return ParameterInfoUtils.findParentOfType(context.getFile(), context.getOffset(), PsiReferenceParameterList.class);
  }

  public void updateParameterInfo(final PsiReferenceParameterList o, final UpdateParameterInfoContext context) {
    int index = ParameterInfoUtils.getCurrentParameterIndex(o.getNode(), context.getOffset(), JavaTokenType.COMMA);
    context.setCurrentParameter(index);
    final Object[] objectsToView = context.getObjectsToView();
    context.setHighlightedParameter(index < objectsToView.length ? (PsiElement)objectsToView[index]:null);
  }

  @NotNull
  public String getParameterCloseChars() {
    return ",>";
  }

  public boolean tracksParameterIndex() {
    return true;
  }

  public void updateUI(PsiTypeParameter o, ParameterInfoUIContext context) {
    updateTypeParameter(o, context);
  }

{'fraction_non_alphanumeric': 0.08977398451082662, 'fraction_numerical': 0.005057689268215584, 'mean_word_length': 5.633123689727463, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 7, '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': '6748391', 'n_tokens_mistral': 1744, 'n_tokens_neox': 1686, 'n_words': 365}