<commit_before>package org.jetbrains.plugins.scala.annotator

import com.intellij.psi.search.GlobalSearchScope
import com.jniwrapper.A
import compilerErrors.CyclicReferencesSearcher
import highlighter.{AnnotatorHighlighter}
import lang.lexer.ScalaTokenTypes
import lang.psi.api.expr._


import lang.psi.api.statements._
import lang.psi.api.statements.params.{ScClassParameter, ScTypeParam}
import lang.psi.api.toplevel.imports.ScImportSelector
import lang.psi.api.toplevel.typedef._
import lang.psi.api.toplevel.{ScEarlyDefinitions, ScTyped}
import _root_.scala.collection.mutable.HashSet
import lang.psi.api.base.types.ScSimpleTypeElement
import lang.psi.api.base.patterns.ScBindingPattern
import lang.psi.api.base.patterns.ScReferencePattern
import lang.psi.api.toplevel.templates.ScTemplateBody
import lang.psi.impl.search.{ScalaOverridengMemberSearch}
import lang.psi.impl.toplevel.synthetic.ScSyntheticClass
import com.intellij.openapi.util.TextRange
import com.intellij.lang.annotation._

import lang.psi.impl.toplevel.typedef.TypeDefinitionMembers


import lang.psi.ScalaPsiUtil
import lang.psi.types.{FullSignature, PhysicalSignature, Signature, ScSubstitutor}
import org.jetbrains.plugins.scala.lang.psi.api.base._
import org.jetbrains.plugins.scala.lang.resolve._
import com.intellij.psi._
import com.intellij.codeInspection._
import org.jetbrains.plugins.scala.annotator.intention._
import org.jetbrains.plugins.scala.overrideImplement.ScalaOIUtil
import quickfix.ImplementMethodsQuickFix
import quickfix.modifiers.{RemoveModifierQuickFix, AddModifierQuickFix}

/**
 *    User: <NAME>
 *    Date: 23.06.2008
 */

class ScalaAnnotator extends Annotator
        with CyclicReferencesSearcher {
  def annotate(element: PsiElement, holder: AnnotationHolder) {
    val file = element.getContainingFile
    val fType = file.getVirtualFile.getFileType
    if (fType != ScalaFileType.SCALA_FILE_TYPE) return
    element match {
      case x: ScFunction if x.getParent.isInstanceOf[ScTemplateBody] => {
        //checkOverrideMethods(x, holder)
      }
      case x: ScTemplateDefinition => {
        //checkImplementedMethods(x, holder)
      }
      case x: ScBlock => {
        checkResultExpression(x, holder)
      }
      case ref: ScReferenceElement => {
        checkCyclicReferences(ref, holder)
        ref.qualifier match {
          case None => checkNotQualifiedReferenceElement(ref, holder)
          case Some(_) => checkQualifiedReferenceElement(ref, holder)
        }
      }
      case _ => AnnotatorHighlighter.highlightElement(element, holder)
    }
  }

  private def checkNotQualifiedReferenceElement(refElement: ScReferenceElement, holder: AnnotationHolder) {

    def processError = {
      val error = ScalaBundle.message("cannot.resolve", refElement.refName)
      val annotation = holder.createErrorAnnotation(refElement.nameId, error)
      annotation.setHighlightType(ProblemHighlightType.LIKE_UNKNOWN_SYMBOL)
      if (refElement.getManager.isInProject(refElement) && refElement.multiResolve(false).length == 0) {
        registerAddImportFix(refElement, annotation)
      }
    }

    refElement.bind() match {
      case None =>
        refElement.getParent match {
          case s: ScImportSelector if refElement.multiResolve(false).length > 0 =>
          case infix: ScInfixExpr if infix.operation == refElement => //todo: remove when resolve of infix operators will work.
          case prefix: ScPrefixExpr if prefix.operation == refElement => //todo: remove when resolve of prefix operators will work.
          case _ => processError
        }
      case Some(result) => {
        registerUsedImports(refElement, result)
        AnnotatorHighlighter.highlightReferenceElement(refElement, holder)
      }
    }
  }

  /**
   * @see CyclicReferenceSearcher for implementation
   */
  def checkCyclicReferences(refElement: ScReferenceElement, holder: AnnotationHolder) = {
    checkCyclicTypeAliases(refElement, holder)<commit_msg>hided Some and other case Classes red characters<commit_after>package org.jetbrains.plugins.scala.annotator

import com.intellij.psi.search.GlobalSearchScope
import com.jniwrapper.A
import compilerErrors.CyclicReferencesSearcher
import highlighter.{AnnotatorHighlighter}
import lang.lexer.ScalaTokenTypes
import lang.psi.api.expr._


import lang.psi.api.statements._
import lang.psi.api.statements.params.{ScClassParameter, ScTypeParam}
import lang.psi.api.toplevel.imports.ScImportSelector
import lang.psi.api.toplevel.typedef._
import lang.psi.api.toplevel.{ScEarlyDefinitions, ScTyped}
import _root_.scala.collection.mutable.HashSet
import lang.psi.api.base.types.ScSimpleTypeElement
import lang.psi.api.base.patterns.ScBindingPattern
import lang.psi.api.base.patterns.ScReferencePattern
import lang.psi.api.toplevel.templates.ScTemplateBody
import lang.psi.impl.search.{ScalaOverridengMemberSearch}
import lang.psi.impl.toplevel.synthetic.ScSyntheticClass
import com.intellij.openapi.util.TextRange
import com.intellij.lang.annotation._

import lang.psi.impl.toplevel.typedef.TypeDefinitionMembers


import lang.psi.ScalaPsiUtil
import lang.psi.types.{FullSignature, PhysicalSignature, Signature, ScSubstitutor}
import org.jetbrains.plugins.scala.lang.psi.api.base._
import org.jetbrains.plugins.scala.lang.resolve._
import com.intellij.psi._
import com.intellij.codeInspection._
import org.jetbrains.plugins.scala.annotator.intention._
import org.jetbrains.plugins.scala.overrideImplement.ScalaOIUtil
import quickfix.ImplementMethodsQuickFix
import quickfix.modifiers.{RemoveModifierQuickFix, AddModifierQuickFix}

/**
 *    User: <NAME>
 *    Date: 23.06.2008
 */

class ScalaAnnotator extends Annotator
        with CyclicReferencesSearcher {
  def annotate(element: PsiElement, holder: AnnotationHolder) {
    val file = element.getContainingFile
    val fType = file.getVirtualFile.getFileType
    if (fType != ScalaFileType.SCALA_FILE_TYPE) return
    element match {
      case x: ScFunction if x.getParent.isInstanceOf[ScTemplateBody] => {
        //checkOverrideMethods(x, holder)
      }
      case x: ScTemplateDefinition => {
        //checkImplementedMethods(x, holder)
      }
      case x: ScBlock => {
        checkResultExpression(x, holder)
      }
      case ref: ScReferenceElement => {
        checkCyclicReferences(ref, holder)
        ref.qualifier match {
          case None => checkNotQualifiedReferenceElement(ref, holder)
          case Some(_) => checkQualifiedReferenceElement(ref, holder)
        }
      }
      case _ => AnnotatorHighlighter.highlightElement(element, holder)
    }
  }

  private def checkNotQualifiedReferenceElement(refElement: ScReferenceElement, holder: AnnotationHolder) {

    def processError = {
      val error = ScalaBundle.message("cannot.resolve", refElement.refName)
      val annotation = holder.createErrorAnnotation(refElement.nameId, error)
      annotation.setHighlightType(ProblemHighlightType.LIKE_UNKNOWN_SYMBOL)
      if (refElement.getManager.isInProject(refElement) && refElement.multiResolve(false).length == 0) {
        registerAddImportFix(refElement, annotation)
      }
    }

    refElement.bind() match {
      case None =>
        refElement.getParent match {
          case s: ScImportSelector if refElement.multiResolve(false).length > 0 =>
          case infix: ScInfixExpr if infix.operation == refElement => //todo: remove when resolve of infix operators will work.
          case prefix: ScPrefixExpr if prefix.operation == refElement => //todo: remove when resolve of prefix operators will work.
          case _ if refElement.isInstanceOf[ScReferenceExpression] && refElement.multiResolve(false).length > 0 => //todo: Resolve for Some token
          case _ => processError
        }
      case Some(result) => {
        registerUsedImports(refElement, result)
        AnnotatorHighlighter.highlightReferenceElement(refElement, holder)
      }
    }
  }

  /**
   * @see CyclicReferenceSearcher for implementation
   */
  def checkCyclicReferences(refElement: ScReferenceElement, holder: AnnotationHolder) = {
    checkCyclicTypeAliases(refElement, holder)
{'fraction_non_alphanumeric': 0.09025982021918483, 'fraction_numerical': 0.0025858884373845584, 'mean_word_length': 4.073079325421611, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 35, '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': '5108961', 'n_tokens_mistral': 2439, 'n_tokens_neox': 2346, 'n_words': 448}