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

import com.intellij.codeInspection.ui.SingleCheckboxOptionsPanel
import com.intellij.codeInspection.{InspectionManager, LocalQuickFix, ProblemDescriptor, ProblemHighlightType}
import com.intellij.psi.PsiElement
import org.jetbrains.annotations.Nls
import org.jetbrains.plugins.scala.codeInspection.quickfix.{RemoveExpressionQuickFix, RemoveReturnKeywordQuickFix}
import org.jetbrains.plugins.scala.codeInspection.{AbstractRegisteredInspection, ScalaInspectionBundle}
import org.jetbrains.plugins.scala.lang.psi.api.ScalaPsiElement
import org.jetbrains.plugins.scala.lang.psi.api.expr.{ScFunctionExpr, ScMethodCall, ScReturn}
import org.jetbrains.plugins.scala.lang.psi.api.statements.ScFunctionDefinition
import org.jetbrains.plugins.scala.project.{ModuleExt, ProjectPsiElementExt}

import javax.swing.JComponent
import scala.annotation.tailrec

final class NonLocalReturnInspection extends AbstractRegisteredInspection {
  import NonLocalReturnInspection._

  override protected def problemDescriptor(element: PsiElement,
                                           maybeQuickFix: Option[LocalQuickFix],
                                           descriptionTemplate: String,
                                           highlightType: ProblemHighlightType)
                                          (implicit manager: InspectionManager, isOnTheFly: Boolean): Option[ProblemDescriptor] = {
    def isCompilerOptionPresent: Boolean =
      element.module.exists(_.scalaCompilerSettings.additionalCompilerOptions.contains("-Xlint:nonlocal-return"))

    element match {
      case function: ScFunctionDefinition if !checkCompilerOption || isCompilerOptionPresent =>
        function.returnUsages.collectFirst {
            case scReturn: ScReturn if isInsideAnonymousFunction(scReturn) =>
              manager.createProblemDescriptor(
                scReturn,
                annotationDescription,
                isOnTheFly,
                createQuickFixes(scReturn),
                ProblemHighlightType.GENERIC_ERROR_OR_WARNING
              )
          }
      case _ =>
        None
    }
  }

  // for the checkbox to work, the var needs to be public, and there have to be a getter and a setter - because of Java reflection
  var checkCompilerOption: Boolean = false

  def isCheckCompilerOption: Boolean = checkCompilerOption

  def setCheckCompilerOption(checkCompilerOption: Boolean): Unit = {
    this.checkCompilerOption = checkCompilerOption
  }

  @Override
  override def createOptionsPanel(): JComponent =
    new SingleCheckboxOptionsPanel(
      ScalaInspectionBundle.message("nonlocal.return.check.compiler.option"),
      this,
      "checkCompilerOption"
    )
}

object NonLocalReturnInspection {
  @Nls
  val annotationDescription: String = ScalaInspectionBundle.message("nonlocal.return.statement")
<commit_msg>checkCompilerOption decorated with BooleanBeanProperty<commit_after>package org.jetbrains.plugins.scala.codeInspection.controlFlow

import com.intellij.codeInspection.ui.SingleCheckboxOptionsPanel
import com.intellij.codeInspection.{InspectionManager, LocalQuickFix, ProblemDescriptor, ProblemHighlightType}
import com.intellij.psi.PsiElement
import org.jetbrains.annotations.Nls
import org.jetbrains.plugins.scala.codeInspection.quickfix.{RemoveExpressionQuickFix, RemoveReturnKeywordQuickFix}
import org.jetbrains.plugins.scala.codeInspection.{AbstractRegisteredInspection, ScalaInspectionBundle}
import org.jetbrains.plugins.scala.lang.psi.api.ScalaPsiElement
import org.jetbrains.plugins.scala.lang.psi.api.expr.{ScFunctionExpr, ScMethodCall, ScReturn}
import org.jetbrains.plugins.scala.lang.psi.api.statements.ScFunctionDefinition
import org.jetbrains.plugins.scala.project.{ModuleExt, ProjectPsiElementExt}

import javax.swing.JComponent
import scala.annotation.tailrec
import scala.beans.BooleanBeanProperty

final class NonLocalReturnInspection extends AbstractRegisteredInspection {
  import NonLocalReturnInspection._

  @BooleanBeanProperty
  var checkCompilerOption: Boolean = false

  @Override
  override def createOptionsPanel(): JComponent =
    new SingleCheckboxOptionsPanel(
      ScalaInspectionBundle.message("nonlocal.return.check.compiler.option"),
      this,
      "checkCompilerOption"
    )

  override protected def problemDescriptor(element: PsiElement,
                                           maybeQuickFix: Option[LocalQuickFix],
                                           descriptionTemplate: String,
                                           highlightType: ProblemHighlightType)
                                          (implicit manager: InspectionManager, isOnTheFly: Boolean): Option[ProblemDescriptor] = {
    def isCompilerOptionPresent: Boolean =
      element.module.exists(_.scalaCompilerSettings.additionalCompilerOptions.contains("-Xlint:nonlocal-return"))

    element match {
      case function: ScFunctionDefinition if !checkCompilerOption || isCompilerOptionPresent =>
        function.returnUsages.collectFirst {
            case scReturn: ScReturn if isInsideAnonymousFunction(scReturn) =>
              manager.createProblemDescriptor(
                scReturn,
                annotationDescription,
                isOnTheFly,
                createQuickFixes(scReturn),
                ProblemHighlightType.GENERIC_ERROR_OR_WARNING
              )
          }
      case _ =>
        None
    }
  }
}

object NonLocalReturnInspection {
  @Nls
  val annotationDescription: String = ScalaInspectionBundle.message("nonlocal.return.statement")

{'fraction_non_alphanumeric': 0.069303402814894, 'fraction_numerical': 0.0, 'mean_word_length': 3.3893666927286943, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '989028', 'n_tokens_mistral': 1454, 'n_tokens_neox': 1378, 'n_words': 251}