annotationcheckers.scala
来自「JAVA 语言的函数式编程扩展」· SCALA 代码 · 共 61 行
SCALA
61 行
/* NSC -- new Scala compiler * Copyright 2007-2008 LAMP/EPFL * @author Martin Odersky */// $Id: AnnotationCheckers.scala 14416 2008-03-19 01:17:25Z mihaylov $package scala.tools.nsc.symtab/** Additions to the type checker that can be added at * run time. Typically these are added by * compiler plugins. */trait AnnotationCheckers { self: SymbolTable => /** An additional checker for annotations on types. * Typically these are registered by compiler plugins * with the addAnnotationChecker method. */ abstract class AnnotationChecker { /** Check the annotations on two types conform. */ def annotationsConform(tpe1: Type, tpe2: Type): Boolean /** Modify the type that has thus far been inferred * for a tree. All this should do is add annotations. */ def addAnnotations(tree: Tree, tpe: Type): Type = tpe } /** The list of annotation checkers that have been registered */ private var annotationCheckers: List[AnnotationChecker] = Nil /** Register an annotation checker. Typically these * are added by compiler plugins. */ def addAnnotationChecker(checker: AnnotationChecker) { if (!(annotationCheckers contains checker)) annotationCheckers = checker :: annotationCheckers } /** Remove all annotation checkers */ def removeAllAnnotationCheckers() { annotationCheckers = Nil } /** Check that the annotations on two types conform. To do * so, consult all registered annotation checkers. */ def annotationsConform(tp1: Type, tp2: Type): Boolean = { /* Finish quickly if there are no attributes */ if (tp1.attributes.isEmpty && tp2.attributes.isEmpty) true else annotationCheckers.forall( _.annotationsConform(tp1,tp2)) } /** Let all annotations checkers add extra annotations * to this tree's type. */ def addAnnotations(tree: Tree, tpe: Type): Type = { annotationCheckers.foldLeft(tpe)((tpe, checker) => checker.addAnnotations(tree, tpe)) }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?