Skip to content
Browse files

Cleaned up meta-annotations.

There were some missing and some others not added to the
set of meta-annotations. I added the missing ones and
defined the set in such a way as to include them all, even
those which have not yet been born.
  • Loading branch information...
1 parent a497229 commit ebdc0ff73b533d2b625a919d0bb57dbe94430c02 @paulp paulp committed Jan 14, 2013
Showing with 16 additions and 5 deletions.
  1. +16 −5 src/reflect/scala/reflect/internal/Definitions.scala
View
21 src/reflect/scala/reflect/internal/Definitions.scala
@@ -901,6 +901,7 @@ trait Definitions extends api.StandardDefinitions {
lazy val GetterTargetClass = requiredClass[meta.getter]
lazy val ParamTargetClass = requiredClass[meta.param]
lazy val SetterTargetClass = requiredClass[meta.setter]
+ lazy val ObjectTargetClass = requiredClass[meta.companionObject]
lazy val ClassTargetClass = requiredClass[meta.companionClass]
lazy val MethodTargetClass = requiredClass[meta.companionMethod] // TODO: module, moduleClass? package, packageObject?
lazy val LanguageFeatureAnnot = requiredClass[meta.languageFeature]
@@ -920,11 +921,21 @@ trait Definitions extends api.StandardDefinitions {
// Trying to allow for deprecated locations
sym.isAliasType && isMetaAnnotation(sym.info.typeSymbol)
)
- lazy val metaAnnotations = Set[Symbol](
- FieldTargetClass, ParamTargetClass,
- GetterTargetClass, SetterTargetClass,
- BeanGetterTargetClass, BeanSetterTargetClass
- )
+ lazy val metaAnnotations: Set[Symbol] = getPackage("scala.annotation.meta").info.members filter (_ isSubClass StaticAnnotationClass) toSet
+
+ // According to the scala.annotation.meta package object:
+ // * By default, annotations on (`val`-, `var`- or plain) constructor parameters
+ // * end up on the parameter, not on any other entity. Annotations on fields
+ // * by default only end up on the field.
+ def defaultAnnotationTarget(t: Tree): Symbol = t match {
+ case ClassDef(_, _, _, _) => ClassTargetClass
+ case ModuleDef(_, _, _) => ObjectTargetClass
+ case vd @ ValDef(_, _, _, _) if vd.symbol.isParamAccessor => ParamTargetClass
+ case vd @ ValDef(_, _, _, _) if vd.symbol.isValueParameter => ParamTargetClass
+ case ValDef(_, _, _, _) => FieldTargetClass
+ case DefDef(_, _, _, _, _, _) => MethodTargetClass
+ case _ => GetterTargetClass
+ }
lazy val AnnotationDefaultAttr: ClassSymbol = {
val attr = enterNewClass(RuntimePackageClass, tpnme.AnnotationDefaultATTR, List(AnnotationClass.tpe))

0 comments on commit ebdc0ff

Please sign in to comment.
Something went wrong with that request. Please try again.