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

import com.intellij.psi.util.PsiTreeUtil
import psi.ScalaPsiElementImpl
import api.expr._
import com.intellij.lang.ASTNode
import api.toplevel.typedef.{ScTemplateDefinition, ScTypeDefinition}
import api.base.ScConstructor
import com.intellij.psi.PsiElement
import api.toplevel.templates.ScTemplateBody
import types._
import result.{TypeResult, 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): TypeResult[ScType] = refTemplate match {
    case Some(td) => {
      val innerType: ScType = td.getType(TypingContext.empty).
              getOrElse(return Failure("No clazz type found", Some(this)))
      expectedType match {
        case Some(ScThisType(_)) => Success(ScThisType(innerType), Some(this))
        case _ => Success(innerType, Some(this))<commit_msg>This Reference type inference improved, when there is self type in type definition.<commit_after>package org.jetbrains.plugins.scala
package lang
package psi
package impl
package expr

import com.intellij.psi.util.PsiTreeUtil
import psi.ScalaPsiElementImpl
import api.expr._
import com.intellij.lang.ASTNode
import api.toplevel.typedef.{ScTemplateDefinition, ScTypeDefinition}
import api.base.ScConstructor
import com.intellij.psi.PsiElement
import api.toplevel.templates.ScTemplateBody
import types._
import result.{TypeResult, 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): TypeResult[ScType] = refTemplate match {
    case Some(td) => {
      val innerType: ScType = td.getType(TypingContext.empty).map(tp => {
        td.selfType match {
          case Some(selfType) => Bounds.glb(tp, selfType)
          case _ => tp
        }
      }).
              getOrElse(return Failure("No clazz type found", Some(this)))
      expectedType match {
        case Some(ScThisType(_)) => Success(ScThisType(innerType), Some(this))
        case _ => Success(innerType, Some(this))
{'fraction_non_alphanumeric': 0.10033167495854063, 'fraction_numerical': 0.006633499170812604, 'mean_word_length': 4.471655328798186, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 14, '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': '2895511', 'n_tokens_mistral': 734, 'n_tokens_neox': 707, 'n_words': 177}