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

import collection.mutable.{ImmutableSetAdaptor}
import com.intellij.codeInsight.intention.IntentionAction
import com.intellij.psi.util.{PsiTreeUtil}
import highlighter.{AnnotatorHighlighter}
import importsTracker._
import lang.lexer.ScalaTokenTypes
import lang.psi.api.expr._


import lang.psi.api.statements._
import lang.psi.api.statements.params.{ScClassParameter}
import lang.psi.api.toplevel.imports.ScImportSelector
import lang.psi.api.toplevel.typedef._
import lang.psi.api.toplevel.templates.ScTemplateBody
import com.intellij.openapi.util.TextRange
import com.intellij.lang.annotation._

import lang.psi.ScalaPsiUtil
import lang.psi.types.{FullSignature}
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}
import modifiers.ModifierChecker
import scala.lang.formatting.settings.ScalaCodeStyleSettings
import scala.lang.psi.api.ScalaFile
import tree.TokenSet
import com.intellij.psi.codeStyle.CodeStyleSettingsManager
/**
 *    User: <NAME>
 *    Date: 23.06.2008
 */

class ScalaAnnotator extends Annotator {

  def annotate(element: PsiElement, holder: AnnotationHolder) {
    element match {
      case x: ScFunction if x.getParent.isInstanceOf[ScTemplateBody] => {
        //todo: unhandled case abstract override
        //checkOverrideMethods(x, holder)
      }
      case x: ScTemplateDefinition => {
        // todo uncomment when lineariztion problems will be fixed
        //        checkImplementedMethods(x, holder)
      }
      case x: ScBlock => {
        checkResultExpression(x, holder)
      }
      case ref: ScReferenceElement => {
        ref.qualifier match {
          case None => checkNotQualifiedReferenceElement(ref, holder)
          case Some(_) => checkQualifiedReferenceElement(ref, holder)
        }
      }
      case ret: ScReturnStmt => {
        checkExplicitTypeForReturnStatement(ret, holder)
      }
      case ml: ScModifierList => {
        ModifierChecker.checkModifiers(ml, holder)
      }
      case sFile: ScalaFile => {
        ImportTracker.getInstance(sFile.getProject).removeAnnotatedFile(sFile) //it must be last annotated element
      }
      case _ => AnnotatorHighlighter.highlightElement(element, holder)
    }
  }

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

    def getFixes = OuterImportsActionCreator.getOuterImportFixes(refElement, refElement.getProject())

    def processError(countError: Boolean, fixes: => Seq[IntentionAction]) = {
      //todo remove when resolve of unqualified expression will be fully implemented
      if (refElement.getManager.isInProject(refElement) && refElement.multiResolve(false).length == 0 &&
              (fixes.length > 0 || countError)) {
        val error = ScalaBundle.message("cannot.resolve", refElement.refName)
        val annotation = holder.createErrorAnnotation(refElement.nameId, error)
        annotation.setHighlightType(ProblemHighlightType.LIKE_UNKNOWN_SYMBOL)
        registerAddImportFix(refElement, annotation, fixes: _*)
      }
    }

    refElement.bind() match {
      case None =>
        refElement match {
          case e: ScReferenceExpression if e.getParent.isInstanceOf[ScPrefixExpr] &&
                  e.getParent.asInstanceOf[ScPrefixExpr].operation == e => //todo: this is hide !(Not Boolean)
          case e: ScReferenceExpression if e.getParent.isInstanceOf[ScInfixExpr] &&
                  e.getParent.asInstanceOf[ScInfixExpr].operation == e => //todo: this is hide A op B
          case e: ScReferenceExpression => processError(false, getFixes)
          case _ => refElement.getParent match {
            case s: ScImportSelector if refElement.multiResolve(false).length > 0 =>
            case _ => processError(true, getFixes)
          }
        }
      case Some(result) => {
        AnnotatorHighlighter.highlightReferenceElement(refElement, holder)
      }
    }
    for (result <- refElement.multiResolve(false) if result.isInstanceOf[ScalaResolveResult];
         scalaResult = result.asInstanceOf[ScalaResolveResult]) {
      registerUsedImports(refElement, scalaResult)
    }
  }

  private def checkQualifiedReferenceElement(refElement: ScReferenceElement, holder: AnnotationHolder) {
    AnnotatorHighlighter.highlightReferenceElement(refElement, holder)
    val settings: ScalaCodeStyleSettings =
           CodeStyleSettingsManager.getSettings(getProject).getCustomSettings(classOf[ScalaCodeStyleSettings])
    if (settings.CHECK_IMPLICITS) {
      for (result <- refElement.multiResolve(false) if result.isInstanceOf[ScalaResolveResult];
           scalaResult = result.asInstanceOf[ScalaResolveResult]) {
        registerUsedImports(refElement, scalaResult)<commit_msg>fixed build<commit_after>package org.jetbrains.plugins.scala.annotator

import collection.mutable.{ImmutableSetAdaptor}
import com.intellij.codeInsight.intention.IntentionAction
import com.intellij.psi.util.{PsiTreeUtil}
import highlighter.{AnnotatorHighlighter}
import importsTracker._
import lang.lexer.ScalaTokenTypes
import lang.psi.api.expr._


import lang.psi.api.statements._
import lang.psi.api.statements.params.{ScClassParameter}
import lang.psi.api.toplevel.imports.ScImportSelector
import lang.psi.api.toplevel.typedef._
import lang.psi.api.toplevel.templates.ScTemplateBody
import com.intellij.openapi.util.TextRange
import com.intellij.lang.annotation._

import lang.psi.ScalaPsiUtil
import lang.psi.types.{FullSignature}
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}
import modifiers.ModifierChecker
import scala.lang.formatting.settings.ScalaCodeStyleSettings
import scala.lang.psi.api.ScalaFile
import tree.TokenSet
import com.intellij.psi.codeStyle.CodeStyleSettingsManager
/**
 *    User: <NAME>
 *    Date: 23.06.2008
 */

class ScalaAnnotator extends Annotator {

  def annotate(element: PsiElement, holder: AnnotationHolder) {
    element match {
      case x: ScFunction if x.getParent.isInstanceOf[ScTemplateBody] => {
        //todo: unhandled case abstract override
        //checkOverrideMethods(x, holder)
      }
      case x: ScTemplateDefinition => {
        // todo uncomment when lineariztion problems will be fixed
        //        checkImplementedMethods(x, holder)
      }
      case x: ScBlock => {
        checkResultExpression(x, holder)
      }
      case ref: ScReferenceElement => {
        ref.qualifier match {
          case None => checkNotQualifiedReferenceElement(ref, holder)
          case Some(_) => checkQualifiedReferenceElement(ref, holder)
        }
      }
      case ret: ScReturnStmt => {
        checkExplicitTypeForReturnStatement(ret, holder)
      }
      case ml: ScModifierList => {
        ModifierChecker.checkModifiers(ml, holder)
      }
      case sFile: ScalaFile => {
        ImportTracker.getInstance(sFile.getProject).removeAnnotatedFile(sFile) //it must be last annotated element
      }
      case _ => AnnotatorHighlighter.highlightElement(element, holder)
    }
  }

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

    def getFixes = OuterImportsActionCreator.getOuterImportFixes(refElement, refElement.getProject())

    def processError(countError: Boolean, fixes: => Seq[IntentionAction]) = {
      //todo remove when resolve of unqualified expression will be fully implemented
      if (refElement.getManager.isInProject(refElement) && refElement.multiResolve(false).length == 0 &&
              (fixes.length > 0 || countError)) {
        val error = ScalaBundle.message("cannot.resolve", refElement.refName)
        val annotation = holder.createErrorAnnotation(refElement.nameId, error)
        annotation.setHighlightType(ProblemHighlightType.LIKE_UNKNOWN_SYMBOL)
        registerAddImportFix(refElement, annotation, fixes: _*)
      }
    }

    refElement.bind() match {
      case None =>
        refElement match {
          case e: ScReferenceExpression if e.getParent.isInstanceOf[ScPrefixExpr] &&
                  e.getParent.asInstanceOf[ScPrefixExpr].operation == e => //todo: this is hide !(Not Boolean)
          case e: ScReferenceExpression if e.getParent.isInstanceOf[ScInfixExpr] &&
                  e.getParent.asInstanceOf[ScInfixExpr].operation == e => //todo: this is hide A op B
          case e: ScReferenceExpression => processError(false, getFixes)
          case _ => refElement.getParent match {
            case s: ScImportSelector if refElement.multiResolve(false).length > 0 =>
            case _ => processError(true, getFixes)
          }
        }
      case Some(result) => {
        AnnotatorHighlighter.highlightReferenceElement(refElement, holder)
      }
    }
    for (result <- refElement.multiResolve(false) if result.isInstanceOf[ScalaResolveResult];
         scalaResult = result.asInstanceOf[ScalaResolveResult]) {
      registerUsedImports(refElement, scalaResult)
    }
  }

  private def checkQualifiedReferenceElement(refElement: ScReferenceElement, holder: AnnotationHolder) {
    AnnotatorHighlighter.highlightReferenceElement(refElement, holder)
    val settings: ScalaCodeStyleSettings =
           CodeStyleSettingsManager.getSettings(refElement.getProject).getCustomSettings(classOf[ScalaCodeStyleSettings])
    if (settings.CHECK_IMPLICITS) {
      for (result <- refElement.multiResolve(false) if result.isInstanceOf[ScalaResolveResult];
           scalaResult = result.asInstanceOf[ScalaResolveResult]) {
        registerUsedImports(refElement, scalaResult)
{'fraction_non_alphanumeric': 0.09103353867214237, 'fraction_numerical': 0.002151168475603794, 'mean_word_length': 3.7373784159333026, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 47, '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': '373564', 'n_tokens_mistral': 2973, 'n_tokens_neox': 2907, 'n_words': 546}