<commit_before>package org.jetbrains.plugins.scala
package lang
package psi
package impl
package expr

import com.intellij.psi.util.PsiTreeUtil
import types.{Bounds, ScDesignatorType, Nothing}
import psi.ScalaPsiElementImpl
import api.expr._
import com.intellij.lang.ASTNode
import api.toplevel.typedef.{ScTemplateDefinition, ScTypeDefinition}
import types.result.{TypingContext, Failure, Success}

/**
 * @author <NAME>
 * Date: 06.03.2008
 */

class ScThisReferenceImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with ScThisReference {
  override def toString: String = "ThisReference"

  protected override def innerType(ctx: TypingContext) = refTemplate match {
    case Some(td) => td.getType(ctx) map { refType =>
      td.selfType match {
        case Some(t) => Bounds.glb(refType, t)
        case None => refType
      }
    }
    case _ => Failure("Cannot infer type", Some(this))
  }

  def refTemplate = reference match {
    case Some(ref) => ref.resolve match {
      case td: ScTypeDefinition => Some(td)
      case _ => None
    }
    case None => {
      val encl = PsiTreeUtil.getContextOfType(this, classOf[ScTemplateDefinition], false)
      if (encl != null) Some(encl) else None
    }
  }
}<commit_msg>scala-liobrary updated for tests fixed SOE (this reference to enclosing TemplateBody instead TemplateDef)<commit_after>package org.jetbrains.plugins.scala
package lang
package psi
package impl
package expr

import com.intellij.psi.util.PsiTreeUtil
import types.{Bounds, ScDesignatorType, Nothing}
import psi.ScalaPsiElementImpl
import api.expr._
import com.intellij.lang.ASTNode
import api.toplevel.typedef.{ScTemplateDefinition, ScTypeDefinition}
import types.result.{TypingContext, Failure, Success}
import api.base.ScConstructor
import com.intellij.psi.PsiElement
import api.toplevel.templates.ScTemplateBody

/**
 * @author <NAME>
 * Date: 06.03.2008
 */

class ScThisReferenceImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with ScThisReference {
  override def toString: String = "ThisReference"

  protected override def innerType(ctx: TypingContext) = refTemplate match {
    case Some(td) => td.getType(ctx) map { refType =>
      td.selfType match {
        case Some(t) => Bounds.glb(refType, t)
        case None => refType
      }
    }
    case _ => Failure("Cannot infer type", Some(this))
  }

  def refTemplate = reference match {
    case Some(ref) => ref.resolve match {
      case td: ScTypeDefinition => Some(td)
      case _ => None
    }
    case None => {
      val encl = PsiTreeUtil.getContextOfType(this, classOf[ScTemplateBody], false)
      if (encl != null) Some(PsiTreeUtil.getContextOfType(encl, classOf[ScTemplateDefinition], false)) else None
    }
  }
}
{'fraction_non_alphanumeric': 0.1027900146842878, 'fraction_numerical': 0.005873715124816446, 'mean_word_length': 4.0, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 23, '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': '6348719', 'n_tokens_mistral': 862, 'n_tokens_neox': 831, 'n_words': 216}