<commit_before>package org.jetbrains.plugins.scala.codeInspection.internal

import com.intellij.psi.{PsiJavaFile, PsiElement, PsiElementVisitor}
import org.jetbrains.plugins.scala.annotator.ScalaAnnotator
import java.lang.String
import com.intellij.openapi.util.TextRange
import com.intellij.lang.ASTNode
import com.intellij.lang.annotation.{HighlightSeverity, Annotation, AnnotationHolder}
import com.intellij.codeInspection._
import com.intellij.lang.annotation.AnnotationSession
import com.intellij.codeHighlighting.HighlightDisplayLevel
import com.intellij.codeInsight.daemon.impl.analysis.{HighlightInfoHolder, HighlightVisitorImpl}
import com.intellij.psi.impl.source.resolve.PsiResolveHelperImpl

/**
 * @author <NAME>
 */
class AnnotatorBasedErrorInspection extends LocalInspectionTool {
  override def isEnabledByDefault: Boolean = false

  override def getID: String = "AnnotatorBasedError"

  override def getGroupDisplayName: String = "Scala: Internal"

  override def getDefaultLevel: HighlightDisplayLevel = HighlightDisplayLevel.ERROR

  override def getDisplayName: String = "Error highlighting for Scala"

  override def buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean): PsiElementVisitor = {
    new PsiElementVisitor {
      override def visitElement(element: PsiElement) {
        val file = element.getContainingFile
        if (file.isInstanceOf[PsiJavaFile]) {
          val visitor = new HighlightVisitorImpl(new PsiResolveHelperImpl(file.getManager))
          val highlightInfoHolder = new HighlightInfoHolder(file)
          visitor.analyze(file, true, highlightInfoHolder, new Runnable {
            def run() {
              element.accept(visitor)
            }
          })
          if (highlightInfoHolder.hasErrorResults) {
            holder.registerProblem(element, "Error detected", ProblemHighlightType.ERROR, null: TextRange)
          }
        } else {
          val annotator = new ScalaAnnotator {
            override def isAdvancedHighlightingEnabled(element: PsiElement): Boolean = true
          }
          val FakeAnnotation = new com.intellij.lang.annotation.Annotation(
            0, 0, HighlightSeverity.INFO, "message", "tooltip")
          val annotationHolder = new AnnotationHolder {
            def createAnnotation(severity: HighlightSeverity, range: TextRange, str: String) = FakeAnnotation
            
            def isBatchMode: Boolean = false

            def createInfoAnnotation(range: TextRange, message: String): Annotation = FakeAnnotation

            def createInfoAnnotation(node: ASTNode, message: String): Annotation = FakeAnnotation

            def createInfoAnnotation(elt: PsiElement, message: String): Annotation = FakeAnnotation

            def createInformationAnnotation(range: TextRange, message: String): Annotation = FakeAnnotation

            def createInformationAnnotation(node: ASTNode, message: String): Annotation = FakeAnnotation

            def createInformationAnnotation(elt: PsiElement, message: String): Annotation = FakeAnnotation

            def createWarningAnnotation(range: TextRange, message: String): Annotation = FakeAnnotation

            def createWarningAnnotation(node: ASTNode, message: String): Annotation = FakeAnnotation

            def createWarningAnnotation(elt: PsiElement, message: String): Annotation = FakeAnnotation

            def createErrorAnnotation(range: TextRange, message: String): Annotation = {
              holder.registerProblem(element, s"Error detected: $message", ProblemHighlightType.ERROR)
              FakeAnnotation
            }

            def createErrorAnnotation(node: ASTNode, message: String): Annotation = {
              holder.registerProblem(element, s"Error detected: $message", ProblemHighlightType.ERROR)
              FakeAnnotation
            }

            def createErrorAnnotation(elt: PsiElement, message: String): Annotation = {
              holder.registerProblem(element, s"Error detected: $message", ProblemHighlightType.ERROR)
              FakeAnnotation
            }

            def getCurrentAnnotationSession: AnnotationSession = {
              new AnnotationSession(element.getContainingFile)
            }

            def createWeakWarningAnnotation(p1: TextRange, p2: String): Annotation = FakeAnnotation

            def createWeakWarningAnnotation(p1: ASTNode, p2: String): Annotation = FakeAnnotation

            def createWeakWarningAnnotation(p1: PsiElement, p2: String): Annotation = FakeAnnotation
          }
          annotator.annotate(element, annotationHolder)
        }
      }
    }
  }
}<commit_msg>Warnings info is collected in AnnotatorBasedErrorInspection<commit_after>package org.jetbrains.plugins.scala.codeInspection.internal

import com.intellij.psi.{PsiJavaFile, PsiElement, PsiElementVisitor}
import org.jetbrains.plugins.scala.annotator.ScalaAnnotator
import java.lang.String
import com.intellij.openapi.util.TextRange
import com.intellij.lang.ASTNode
import com.intellij.lang.annotation.{HighlightSeverity, Annotation, AnnotationHolder}
import com.intellij.codeInspection._
import com.intellij.lang.annotation.AnnotationSession
import com.intellij.codeHighlighting.HighlightDisplayLevel
import com.intellij.codeInsight.daemon.impl.analysis.{HighlightInfoHolder, HighlightVisitorImpl}
import com.intellij.psi.impl.source.resolve.PsiResolveHelperImpl

/**
 * @author <NAME>
 */
class AnnotatorBasedErrorInspection extends LocalInspectionTool {
  override def isEnabledByDefault: Boolean = false

  override def getID: String = "AnnotatorBasedError"

  override def getGroupDisplayName: String = "Scala: Internal"

  override def getDefaultLevel: HighlightDisplayLevel = HighlightDisplayLevel.ERROR

  override def getDisplayName: String = "Error highlighting for Scala"

  override def buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean): PsiElementVisitor = {
    new PsiElementVisitor {
      override def visitElement(element: PsiElement) {
        val file = element.getContainingFile
        if (file.isInstanceOf[PsiJavaFile]) {
          val visitor = new HighlightVisitorImpl(new PsiResolveHelperImpl(file.getManager))
          val highlightInfoHolder = new HighlightInfoHolder(file)
          visitor.analyze(file, true, highlightInfoHolder, new Runnable {
            def run() {
              element.accept(visitor)
            }
          })
          if (highlightInfoHolder.hasErrorResults) {
            holder.registerProblem(element, "Error detected", ProblemHighlightType.ERROR, null: TextRange)
          }
        } else {
          val annotator = new ScalaAnnotator {
            override def isAdvancedHighlightingEnabled(element: PsiElement): Boolean = true
          }
          val FakeAnnotation = new com.intellij.lang.annotation.Annotation(
            0, 0, HighlightSeverity.INFO, "message", "tooltip")
          val annotationHolder = new AnnotationHolder {
            def createAnnotation(severity: HighlightSeverity, range: TextRange, str: String) = FakeAnnotation
            
            def isBatchMode: Boolean = false

            def createInfoAnnotation(range: TextRange, message: String): Annotation = FakeAnnotation

            def createInfoAnnotation(node: ASTNode, message: String): Annotation = FakeAnnotation

            def createInfoAnnotation(elt: PsiElement, message: String): Annotation = FakeAnnotation

            def createInformationAnnotation(range: TextRange, message: String): Annotation = FakeAnnotation

            def createInformationAnnotation(node: ASTNode, message: String): Annotation = FakeAnnotation

            def createInformationAnnotation(elt: PsiElement, message: String): Annotation = FakeAnnotation

            def createWarningAnnotation(range: TextRange, message: String): Annotation = {
              holder.registerProblem(element, s"Warning: $message", ProblemHighlightType.GENERIC_ERROR_OR_WARNING)
              FakeAnnotation
            }

            def createWarningAnnotation(node: ASTNode, message: String): Annotation = {
              holder.registerProblem(element, s"Warning: $message", ProblemHighlightType.GENERIC_ERROR_OR_WARNING)
              FakeAnnotation
            }

            def createWarningAnnotation(elt: PsiElement, message: String): Annotation = {
              holder.registerProblem(element, s"Warning: $message", ProblemHighlightType.GENERIC_ERROR_OR_WARNING)
              FakeAnnotation
            }

            def createErrorAnnotation(range: TextRange, message: String): Annotation = {
              holder.registerProblem(element, s"Error detected: $message", ProblemHighlightType.ERROR)
              FakeAnnotation
            }

            def createErrorAnnotation(node: ASTNode, message: String): Annotation = {
              holder.registerProblem(element, s"Error detected: $message", ProblemHighlightType.ERROR)
              FakeAnnotation
            }

            def createErrorAnnotation(elt: PsiElement, message: String): Annotation = {
              holder.registerProblem(element, s"Error detected: $message", ProblemHighlightType.ERROR)
              FakeAnnotation
            }

            def getCurrentAnnotationSession: AnnotationSession = {
              new AnnotationSession(element.getContainingFile)
            }

            def createWeakWarningAnnotation(p1: TextRange, p2: String): Annotation = FakeAnnotation

            def createWeakWarningAnnotation(p1: ASTNode, p2: String): Annotation = FakeAnnotation

            def createWeakWarningAnnotation(p1: PsiElement, p2: String): Annotation = FakeAnnotation
          }
          annotator.annotate(element, annotationHolder)
        }
      }
    }
  }
}
{'fraction_non_alphanumeric': 0.07498197548666186, 'fraction_numerical': 0.0016479555052013595, 'mean_word_length': 3.258771929824561, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '6207452', 'n_tokens_mistral': 2524, 'n_tokens_neox': 2396, 'n_words': 557}