<commit_before>/*
 * Copyright 2000-2014 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.codeInsight;

import com.intellij.codeHighlighting.Pass;
import com.intellij.codeInsight.daemon.GutterIconNavigationHandler;
import com.intellij.codeInsight.daemon.LineMarkerInfo;
import com.intellij.codeInsight.daemon.LineMarkerProvider;
import com.intellij.codeInsight.intention.IntentionAction;
import com.intellij.codeInsight.intention.IntentionManager;
import com.intellij.codeInsight.javadoc.JavaDocInfoGenerator;
import com.intellij.icons.AllIcons;
import com.intellij.ide.actions.ApplyIntentionAction;
import com.intellij.openapi.actionSystem.DefaultActionGroup;
import com.intellij.openapi.actionSystem.impl.SimpleDataContext;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.markup.GutterIconRenderer;
import com.intellij.openapi.fileEditor.FileEditorManager;
import com.intellij.openapi.fileEditor.OpenFileDescriptor;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.popup.JBPopupFactory;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.*;
import com.intellij.psi.util.PsiUtilCore;
import com.intellij.util.Function;
import com.intellij.xml.util.XmlStringUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.awt.event.MouseEvent;
import java.util.Collection;
import java.util.List;

public class ExternalAnnotationsLineMarkerProvider implements LineMarkerProvider {
  private static final Function<PsiElement, String> ourTooltipProvider = new Function<PsiElement, String>() {
    @Override
    public String fun(PsiElement nameIdentifier) {
      return XmlStringUtil.wrapInHtml(JavaDocInfoGenerator.generateSignature(nameIdentifier.getParent()));
    }
  };

  @Nullable
  @Override
  public LineMarkerInfo getLineMarkerInfo(@NotNull final PsiElement element) {
    if (!(element instanceof PsiModifierListOwner) || !(element instanceof PsiNameIdentifierOwner)) return null;
    if (element instanceof PsiParameter || element instanceof PsiLocalVariable) return null;

    PsiElement nameIdentifier = ((PsiNameIdentifierOwner)element).getNameIdentifier();
    if (nameIdentifier == null || nameIdentifier.getParent() != element) return null;

    if (!shouldShowSignature((PsiModifierListOwner)element)) {
      return null;
    }

    return new LineMarkerInfo<PsiElement>(nameIdentifier, nameIdentifier.getTextRange().getStartOffset(),
                                          AllIcons.Gutter.ExtAnnotation,
                                          Pass.UPDATE_ALL,
                                          ourTooltipProvider, MyIconGutterHandler.INSTANCE,
                                          GutterIconRenderer.Alignment.LEFT);
  }

  private static boolean shouldShowSignature(PsiModifierListOwner owner) {
    if (hasNonCodeAnnotations(owner)) {
      return true;
    }

    if (owner instanceof PsiMethod) {
      for (PsiParameter parameter : ((PsiMethod)owner).getParameterList().getParameters()) {
        if (hasNonCodeAnnotations(parameter)) {
          return true;
        }
      }
    }

    return false;
  }

  private static boolean hasNonCodeAnnotations(@NotNull PsiModifierListOwner element) {
    Project project = element.getProject();
    PsiAnnotation[] externalAnnotations = ExternalAnnotationsManager.getInstance(project).findExternalAnnotations(element);
    if (externalAnnotations != null) {
      for (PsiAnnotation annotation : externalAnnotations) {
        if (isVisibleAnnotation(annotation)) {
          return true;<commit_msg>ExternalAnnotationsLineMarkerProvider: don't blink (return line marker for the same element as queried)<commit_after>/*
 * Copyright 2000-2014 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.codeInsight;

import com.intellij.codeHighlighting.Pass;
import com.intellij.codeInsight.daemon.GutterIconNavigationHandler;
import com.intellij.codeInsight.daemon.LineMarkerInfo;
import com.intellij.codeInsight.daemon.LineMarkerProvider;
import com.intellij.codeInsight.intention.IntentionAction;
import com.intellij.codeInsight.intention.IntentionManager;
import com.intellij.codeInsight.javadoc.JavaDocInfoGenerator;
import com.intellij.icons.AllIcons;
import com.intellij.ide.actions.ApplyIntentionAction;
import com.intellij.openapi.actionSystem.DefaultActionGroup;
import com.intellij.openapi.actionSystem.impl.SimpleDataContext;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.markup.GutterIconRenderer;
import com.intellij.openapi.fileEditor.FileEditorManager;
import com.intellij.openapi.fileEditor.OpenFileDescriptor;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.popup.JBPopupFactory;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.*;
import com.intellij.psi.util.PsiUtilCore;
import com.intellij.util.Function;
import com.intellij.xml.util.XmlStringUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.awt.event.MouseEvent;
import java.util.Collection;
import java.util.List;

public class ExternalAnnotationsLineMarkerProvider implements LineMarkerProvider {
  private static final Function<PsiElement, String> ourTooltipProvider = new Function<PsiElement, String>() {
    @Override
    public String fun(PsiElement nameIdentifier) {
      return XmlStringUtil.wrapInHtml(JavaDocInfoGenerator.generateSignature(nameIdentifier.getParent()));
    }
  };

  @Nullable
  @Override
  public LineMarkerInfo getLineMarkerInfo(@NotNull final PsiElement element) {
    PsiElement owner = element.getParent();
    if (!(owner instanceof PsiModifierListOwner) || !(owner instanceof PsiNameIdentifierOwner)) return null;
    if (owner instanceof PsiParameter || owner instanceof PsiLocalVariable) return null;

    // support non-Java languages where getNameIdentifier may return non-physical psi with the same range
    PsiElement nameIdentifier = ((PsiNameIdentifierOwner)owner).getNameIdentifier();
    if (nameIdentifier == null || !nameIdentifier.getTextRange().equals(element.getTextRange())) return null;

    if (!shouldShowSignature((PsiModifierListOwner)owner)) {
      return null;
    }

    return new LineMarkerInfo<PsiElement>(element, element.getTextRange().getStartOffset(),
                                          AllIcons.Gutter.ExtAnnotation,
                                          Pass.UPDATE_ALL,
                                          ourTooltipProvider, MyIconGutterHandler.INSTANCE,
                                          GutterIconRenderer.Alignment.LEFT);
  }

  private static boolean shouldShowSignature(PsiModifierListOwner owner) {
    if (hasNonCodeAnnotations(owner)) {
      return true;
    }

    if (owner instanceof PsiMethod) {
      for (PsiParameter parameter : ((PsiMethod)owner).getParameterList().getParameters()) {
        if (hasNonCodeAnnotations(parameter)) {
          return true;
        }
      }
    }

    return false;
  }

  private static boolean hasNonCodeAnnotations(@NotNull PsiModifierListOwner element) {
    Project project = element.getProject();
    PsiAnnotation[] externalAnnotations = ExternalAnnotationsManager.getInstance(project).findExternalAnnotations(element);
    if (externalAnnotations != null) {
      for (PsiAnnotation annotation : externalAnnotations) {
        if (isVisibleAnnotation(annotation)) {
          return true;
{'fraction_non_alphanumeric': 0.08550011712344811, 'fraction_numerical': 0.0028109627547434997, 'mean_word_length': 4.172016959418534, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4674140', 'n_tokens_mistral': 2290, 'n_tokens_neox': 2248, 'n_words': 535}