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

import collection.mutable.HashSet
import com.intellij.codeInsight.intention.IntentionAction
import com.intellij.openapi.util.{Key, TextRange}
import com.intellij.psi.util.PsiTreeUtil
import controlFlow.ControlFlowInspections
import createFromUsage._
import highlighter.AnnotatorHighlighter
import importsTracker._
import lang.psi.api.statements._
import lang.psi.api.toplevel.typedef._
import lang.psi.api.toplevel.templates.ScTemplateBody
import com.intellij.lang.annotation._

import lang.psi.api.toplevel.imports.{ScImportExpr, ScImportSelector}
import org.jetbrains.plugins.scala.lang.psi.api.base._
import org.jetbrains.plugins.scala.lang.resolve._
import com.intellij.codeInspection._
import org.jetbrains.plugins.scala.annotator.intention._
import org.jetbrains.plugins.scala.overrideImplement.ScalaOIUtil
import params.{ScParameter, ScParameters, ScClassParameter}
import patterns.{ScInfixPattern, ScBindingPattern}
import quickfix.modifiers.{RemoveModifierQuickFix, AddModifierQuickFix}
import modifiers.ModifierChecker
import org.jetbrains.plugins.scala.lang.formatting.settings.ScalaCodeStyleSettings
import com.intellij.psi._
import com.intellij.psi.codeStyle.CodeStyleSettingsManager
import org.jetbrains.plugins.scala.lang.psi.api.toplevel.ScTypeBoundsOwner
import quickfix.{ChangeTypeFix, ReportHighlightingErrorQuickFix, ImplementMethodsQuickFix}
import template._
import types.ScTypeElement
import scala.Some
import com.intellij.openapi.project.DumbAware
import org.jetbrains.plugins.scala.lang.psi.api.ScalaFile
import org.jetbrains.plugins.scala.lang.psi.types.result.{TypingContext, TypeResult, Success}
import org.jetbrains.plugins.scala.lang.psi.api.expr.ScExpression.ExpressionTypeResult
import com.intellij.openapi.editor.markup.{EffectType, TextAttributes}
import java.awt.{Font, Color}
import org.jetbrains.plugins.scala.lang.psi.ScalaPsiUtil
import components.HighlightingAdvisor
import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiElementFactory
import org.jetbrains.plugins.scala.extensions._
import collection.{Seq, Set}
import org.jetbrains.plugins.scala.lang.psi.api.toplevel.imports.usages.{ReadValueUsed, WriteValueUsed, ValueUsed, ImportUsed}
import org.jetbrains.plugins.scala.lang.psi.types._
import org.jetbrains.plugins.scala.lang.psi.api.expr._
import org.jetbrains.plugins.scala.lang.scaladoc.psi.api.ScDocResolvableCodeReference

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

class ScalaAnnotator extends Annotator with FunctionAnnotator with ScopeAnnotator 
        with ParametersAnnotator with ApplicationAnnotator
        with AssignmentAnnotator with VariableDefinitionAnnotator
        with TypedStatementAnnotator with PatternDefinitionAnnotator
        with ControlFlowInspections with ConstructorAnnotator
        with DumbAware {
  override def annotate(element: PsiElement, holder: AnnotationHolder) {
    val typeAware = isAdvancedHighlightingEnabled(element)

    val compiled = element.getContainingFile match {
      case file: ScalaFile => file.isCompiled
      case _ => false
    }

    if (!compiled && element.isInstanceOf[ScExpression]) {
      val expr = element.asInstanceOf[ScExpression]
      checkExpressionType(expr, holder, typeAware)
      checkExpressionImplicitParameters(expr, holder)
      ByNameParameter.annotate(expr, holder, typeAware)
    }

    if (element.isInstanceOf[ScTypeElement]) {
      checkTypeElementForm(element.asInstanceOf[ScTypeElement], holder)
    }

    if (element.isInstanceOf[ScAnnotation]) {
      checkAnnotationType(element.asInstanceOf[ScAnnotation], holder)
    }

    if (element.isInstanceOf[ScForStatement]) {
      checkForStmtUsedTypes(element.asInstanceOf[ScForStatement], holder)
    }

    if (element.isInstanceOf[ScVariableDefinition]) {
      annotateVariableDefinition(element.asInstanceOf[ScVariableDefinition], holder, typeAware)
    }

    if (element.isInstanceOf[ScTypedStmt]) {
      annotateTypedStatement(element.asInstanceOf[ScTypedStmt], holder, typeAware)
    }

    if (!compiled && element.isInstanceOf[ScPatternDefinition]) {
      annotatePatternDefinition(element.asInstanceOf[ScPatternDefinition], holder, typeAware)
    }
    if (element.isInstanceOf[ScMethodCall]) {
      val call = element.asInstanceOf[ScMethodCall]
      checkMethodCallImplicitConversion(call, holder)
      annotateMethodCall(call, holder)
    }
    if (element.isInstanceOf[ScSelfInvocation]) {
      checkSelfInvocation(element.asInstanceOf[ScSelfInvocation], holder)
    }
    if (element.isInstanceOf[ScConstrBlock]) {
      annotateAuxiliaryConstructor(element.asInstanceOf[ScConstrBlock], holder)
    }

    if (element.isInstanceOf[ScParameter]) {
      annotateParameter(element.asInstanceOf[ScParameter], holder)
    }

    annotateScope(element, holder)

    if (isAdvancedHighlightingEnabled(element) && settings(element).SHOW_IMPLICIT_CONVERSIONS) {
      element match {
        case expr: ScExpression =>
          expr.getTypeExt(TypingContext.empty) match {
            case ExpressionTypeResult(Success(t, _), _, Some(implicitFunction)) =>
              highlightImplicitView(expr, implicitFunction, t, expr, holder)
            case _ =>
          }
        case _ =>
      }
    }

    element match {
      case a: ScAssignStmt => annotateAssignment(a, holder, typeAware)
      
      case ps: ScParameters => annotateParameters(ps, holder) 
      
      case f: ScFunctionDefinition if !compiled && !f.isConstructor => {
        annotateFunction(f, holder, typeAware)
      }
      
      case x: ScFunction if x.getParent.isInstanceOf[ScTemplateBody] => {
        //todo: unhandled case abstract override
        checkOverrideMethods(x, holder)
      }
      case x: ScTemplateDefinition => {
        val tdParts = Seq(AbstractInstantiation, FinalClassInheritance, IllegalInheritance, ObjectCreationImpossible,
          MultipleInheritance, NeedsToBeAbstract, NeedsToBeTrait, SealedClassInheritance, UndefinedMember)
        tdParts.foreach(_.annotate(x, holder, typeAware))<commit_msg>Removed wrong check of override modifier in compiled classes.<commit_after>package org.jetbrains.plugins.scala
package annotator

import collection.mutable.HashSet
import com.intellij.codeInsight.intention.IntentionAction
import com.intellij.openapi.util.{Key, TextRange}
import com.intellij.psi.util.PsiTreeUtil
import controlFlow.ControlFlowInspections
import createFromUsage._
import highlighter.AnnotatorHighlighter
import importsTracker._
import lang.psi.api.statements._
import lang.psi.api.toplevel.typedef._
import lang.psi.api.toplevel.templates.ScTemplateBody
import com.intellij.lang.annotation._

import lang.psi.api.toplevel.imports.{ScImportExpr, ScImportSelector}
import org.jetbrains.plugins.scala.lang.psi.api.base._
import org.jetbrains.plugins.scala.lang.resolve._
import com.intellij.codeInspection._
import org.jetbrains.plugins.scala.annotator.intention._
import org.jetbrains.plugins.scala.overrideImplement.ScalaOIUtil
import params.{ScParameter, ScParameters, ScClassParameter}
import patterns.{ScInfixPattern, ScBindingPattern}
import quickfix.modifiers.{RemoveModifierQuickFix, AddModifierQuickFix}
import modifiers.ModifierChecker
import org.jetbrains.plugins.scala.lang.formatting.settings.ScalaCodeStyleSettings
import com.intellij.psi._
import com.intellij.psi.codeStyle.CodeStyleSettingsManager
import org.jetbrains.plugins.scala.lang.psi.api.toplevel.ScTypeBoundsOwner
import quickfix.{ChangeTypeFix, ReportHighlightingErrorQuickFix, ImplementMethodsQuickFix}
import template._
import types.ScTypeElement
import scala.Some
import com.intellij.openapi.project.DumbAware
import org.jetbrains.plugins.scala.lang.psi.api.ScalaFile
import org.jetbrains.plugins.scala.lang.psi.types.result.{TypingContext, TypeResult, Success}
import org.jetbrains.plugins.scala.lang.psi.api.expr.ScExpression.ExpressionTypeResult
import com.intellij.openapi.editor.markup.{EffectType, TextAttributes}
import java.awt.{Font, Color}
import org.jetbrains.plugins.scala.lang.psi.ScalaPsiUtil
import components.HighlightingAdvisor
import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiElementFactory
import org.jetbrains.plugins.scala.extensions._
import collection.{Seq, Set}
import org.jetbrains.plugins.scala.lang.psi.api.toplevel.imports.usages.{ReadValueUsed, WriteValueUsed, ValueUsed, ImportUsed}
import org.jetbrains.plugins.scala.lang.psi.types._
import org.jetbrains.plugins.scala.lang.psi.api.expr._
import org.jetbrains.plugins.scala.lang.scaladoc.psi.api.ScDocResolvableCodeReference

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

class ScalaAnnotator extends Annotator with FunctionAnnotator with ScopeAnnotator 
        with ParametersAnnotator with ApplicationAnnotator
        with AssignmentAnnotator with VariableDefinitionAnnotator
        with TypedStatementAnnotator with PatternDefinitionAnnotator
        with ControlFlowInspections with ConstructorAnnotator
        with DumbAware {
  override def annotate(element: PsiElement, holder: AnnotationHolder) {
    val typeAware = isAdvancedHighlightingEnabled(element)

    val compiled = element.getContainingFile match {
      case file: ScalaFile => file.isCompiled
      case _ => false
    }

    if (!compiled && element.isInstanceOf[ScExpression]) {
      val expr = element.asInstanceOf[ScExpression]
      checkExpressionType(expr, holder, typeAware)
      checkExpressionImplicitParameters(expr, holder)
      ByNameParameter.annotate(expr, holder, typeAware)
    }

    if (element.isInstanceOf[ScTypeElement]) {
      checkTypeElementForm(element.asInstanceOf[ScTypeElement], holder)
    }

    if (element.isInstanceOf[ScAnnotation]) {
      checkAnnotationType(element.asInstanceOf[ScAnnotation], holder)
    }

    if (element.isInstanceOf[ScForStatement]) {
      checkForStmtUsedTypes(element.asInstanceOf[ScForStatement], holder)
    }

    if (element.isInstanceOf[ScVariableDefinition]) {
      annotateVariableDefinition(element.asInstanceOf[ScVariableDefinition], holder, typeAware)
    }

    if (element.isInstanceOf[ScTypedStmt]) {
      annotateTypedStatement(element.asInstanceOf[ScTypedStmt], holder, typeAware)
    }

    if (!compiled && element.isInstanceOf[ScPatternDefinition]) {
      annotatePatternDefinition(element.asInstanceOf[ScPatternDefinition], holder, typeAware)
    }
    if (element.isInstanceOf[ScMethodCall]) {
      val call = element.asInstanceOf[ScMethodCall]
      checkMethodCallImplicitConversion(call, holder)
      annotateMethodCall(call, holder)
    }
    if (element.isInstanceOf[ScSelfInvocation]) {
      checkSelfInvocation(element.asInstanceOf[ScSelfInvocation], holder)
    }
    if (element.isInstanceOf[ScConstrBlock]) {
      annotateAuxiliaryConstructor(element.asInstanceOf[ScConstrBlock], holder)
    }

    if (element.isInstanceOf[ScParameter]) {
      annotateParameter(element.asInstanceOf[ScParameter], holder)
    }

    annotateScope(element, holder)

    if (isAdvancedHighlightingEnabled(element) && settings(element).SHOW_IMPLICIT_CONVERSIONS) {
      element match {
        case expr: ScExpression =>
          expr.getTypeExt(TypingContext.empty) match {
            case ExpressionTypeResult(Success(t, _), _, Some(implicitFunction)) =>
              highlightImplicitView(expr, implicitFunction, t, expr, holder)
            case _ =>
          }
        case _ =>
      }
    }
    
    if (element.isInstanceOf[ScFunctionDefinition]) {
      val f: ScFunctionDefinition = element.asInstanceOf[ScFunctionDefinition]
      if (!compiled && !f.isConstructor)
        annotateFunction(f, holder, typeAware)
    }
    
    if (element.isInstanceOf[ScFunction] && typeAware && !compiled && element.getParent.isInstanceOf[ScTemplateBody]) {
      //todo: unhandled case abstract override
      //todo: other kinds of members
      //checkOverrideMethods(element.asInstanceOf[ScFunction], holder)
    }

    element match {
      case a: ScAssignStmt => annotateAssignment(a, holder, typeAware)
      case ps: ScParameters => annotateParameters(ps, holder)
      case x: ScTemplateDefinition => {
        val tdParts = Seq(AbstractInstantiation, FinalClassInheritance, IllegalInheritance, ObjectCreationImpossible,
          MultipleInheritance, NeedsToBeAbstract, NeedsToBeTrait, SealedClassInheritance, UndefinedMember)
        tdParts.foreach(_.annotate(x, holder, typeAware))
{'fraction_non_alphanumeric': 0.08946226187605498, 'fraction_numerical': 0.0012860702515874929, 'mean_word_length': 4.686471663619744, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 25, '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': '2275245', 'n_tokens_mistral': 3746, 'n_tokens_neox': 3608, 'n_words': 605}