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

import com.intellij.codeInspection.ProblemsHolder
import codeInspection.AbstractInspection
import lang.psi.api.expr.ScReferenceExpression
import com.intellij.psi.util.PsiTreeUtil
import lang.psi.api.toplevel.typedef.ScMember
import lang.psi.api.toplevel.templates.ScTemplateBody
import lang.psi.api.statements.{ScVariable, ScValue}
import lang.resolve.ScalaResolveResult
import lang.psi.ScalaPsiUtil

/**
 * <NAME>
 */

class ForwardReferenceInspection extends AbstractInspection {

  def actionFor(holder: ProblemsHolder) = {
    case ref: ScReferenceExpression =>
      val member: ScMember = PsiTreeUtil.getParentOfType(ref, classOf[ScMember])
      if (member != null) {
        member.getContext match {
          case tb: ScTemplateBody if member.isInstanceOf[ScValue] || member.isInstanceOf[ScVariable] =>
            ref.bind() match {
              case Some(r: ScalaResolveResult) =>
                ScalaPsiUtil.nameContext(r.getActualElement) match {
                  case resolved if resolved.isInstanceOf[ScValue] || resolved.isInstanceOf[ScVariable] =>
                    if (resolved.getParent == tb && resolved.getTextOffset > member.getTextOffset) {
                      holder.registerProblem(ref, ScalaBundle.message("suspicicious.forward.reference.template.body"))
                    }
                  case _ =>
                }
              case _ =>
            }
          case _ =>
        }
      }
  }
}<commit_msg>Fixed inspection for lazy values: #SCL-2891<commit_after>package org.jetbrains.plugins.scala
package codeInspection.forwardReferenceInspection

import com.intellij.codeInspection.ProblemsHolder
import codeInspection.AbstractInspection
import lang.psi.api.expr.ScReferenceExpression
import com.intellij.psi.util.PsiTreeUtil
import lang.psi.api.toplevel.typedef.ScMember
import lang.psi.api.toplevel.templates.ScTemplateBody
import lang.psi.api.statements.{ScVariable, ScValue}
import lang.resolve.ScalaResolveResult
import lang.psi.ScalaPsiUtil

/**
 * Alefas
 */
class ForwardReferenceInspection extends AbstractInspection {
  def actionFor(holder: ProblemsHolder) = {
    case ref: ScReferenceExpression =>
      val member: ScMember = PsiTreeUtil.getParentOfType(ref, classOf[ScMember])
      if (member != null) {
        member.getContext match {
          case tb: ScTemplateBody if member.isInstanceOf[ScValue] || member.isInstanceOf[ScVariable] =>
            ref.bind() match {
              case Some(r: ScalaResolveResult) =>
                ScalaPsiUtil.nameContext(r.getActualElement) match {
                  case resolved if resolved.isInstanceOf[ScValue] || resolved.isInstanceOf[ScVariable]=>
                    if (resolved.getParent == tb && !member.hasModifierProperty("lazy") &&
                      !resolved.asInstanceOf[ScMember].hasModifierProperty("lazy") &&
                      resolved.getTextOffset > member.getTextOffset) {
                      holder.registerProblem(ref, ScalaBundle.message("suspicicious.forward.reference.template.body"))
                    }
                  case _ =>
                }
              case _ =>
            }
          case _ =>
        }
      }
  }
}
{'fraction_non_alphanumeric': 0.09395973154362416, 'fraction_numerical': 0.0012202562538133007, 'mean_word_length': 2.7474285714285713, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 20, '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': '7397430', 'n_tokens_mistral': 926, 'n_tokens_neox': 892, 'n_words': 151}