<commit_before>package org.jetbrains.plugins.scala
package annotator

import com.intellij.lang.annotation.AnnotationHolder
import lang.psi.api.toplevel.typedef.ScTemplateDefinition
import lang.psi.types.ScType
import org.jetbrains.plugins.scala.lang.psi.types.result.TypingContext
import lang.psi.api.expr.ScNewTemplateDefinition

/**
 * <NAME>
 */

trait TemplateDefinitionAnnotator {
  def annotateTemplateDefinition(defintion: ScTemplateDefinition, holder: AnnotationHolder) {
    val block = defintion.extendsBlock

    if (defintion.isInstanceOf[ScNewTemplateDefinition] && block.templateBody.isEmpty) return

    block.templateParents.toSeq.flatMap(_.typeElements).foreach { element =>
      element.getType(TypingContext.empty).toOption.toSeq
              .flatMap(ScType.extractClass(_).toSeq)
              .filter(_.getModifierList.hasModifierProperty("final")).foreach { aClass =>
        holder.createErrorAnnotation(element, "Illegal inheritance from final class %s".format(aClass.getName))
      }
    }
  }
}<commit_msg>SCL-2747 Highlight illegal inheritance from sealed class<commit_after>package org.jetbrains.plugins.scala
package annotator

import com.intellij.lang.annotation.AnnotationHolder
import lang.psi.api.toplevel.typedef.ScTemplateDefinition
import lang.psi.types.ScType
import org.jetbrains.plugins.scala.lang.psi.types.result.TypingContext
import lang.psi.api.expr.ScNewTemplateDefinition

/**
 * <NAME>
 */

trait TemplateDefinitionAnnotator {
  def annotateTemplateDefinition(defintion: ScTemplateDefinition, holder: AnnotationHolder) {
    val block = defintion.extendsBlock

    if (defintion.isInstanceOf[ScNewTemplateDefinition] && block.templateBody.isEmpty) return

    block.templateParents.toSeq.flatMap(_.typeElements).foreach { refElement =>
      val classes = refElement.getType(TypingContext.empty).toOption.toSeq
              .flatMap(ScType.extractClass(_).toSeq)

      classes.filter(_.getModifierList.hasModifierProperty("final")).foreach { it =>
        holder.createErrorAnnotation(refElement, "Illegal inheritance from final class %s".format(it.getName))
      }

      classes.filter(_.getModifierList.hasModifierProperty("sealed"))
              .filter(_.getContainingFile != refElement.getContainingFile).foreach { it =>
        holder.createErrorAnnotation(refElement, "Illegal inheritance from sealed type %s".format(it.getName))
      }
    }
  }
}
{'fraction_non_alphanumeric': 0.10286188303608461, 'fraction_numerical': 0.0016590626296142678, 'mean_word_length': 4.609302325581395, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 10, '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': '6649905', 'n_tokens_mistral': 704, 'n_tokens_neox': 684, 'n_words': 103}