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 | |
parent | 055190a38ba1496821b2b67c368c97e33573883a (diff) | |
download | scala-1e1c87c234826279a58c97bc5124f2e76ab58dce.tar.gz scala-1e1c87c234826279a58c97bc5124f2e76ab58dce.tar.bz2 scala-1e1c87c234826279a58c97bc5124f2e76ab58dce.zip |
closes #2670.
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Typers.scala | 34 | ||||
-rw-r--r-- | src/library/scala/annotation/target/beanGetter.scala | 12 | ||||
-rw-r--r-- | src/library/scala/annotation/target/beanSetter.scala | 12 | ||||
-rw-r--r-- | src/library/scala/annotation/target/field.scala | 12 | ||||
-rw-r--r-- | src/library/scala/annotation/target/getter.scala | 12 | ||||
-rw-r--r-- | src/library/scala/annotation/target/setter.scala | 12 | ||||
-rw-r--r-- | src/library/scala/deprecated.scala | 3 |
7 files changed, 79 insertions, 18 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) }) } diff --git a/src/library/scala/annotation/target/beanGetter.scala b/src/library/scala/annotation/target/beanGetter.scala index cc39a32874..8518049f2c 100644 --- a/src/library/scala/annotation/target/beanGetter.scala +++ b/src/library/scala/annotation/target/beanGetter.scala @@ -14,8 +14,8 @@ package scala.annotation.target * used to control to which of the above members the annotations on * the field are copied. By default, field annotations are only added * to the actual field, but not to any of the accessors. By annotating - * the annotation type with one or several of the meta-annotations this - * behavior can be changed. + * the annotation type or the annotation class with one or several of + * the meta-annotations this behavior can be changed. * * In the following example, the annotation {{{@Id}}} will be added * only to the bean getter {{{getX}}}. In order to annotate the field @@ -39,5 +39,13 @@ package scala.annotation.target * @Id @BeanProperty val x = 0 * } * }}} + * + * For annotations defined in Scala, a default target can be specified + * in the annotation class itself, for example + * + * {{{ + * @getter + * class myAnnotation extends Annotation + * }}} */ final class beanGetter extends StaticAnnotation diff --git a/src/library/scala/annotation/target/beanSetter.scala b/src/library/scala/annotation/target/beanSetter.scala index 5f1513fd51..a5df4c933f 100644 --- a/src/library/scala/annotation/target/beanSetter.scala +++ b/src/library/scala/annotation/target/beanSetter.scala @@ -14,8 +14,8 @@ package scala.annotation.target * used to control to which of the above members the annotations on * the field are copied. By default, field annotations are only added * to the actual field, but not to any of the accessors. By annotating - * the annotation type with one or several of the meta-annotations this - * behavior can be changed. + * the annotation type or the annotation class with one or several of + * the meta-annotations this behavior can be changed. * * In the following example, the annotation {{{@Id}}} will be added * only to the bean getter {{{getX}}}. In order to annotate the field @@ -39,5 +39,13 @@ package scala.annotation.target * @Id @BeanProperty val x = 0 * } * }}} + * + * For annotations defined in Scala, a default target can be specified + * in the annotation class itself, for example + * + * {{{ + * @getter + * class myAnnotation extends Annotation + * }}} */ final class beanSetter extends StaticAnnotation diff --git a/src/library/scala/annotation/target/field.scala b/src/library/scala/annotation/target/field.scala index 19533c6908..c202d276cc 100644 --- a/src/library/scala/annotation/target/field.scala +++ b/src/library/scala/annotation/target/field.scala @@ -14,8 +14,8 @@ package scala.annotation.target * used to control to which of the above members the annotations on * the field are copied. By default, field annotations are only added * to the actual field, but not to any of the accessors. By annotating - * the annotation type with one or several of the meta-annotations this - * behavior can be changed. + * the annotation type or the annotation class with one or several of + * the meta-annotations this behavior can be changed. * * In the following example, the annotation {{{@Id}}} will be added * only to the bean getter {{{getX}}}. In order to annotate the field @@ -39,5 +39,13 @@ package scala.annotation.target * @Id @BeanProperty val x = 0 * } * }}} + * + * For annotations defined in Scala, a default target can be specified + * in the annotation class itself, for example + * + * {{{ + * @getter + * class myAnnotation extends Annotation + * }}} */ final class field extends StaticAnnotation diff --git a/src/library/scala/annotation/target/getter.scala b/src/library/scala/annotation/target/getter.scala index 45e2a8ac4b..02c372fe2e 100644 --- a/src/library/scala/annotation/target/getter.scala +++ b/src/library/scala/annotation/target/getter.scala @@ -14,8 +14,8 @@ package scala.annotation.target * used to control to which of the above members the annotations on * the field are copied. By default, field annotations are only added * to the actual field, but not to any of the accessors. By annotating - * the annotation type with one or several of the meta-annotations this - * behavior can be changed. + * the annotation type or the annotation class with one or several of + * the meta-annotations this behavior can be changed. * * In the following example, the annotation {{{@Id}}} will be added * only to the bean getter {{{getX}}}. In order to annotate the field @@ -39,5 +39,13 @@ package scala.annotation.target * @Id @BeanProperty val x = 0 * } * }}} + * + * For annotations defined in Scala, a default target can be specified + * in the annotation class itself, for example + * + * {{{ + * @getter + * class myAnnotation extends Annotation + * }}} */ final class getter extends StaticAnnotation diff --git a/src/library/scala/annotation/target/setter.scala b/src/library/scala/annotation/target/setter.scala index 6f270a6116..b4d09263b4 100644 --- a/src/library/scala/annotation/target/setter.scala +++ b/src/library/scala/annotation/target/setter.scala @@ -14,8 +14,8 @@ package scala.annotation.target * used to control to which of the above members the annotations on * the field are copied. By default, field annotations are only added * to the actual field, but not to any of the accessors. By annotating - * the annotation type with one or several of the meta-annotations this - * behavior can be changed. + * the annotation type or the annotation class with one or several of + * the meta-annotations this behavior can be changed. * * In the following example, the annotation {{{@Id}}} will be added * only to the bean getter {{{getX}}}. In order to annotate the field @@ -39,5 +39,13 @@ package scala.annotation.target * @Id @BeanProperty val x = 0 * } * }}} + * + * For annotations defined in Scala, a default target can be specified + * in the annotation class itself, for example + * + * {{{ + * @getter + * class myAnnotation extends Annotation + * }}} */ final class setter extends StaticAnnotation diff --git a/src/library/scala/deprecated.scala b/src/library/scala/deprecated.scala index 1a176d1bc2..0b10b1ab74 100644 --- a/src/library/scala/deprecated.scala +++ b/src/library/scala/deprecated.scala @@ -11,12 +11,15 @@ package scala +import annotation.target._ + /** * An annotation that designates the definition to which it is applied as deprecated. * Access to the member then generates a deprecated warning. * * @since 2.3 */ +@getter @setter @beanGetter @beanSetter class deprecated(message: String) extends StaticAnnotation { def this() = this("") } |