diff options
author | Lukas Rytz <lukas.rytz@epfl.ch> | 2009-11-19 13:44:15 +0000 |
---|---|---|
committer | Lukas Rytz <lukas.rytz@epfl.ch> | 2009-11-19 13:44:15 +0000 |
commit | 1e1c87c234826279a58c97bc5124f2e76ab58dce (patch) | |
tree | 695573d62d174feb76c017ad04875e2e8404f5cc /src/compiler | |
parent | 055190a38ba1496821b2b67c368c97e33573883a (diff) | |
download | scala-1e1c87c234826279a58c97bc5124f2e76ab58dce.tar.gz scala-1e1c87c234826279a58c97bc5124f2e76ab58dce.tar.bz2 scala-1e1c87c234826279a58c97bc5124f2e76ab58dce.zip |
closes #2670.
Diffstat (limited to 'src/compiler')
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Typers.scala | 34 |
1 files changed, 26 insertions, 8 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 6e6fdd3c35..1ddc3b9116 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -1314,16 +1314,34 @@ trait Typers { self: Analyzer => case ValDef(mods, name, tpt, rhs) if (mods.flags & (PRIVATE | LOCAL)) != (PRIVATE | LOCAL).toLong && !stat.symbol.isModuleVar => + /** The annotations amongst `annots` that should go on a member of class + * `memberClass` (field, getter, setter, beanGetter, beanSetter) + */ def memberAnnots(annots: List[AnnotationInfo], memberClass: Symbol) = { + + 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 != GetterClass && annClass != SetterClass && + annClass != BeanGetterClass && annClass != BeanSetterClass + }) && 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, memberClass == FieldClass) + } + annots.filter(ann => ann.atp match { - case AnnotatedType(annots, _, _) => - annots.exists(_.atp.typeSymbol == memberClass) || - (memberClass == FieldClass && annots.forall(ann => { - val annClass = ann.atp.typeSymbol - annClass != GetterClass && annClass != SetterClass && - annClass != BeanGetterClass && annClass != BeanSetterClass - })) - case _ => memberClass == FieldClass + // 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) }) } |