diff options
author | Paul Phillips <paulp@improving.org> | 2011-10-10 06:24:46 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2011-10-10 06:24:46 +0000 |
commit | 4e86106b5b0637aa88de2e3d5a8751d918e4c069 (patch) | |
tree | fd4fc08760ffd102b590f670720c8846e41fb15e /src/compiler/scala/reflect/internal/Symbols.scala | |
parent | 1706358bdcf0492b82e87c8f34e9b7120348df8b (diff) | |
download | scala-4e86106b5b0637aa88de2e3d5a8751d918e4c069.tar.gz scala-4e86106b5b0637aa88de2e3d5a8751d918e4c069.tar.bz2 scala-4e86106b5b0637aa88de2e3d5a8751d918e4c069.zip |
Moved meta annotations to annotation.meta, plus.
It took me a long time to find a trivial error while adjusting the
annotation packages, so I spent even longer trying to make sure next
time it would take me less time. It's the usual business of eliminating
duplication and unnecessary indirection.
Behavioral note: there was no consistency or deducible reasoning
regarding when annotation checks would be performed against the
typeSymbol directly (thus excluding annotation subclasses) or when they
would do a subclass check. I saw no reason it shouldn't always be a
subclass check; if the annotation isn't supposed to be subclassed it
should be final, and if it is, then the subclasses had probably better
not stop exhibiting the behavior of the base class.
Example: this now draws deprecated warnings, but did not before.
class bippy extends deprecated("hi mom", "burma shave")
@bippy def f = 5
(The deprecation message isn't printed so we're not there yet, but
closer.)
There is some new internal documentation on annotations, sadly lacking
in my famous ascii diagrams, and some new conveniences. Review by rytz.
Diffstat (limited to 'src/compiler/scala/reflect/internal/Symbols.scala')
-rw-r--r-- | src/compiler/scala/reflect/internal/Symbols.scala | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/src/compiler/scala/reflect/internal/Symbols.scala b/src/compiler/scala/reflect/internal/Symbols.scala index 533a343589..db17306768 100644 --- a/src/compiler/scala/reflect/internal/Symbols.scala +++ b/src/compiler/scala/reflect/internal/Symbols.scala @@ -42,7 +42,10 @@ trait Symbols extends api.Symbols { self: SymbolTable => val originalOwner = perRunCaches.newMap[Symbol, Symbol]() /** The class for all symbols */ - abstract class Symbol(initOwner: Symbol, initPos: Position, initName: Name) extends AbsSymbol with HasFlags { + abstract class Symbol(initOwner: Symbol, initPos: Position, initName: Name) + extends AbsSymbol + with HasFlags + with Annotatable[Symbol] { type FlagsType = Long type AccessBoundaryType = Symbol @@ -1166,25 +1169,25 @@ trait Symbols extends api.Symbols { self: SymbolTable => annots1 } - def setAnnotations(annots: List[AnnotationInfoBase]): this.type = { + def setRawAnnotations(annots: List[AnnotationInfoBase]): this.type = { this.rawannots = annots this } + def setAnnotations(annots: List[AnnotationInfo]): this.type = + setRawAnnotations(annots) - def addAnnotation(annot: AnnotationInfo) { - setAnnotations(annot :: this.rawannots) - } + def withAnnotations(annots: List[AnnotationInfo]): this.type = + setRawAnnotations(annots ::: rawannots) - /** Does this symbol have an annotation of the given class? */ - def hasAnnotation(cls: Symbol) = - getAnnotation(cls).isDefined + def withoutAnnotations: this.type = + setRawAnnotations(Nil) - def getAnnotation(cls: Symbol): Option[AnnotationInfo] = - annotations find (_.atp.typeSymbol == cls) + def addAnnotation(annot: AnnotationInfo): this.type = + setRawAnnotations(annot :: rawannots) - /** Remove all annotations matching the given class. */ - def removeAnnotation(cls: Symbol): Unit = - setAnnotations(annotations filterNot (_.atp.typeSymbol == cls)) + // Convenience for the overwhelmingly common case + def addAnnotation(sym: Symbol, args: Tree*): this.type = + addAnnotation(AnnotationInfo(sym.tpe, args.toList, Nil)) // ------ comparisons ---------------------------------------------------------------- |