summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/typechecker/Typers.scala
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2011-10-10 06:24:46 +0000
committerPaul Phillips <paulp@improving.org>2011-10-10 06:24:46 +0000
commit4e86106b5b0637aa88de2e3d5a8751d918e4c069 (patch)
treefd4fc08760ffd102b590f670720c8846e41fb15e /src/compiler/scala/tools/nsc/typechecker/Typers.scala
parent1706358bdcf0492b82e87c8f34e9b7120348df8b (diff)
downloadscala-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/tools/nsc/typechecker/Typers.scala')
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala41
1 files changed, 13 insertions, 28 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
index 676ad34592..d01cd829ac 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -1490,36 +1490,21 @@ trait Typers extends Modes with Adaptations {
/**
* The annotations amongst `annots` that should go on a member of class
- * `memberClass` (field, getter, setter, beanGetter, beanSetter, param)
- * If 'keepClean' is true, annotations without any meta-annotation are kept
+ * `annotKind` (one of: field, getter, setter, beanGetter, beanSetter, param)
+ * If 'keepClean' is true, annotations without any meta-annotations are kept.
*/
- protected def memberAnnots(annots: List[AnnotationInfo], memberClass: Symbol, keepClean: Boolean = false) = {
-
- def hasMatching(metaAnnots: List[AnnotationInfo], orElse: => Boolean) = {
- // either one of the meta-annotations matches the `memberClass`
- metaAnnots.exists(_.atp.typeSymbol == memberClass) ||
- // else, if there is no `target` meta-annotation at all, use the default case
- (metaAnnots.forall(ann => {
- val annClass = ann.atp.typeSymbol
- annClass != FieldTargetClass && annClass != GetterTargetClass &&
- annClass != SetterTargetClass && annClass != BeanGetterTargetClass &&
- annClass != BeanSetterTargetClass && annClass != ParamTargetClass
- }) && orElse)
- }
-
- // there was no meta-annotation on `ann`. Look if the class annotations of
- // `ann` has a `target` annotation, otherwise put `ann` only on fields.
- def noMetaAnnot(ann: AnnotationInfo) = {
- hasMatching(ann.atp.typeSymbol.annotations, keepClean)
+ protected def memberAnnots(annots: List[AnnotationInfo], annotKind: Symbol, keepClean: Boolean = false) = {
+ annots filter { ann =>
+ // There are no meta-annotation arguments attached to `ann`
+ if (ann.metaAnnotations.isEmpty) {
+ // A meta-annotation matching `annotKind` exists on `ann`'s definition.
+ (ann.defaultTargets contains annotKind) ||
+ // `ann`'s definition has no meta-annotations, and `keepClean` is true.
+ (ann.defaultTargets.isEmpty && keepClean)
+ }
+ // There are meta-annotation arguments, and one of them matches `annotKind`
+ else ann.metaAnnotations exists (_ matches annotKind)
}
-
- annots.filter(ann => ann.atp match {
- // the annotation type has meta-annotations, e.g. @(foo @getter)
- case AnnotatedType(metaAnnots, _, _) =>
- hasMatching(metaAnnots, noMetaAnnot(ann))
- // there are no meta-annotations, e.g. @foo
- case _ => noMetaAnnot(ann)
- })
}
protected def enterSyms(txt: Context, trees: List[Tree]) = {