<commit_before>package org.jetbrains.plugins.scala.codeInspection.declarationRedundancy.quickfix

import com.intellij.codeInsight.intention.IntentionAction
import com.intellij.codeInspection.LocalQuickFixAsIntentionAdapter
import org.jetbrains.plugins.scala.codeInspection.{ScalaAnnotatorQuickFixTestBase, ScalaInspectionBundle}
import org.jetbrains.plugins.scala.codeInspection.declarationRedundancy.ScalaAccessCanBeTightenedInspection
import org.jetbrains.plugins.scala.lang.psi.api.statements.ScPatternDefinition
import org.junit.Assert.assertTrue

/**
 * For the motivation behind this test, see
 * [[org.jetbrains.plugins.scala.codeInspection.declarationRedundancy.ScalaAccessCanBeTightenedInspection.quickFixText]]
 */

class MakePrivateQuickFixIsAboveAddTypeAnnotationQuickFixTest extends ScalaAnnotatorQuickFixTestBase {

  override protected val description = ScalaInspectionBundle.message("access.can.be.private")

  override def setUp(): Unit = {
    super.setUp()
    myFixture.enableInspections(classOf[ScalaAccessCanBeTightenedInspection])
  }

  private def unwrapFix(intentionAction: IntentionAction): ScalaAccessCanBeTightenedInspection.MakePrivateQuickFix = {
    val wrappedFix = intentionAction.asInstanceOf[LocalQuickFixAsIntentionAdapter]
    val myFixField = wrappedFix.getClass.getDeclaredField("myFix")
    myFixField.setAccessible(true)
    myFixField.get(wrappedFix).asInstanceOf[ScalaAccessCanBeTightenedInspection.MakePrivateQuickFix]
  }

  def test_text_when_add_type_annotation_quickfix_is_offered(): Unit = {
    val code = s"class A { val a = new A }; private class B { val b = new A().a }"
    val fixes = doFindQuickFixes(code, ScalaInspectionBundle.message("add.private.modifier"))

    assertTrue(fixes.size == 1)

    val makePrivateQuickFix = unwrapFix(fixes.head)

    val quickFixElement = makePrivateQuickFix.getStartElement.asInstanceOf[ScPatternDefinition]
    assert(quickFixElement.declaredNames.head == "b")
  }

  def test_text_when_add_type_annotation_quickfix_is_not_offered(): Unit = {
    val code = s"class A { val a = 42 }"
    val fixes = doFindQuickFixes(code, ScalaInspectionBundle.message("make.private"))

    assertTrue(fixes.size == 1)

    val makePrivateQuickFix = unwrapFix(fixes.head)

    val quickFixElement = makePrivateQuickFix.getStartElement.asInstanceOf[ScPatternDefinition]
    assert(quickFixElement.declaredNames.head == "a")
  }
}<commit_msg>Do not use reflection in MakePrivateQuickFixIsAbove...Test #SCL-20636<commit_after>package org.jetbrains.plugins.scala.codeInspection.declarationRedundancy.quickfix

import com.intellij.codeInsight.daemon.impl.HighlightInfo
import com.intellij.openapi.util.TextRange
import org.jetbrains.plugins.scala.codeInspection.declarationRedundancy.ScalaAccessCanBeTightenedInspection
import org.jetbrains.plugins.scala.codeInspection.{ScalaAnnotatorQuickFixTestBase, ScalaInspectionBundle}
import org.junit.Assert.assertTrue

/**
 * For the motivation behind this test, see
 * [[org.jetbrains.plugins.scala.codeInspection.declarationRedundancy.ScalaAccessCanBeTightenedInspection.quickFixText]]
 */

class MakePrivateQuickFixIsAboveAddTypeAnnotationQuickFixTest extends ScalaAnnotatorQuickFixTestBase {

  override protected val description = ScalaInspectionBundle.message("access.can.be.private")

  override def setUp(): Unit = {
    super.setUp()
    myFixture.enableInspections(classOf[ScalaAccessCanBeTightenedInspection])
  }

  def test_text_when_add_type_annotation_quickfix_is_offered(): Unit = {
    val code = s"private class A { val a = new A }; private class B { val b = new A().a }"

    val highlights = configureByText(code).actualHighlights
    assert(highlights.size == 1)
    val (descriptor: HighlightInfo.IntentionActionDescriptor, range: TextRange) = highlights.head.findRegisteredQuickFix((a, b)  => (a, b))
    assert(range == new TextRange(57, 58))
    assertTrue(descriptor.getAction.getText == ScalaInspectionBundle.message("add.private.modifier"))
  }

  def test_text_when_add_type_annotation_quickfix_is_not_offered(): Unit = {
    val code = s"private class A { val a = 42 }"

    val highlights = configureByText(code).actualHighlights
    assert(highlights.size == 1)
    val (descriptor: HighlightInfo.IntentionActionDescriptor, range: TextRange) = highlights.head.findRegisteredQuickFix((a, b) => (a, b))
    assert(range == new TextRange(22, 23))
    assertTrue(descriptor.getAction.getText == ScalaInspectionBundle.message("make.private"))
  }
}
{'fraction_non_alphanumeric': 0.09349955476402494, 'fraction_numerical': 0.004674977738201247, 'mean_word_length': 6.097946287519747, 'pattern_counts': {'":': 0, '<': 3, '<?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': '4676202', 'n_tokens_mistral': 1432, 'n_tokens_neox': 1378, 'n_words': 219}