From 55109d0d253c7e89660f1b61d17408648c0c53a4 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Sat, 1 Oct 2011 05:16:22 +0000 Subject: Shuffling classes around. Old Man Reflection is coming home and he's not going to like finding out a bunch of beans have moved into his reflecting room. We had better evict those guys before he blows his stack. scala.reflect.*Bean* --> scala.beans.* scala.beans, that's kind of a fancy package name for some beans. I figure it's time to start fishing or cutting bait on this kind of thing. I don't even know what beans are, but if we're going to have them in the mainline, the least surprising place to find them is scala.beans. If we don't want to put them in scala.beans for whatever reason, then I say they don't belong in trunk at all. Bonus round: scala.annotation.target --> scala.beans.meta I don't know if there is any more unfortunate name for a package possible than "target". Maybe ".svn" or ".git" if you could have dots in package names. Package CVS wouldn't hit too hard these days. Package lib_managed? I'll try to come up with something. In any case this golden opportunity could not be squandered. There is a new starr included, because GenJVM contains all kinds of shooting-from-the-hip Bean-related name hardcoding. (Yes, still. I ran out of stones. So a few birds escape with their lives... this time.) --- .../scala/annotation/target/beanGetter.scala | 13 --- .../scala/annotation/target/beanSetter.scala | 13 --- src/library/scala/annotation/target/field.scala | 13 --- src/library/scala/annotation/target/getter.scala | 13 --- src/library/scala/annotation/target/package.scala | 93 +++++++--------------- src/library/scala/annotation/target/param.scala | 13 --- src/library/scala/annotation/target/setter.scala | 13 --- src/library/scala/beans/BeanDescription.scala | 19 +++++ src/library/scala/beans/BeanDisplayName.scala | 18 +++++ src/library/scala/beans/BeanInfo.scala | 20 +++++ src/library/scala/beans/BeanInfoSkip.scala | 18 +++++ src/library/scala/beans/BeanProperty.scala | 28 +++++++ src/library/scala/beans/BooleanBeanProperty.scala | 18 +++++ src/library/scala/beans/ScalaBeanInfo.scala | 46 +++++++++++ src/library/scala/beans/meta/beanGetter.scala | 13 +++ src/library/scala/beans/meta/beanSetter.scala | 13 +++ src/library/scala/beans/meta/field.scala | 13 +++ src/library/scala/beans/meta/getter.scala | 13 +++ src/library/scala/beans/meta/package.scala | 68 ++++++++++++++++ src/library/scala/beans/meta/param.scala | 13 +++ src/library/scala/beans/meta/setter.scala | 13 +++ src/library/scala/deprecated.scala | 2 +- src/library/scala/deprecatedName.scala | 2 +- src/library/scala/reflect/BeanDescription.scala | 19 ----- src/library/scala/reflect/BeanDisplayName.scala | 18 ----- src/library/scala/reflect/BeanInfo.scala | 20 ----- src/library/scala/reflect/BeanInfoSkip.scala | 18 ----- src/library/scala/reflect/BeanProperty.scala | 28 ------- .../scala/reflect/BooleanBeanProperty.scala | 18 ----- src/library/scala/reflect/ScalaBeanInfo.scala | 46 ----------- src/library/scala/reflect/package.scala | 14 ++++ src/library/scala/transient.scala | 2 +- src/library/scala/volatile.scala | 2 +- 33 files changed, 358 insertions(+), 315 deletions(-) delete mode 100644 src/library/scala/annotation/target/beanGetter.scala delete mode 100644 src/library/scala/annotation/target/beanSetter.scala delete mode 100644 src/library/scala/annotation/target/field.scala delete mode 100644 src/library/scala/annotation/target/getter.scala delete mode 100644 src/library/scala/annotation/target/param.scala delete mode 100644 src/library/scala/annotation/target/setter.scala create mode 100644 src/library/scala/beans/BeanDescription.scala create mode 100644 src/library/scala/beans/BeanDisplayName.scala create mode 100644 src/library/scala/beans/BeanInfo.scala create mode 100644 src/library/scala/beans/BeanInfoSkip.scala create mode 100644 src/library/scala/beans/BeanProperty.scala create mode 100644 src/library/scala/beans/BooleanBeanProperty.scala create mode 100644 src/library/scala/beans/ScalaBeanInfo.scala create mode 100644 src/library/scala/beans/meta/beanGetter.scala create mode 100644 src/library/scala/beans/meta/beanSetter.scala create mode 100644 src/library/scala/beans/meta/field.scala create mode 100644 src/library/scala/beans/meta/getter.scala create mode 100644 src/library/scala/beans/meta/package.scala create mode 100644 src/library/scala/beans/meta/param.scala create mode 100644 src/library/scala/beans/meta/setter.scala delete mode 100644 src/library/scala/reflect/BeanDescription.scala delete mode 100644 src/library/scala/reflect/BeanDisplayName.scala delete mode 100644 src/library/scala/reflect/BeanInfo.scala delete mode 100644 src/library/scala/reflect/BeanInfoSkip.scala delete mode 100644 src/library/scala/reflect/BeanProperty.scala delete mode 100644 src/library/scala/reflect/BooleanBeanProperty.scala delete mode 100644 src/library/scala/reflect/ScalaBeanInfo.scala (limited to 'src/library') diff --git a/src/library/scala/annotation/target/beanGetter.scala b/src/library/scala/annotation/target/beanGetter.scala deleted file mode 100644 index 1707a9d258..0000000000 --- a/src/library/scala/annotation/target/beanGetter.scala +++ /dev/null @@ -1,13 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2002-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ -package scala.annotation.target - -/** - * Consult the documentation in package [[scala.annotation.target]]. - */ -final class beanGetter extends annotation.StaticAnnotation diff --git a/src/library/scala/annotation/target/beanSetter.scala b/src/library/scala/annotation/target/beanSetter.scala deleted file mode 100644 index 11e95db3cb..0000000000 --- a/src/library/scala/annotation/target/beanSetter.scala +++ /dev/null @@ -1,13 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2002-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ -package scala.annotation.target - -/** - * Consult the documentation in package [[scala.annotation.target]]. - */ -final class beanSetter extends annotation.StaticAnnotation diff --git a/src/library/scala/annotation/target/field.scala b/src/library/scala/annotation/target/field.scala deleted file mode 100644 index cd0e5a58b3..0000000000 --- a/src/library/scala/annotation/target/field.scala +++ /dev/null @@ -1,13 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2002-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ -package scala.annotation.target - -/** - * Consult the documentation in package [[scala.annotation.target]]. - */ -final class field extends annotation.StaticAnnotation diff --git a/src/library/scala/annotation/target/getter.scala b/src/library/scala/annotation/target/getter.scala deleted file mode 100644 index 9363401d35..0000000000 --- a/src/library/scala/annotation/target/getter.scala +++ /dev/null @@ -1,13 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2002-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ -package scala.annotation.target - -/** - * Consult the documentation in package [[scala.annotation.target]]. - */ -final class getter extends annotation.StaticAnnotation diff --git a/src/library/scala/annotation/target/package.scala b/src/library/scala/annotation/target/package.scala index 454ce46e5c..3aff964c7b 100644 --- a/src/library/scala/annotation/target/package.scala +++ b/src/library/scala/annotation/target/package.scala @@ -1,68 +1,29 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + package scala.annotation -/** - * When defining a field, the Scala compiler creates up to four accessors - * for it: a getter, a setter, and if the field is annotated with - * `@BeanProperty`, a bean getter and a bean setter. - * - * For instance in the following class definition - * - * {{{ - * class C(@myAnnot @BeanProperty var c: Int) - * }}} - * - * there are six entities which can carry the annotation `@myAnnot`: the - * constructor parameter, the generated field and the four accessors. - * - * 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. - * - * The meta-annotations in package `scala.annotation.target` are used - * to control where annotations on fields and class parameters are copied. - * This is done by annotating either the annotation type or the annotation - * class with one or several of the meta-annotations in this package. - * - * ==Annotating the annotation type== - * - * The target meta-annotations can be put on the annotation type when - * instantiating the annotation. In the following example, the annotation - * `@Id` will be added only to the bean getter `getX`. - * - * {{{ - * import javax.persistence.Id - * class A { - * @(Id @beanGetter) @BeanProperty val x = 0 - * } - * }}} - * - * In order to annotate the field as well, the meta-annotation `@field` - * would need to be added. - * - * The syntax can be improved using a type alias: - * - * {{{ - * object ScalaJPA { - * type Id = javax.persistence.Id @beanGetter - * } - * import ScalaJPA.Id - * class A { - * @Id @BeanProperty val x = 0 - * } - * }}} - * - * ==Annotating the annotation class== - * - * For annotations defined in Scala, a default target can be specified - * in the annotation class itself, for example - * - * {{{ - * @getter - * class myAnnotation extends Annotation - * }}} - * - * This only changes the default target for the annotation `myAnnotation`. - * When instantiating the annotation, the target can still be specified - * as described in the last section. - */ -package object target +package object target { + @deprecated("Use `@scala.beans.meta.beanGetter` instead", "2.10.0") + type beanGetter = scala.beans.meta.beanGetter + + @deprecated("Use `@scala.beans.meta.beanSetter` instead", "2.10.0") + type beanSetter = scala.beans.meta.beanSetter + + @deprecated("Use `@scala.beans.meta.field` instead", "2.10.0") + type field = scala.beans.meta.field + + @deprecated("Use `@scala.beans.meta.getter` instead", "2.10.0") + type getter = scala.beans.meta.getter + + @deprecated("Use `@scala.beans.meta.param` instead", "2.10.0") + type param = scala.beans.meta.param + + @deprecated("Use `@scala.beans.meta.setter` instead", "2.10.0") + type setter = scala.beans.meta.setter +} diff --git a/src/library/scala/annotation/target/param.scala b/src/library/scala/annotation/target/param.scala deleted file mode 100644 index 5b917b883f..0000000000 --- a/src/library/scala/annotation/target/param.scala +++ /dev/null @@ -1,13 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2002-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ -package scala.annotation.target - -/** - * Consult the documentation in package [[scala.annotation.target]]. - */ -final class param extends annotation.StaticAnnotation diff --git a/src/library/scala/annotation/target/setter.scala b/src/library/scala/annotation/target/setter.scala deleted file mode 100644 index 1c13a796a0..0000000000 --- a/src/library/scala/annotation/target/setter.scala +++ /dev/null @@ -1,13 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2002-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ -package scala.annotation.target - -/** - * Consult the documentation in package [[scala.annotation.target]]. - */ -final class setter extends annotation.StaticAnnotation diff --git a/src/library/scala/beans/BeanDescription.scala b/src/library/scala/beans/BeanDescription.scala new file mode 100644 index 0000000000..d6c9b0c736 --- /dev/null +++ b/src/library/scala/beans/BeanDescription.scala @@ -0,0 +1,19 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2002-2011, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + + +package scala.beans + +/** Provides a short description that will be included when generating + * bean information. This annotation can be attached to the bean itself, + * or to any member. + * + * @author Ross Judson (rjudson@managedobjects.com) + */ +class BeanDescription(val description: String) extends annotation.Annotation + diff --git a/src/library/scala/beans/BeanDisplayName.scala b/src/library/scala/beans/BeanDisplayName.scala new file mode 100644 index 0000000000..fbbfa08ffc --- /dev/null +++ b/src/library/scala/beans/BeanDisplayName.scala @@ -0,0 +1,18 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2002-2011, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + + +package scala.beans + +/** Provides a display name when generating bean information. This + * annotation can be attached to the bean itself, or to any member. + * + * @author Ross Judson (rjudson@managedobjects.com) + */ +class BeanDisplayName(val name: String) extends annotation.Annotation + diff --git a/src/library/scala/beans/BeanInfo.scala b/src/library/scala/beans/BeanInfo.scala new file mode 100644 index 0000000000..1a1d8defa4 --- /dev/null +++ b/src/library/scala/beans/BeanInfo.scala @@ -0,0 +1,20 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2002-2011, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +package scala.beans + +/** This annotation indicates that a JavaBean-compliant `BeanInfo` class + * should be generated for this annotated Scala class. + * + * - A `'''val'''` becomes a read-only property. + * - A `'''var'''` becomes a read-write property. + * - A `'''def'''` becomes a method. + * + * @author Ross Judson (rjudson@managedobjects.com) + */ +class BeanInfo extends annotation.Annotation diff --git a/src/library/scala/beans/BeanInfoSkip.scala b/src/library/scala/beans/BeanInfoSkip.scala new file mode 100644 index 0000000000..23adf74924 --- /dev/null +++ b/src/library/scala/beans/BeanInfoSkip.scala @@ -0,0 +1,18 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2002-2011, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + + +package scala.beans + +/** This annotation indicates that bean information should + * not be generated for the val, var, or def that it is + * attached to. + * + * @author Ross Judson (rjudson@managedobjects.com) + */ +class BeanInfoSkip extends annotation.Annotation diff --git a/src/library/scala/beans/BeanProperty.scala b/src/library/scala/beans/BeanProperty.scala new file mode 100644 index 0000000000..f5708a0ab0 --- /dev/null +++ b/src/library/scala/beans/BeanProperty.scala @@ -0,0 +1,28 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2002-2011, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +package scala.beans + +import meta._ + +/** When attached to a field, this annotation adds a setter and a getter + * method following the Java Bean convention. For example: + * {{{ + * @BeanProperty + * var status = "" + * }}} + * adds the following methods to the class: + * {{{ + * def setStatus(s: String) { this.status = s } + * def getStatus: String = this.status + * }}} + * For fields of type `Boolean`, if you need a getter named `isStatus`, + * use the `scala.beans.BooleanBeanProperty` annotation instead. + */ +@field +class BeanProperty extends annotation.StaticAnnotation diff --git a/src/library/scala/beans/BooleanBeanProperty.scala b/src/library/scala/beans/BooleanBeanProperty.scala new file mode 100644 index 0000000000..2215177a80 --- /dev/null +++ b/src/library/scala/beans/BooleanBeanProperty.scala @@ -0,0 +1,18 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2002-2011, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +package scala.beans + +import meta._ + +/** This annotation has the same functionality as + * `scala.beans.BeanProperty`, but the generated Bean getter will be + * named `isFieldName` instead of `getFieldName`. + */ +@field +class BooleanBeanProperty extends annotation.StaticAnnotation diff --git a/src/library/scala/beans/ScalaBeanInfo.scala b/src/library/scala/beans/ScalaBeanInfo.scala new file mode 100644 index 0000000000..4661b23568 --- /dev/null +++ b/src/library/scala/beans/ScalaBeanInfo.scala @@ -0,0 +1,46 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2002-2011, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + + +package scala.beans + +/** Provides some simple runtime processing necessary to create + * JavaBean descriptors for Scala entities. The compiler creates + * subclasses of this class automatically when the BeanInfo annotation is + * attached to a class. + * + * @author Ross Judson (rjudson@managedobjects.com) + */ +abstract class ScalaBeanInfo(clazz: java.lang.Class[_], + props: Array[String], + methods: Array[String]) extends java.beans.SimpleBeanInfo { + + import java.beans._ + + private val pd = new Array[PropertyDescriptor](props.length / 3) + private val md = + for (m <- clazz.getMethods if methods.exists(_ == m.getName)) + yield new MethodDescriptor(m) + + init + + override def getPropertyDescriptors() = pd + override def getMethodDescriptors() = md + + // override def getAdditionalBeanInfo() = Array(Introspector getBeanInfo clazz.getSuperclass) + + private def init() { + var i = 0; + while (i < props.length) { + pd(i/3) = new PropertyDescriptor(props(i), clazz, props(i+1), props(i+2)) + i = i + 3; + } + } + +} + diff --git a/src/library/scala/beans/meta/beanGetter.scala b/src/library/scala/beans/meta/beanGetter.scala new file mode 100644 index 0000000000..3eb2dcbda3 --- /dev/null +++ b/src/library/scala/beans/meta/beanGetter.scala @@ -0,0 +1,13 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2002-2011, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ +package scala.beans.meta + +/** + * Consult the documentation in package [[scala.beans.meta]]. + */ +final class beanGetter extends annotation.StaticAnnotation diff --git a/src/library/scala/beans/meta/beanSetter.scala b/src/library/scala/beans/meta/beanSetter.scala new file mode 100644 index 0000000000..8c61acfe6d --- /dev/null +++ b/src/library/scala/beans/meta/beanSetter.scala @@ -0,0 +1,13 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2002-2011, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ +package scala.beans.meta + +/** + * Consult the documentation in package [[scala.beans.meta]]. + */ +final class beanSetter extends annotation.StaticAnnotation diff --git a/src/library/scala/beans/meta/field.scala b/src/library/scala/beans/meta/field.scala new file mode 100644 index 0000000000..135b2e590c --- /dev/null +++ b/src/library/scala/beans/meta/field.scala @@ -0,0 +1,13 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2002-2011, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ +package scala.beans.meta + +/** + * Consult the documentation in package [[scala.beans.meta]]. + */ +final class field extends annotation.StaticAnnotation diff --git a/src/library/scala/beans/meta/getter.scala b/src/library/scala/beans/meta/getter.scala new file mode 100644 index 0000000000..18afa8e324 --- /dev/null +++ b/src/library/scala/beans/meta/getter.scala @@ -0,0 +1,13 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2002-2011, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ +package scala.beans.meta + +/** + * Consult the documentation in package [[scala.beans.meta]]. + */ +final class getter extends annotation.StaticAnnotation diff --git a/src/library/scala/beans/meta/package.scala b/src/library/scala/beans/meta/package.scala new file mode 100644 index 0000000000..c7b7b425e1 --- /dev/null +++ b/src/library/scala/beans/meta/package.scala @@ -0,0 +1,68 @@ +package scala.beans + +/** + * When defining a field, the Scala compiler creates up to four accessors + * for it: a getter, a setter, and if the field is annotated with + * `@BeanProperty`, a bean getter and a bean setter. + * + * For instance in the following class definition + * + * {{{ + * class C(@myAnnot @BeanProperty var c: Int) + * }}} + * + * there are six entities which can carry the annotation `@myAnnot`: the + * constructor parameter, the generated field and the four accessors. + * + * 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. + * + * The meta-annotations in package `scala.beans.meta` are used + * to control where annotations on fields and class parameters are copied. + * This is done by annotating either the annotation type or the annotation + * class with one or several of the meta-annotations in this package. + * + * ==Annotating the annotation type== + * + * The target meta-annotations can be put on the annotation type when + * instantiating the annotation. In the following example, the annotation + * `@Id` will be added only to the bean getter `getX`. + * + * {{{ + * import javax.persistence.Id + * class A { + * @(Id @beanGetter) @BeanProperty val x = 0 + * } + * }}} + * + * In order to annotate the field as well, the meta-annotation `@field` + * would need to be added. + * + * The syntax can be improved using a type alias: + * + * {{{ + * object ScalaJPA { + * type Id = javax.persistence.Id @beanGetter + * } + * import ScalaJPA.Id + * class A { + * @Id @BeanProperty val x = 0 + * } + * }}} + * + * ==Annotating the annotation class== + * + * For annotations defined in Scala, a default target can be specified + * in the annotation class itself, for example + * + * {{{ + * @getter + * class myAnnotation extends Annotation + * }}} + * + * This only changes the default target for the annotation `myAnnotation`. + * When instantiating the annotation, the target can still be specified + * as described in the last section. + */ +package object meta diff --git a/src/library/scala/beans/meta/param.scala b/src/library/scala/beans/meta/param.scala new file mode 100644 index 0000000000..45c3e3e00f --- /dev/null +++ b/src/library/scala/beans/meta/param.scala @@ -0,0 +1,13 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2002-2011, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ +package scala.beans.meta + +/** + * Consult the documentation in package [[scala.beans.meta]]. + */ +final class param extends annotation.StaticAnnotation diff --git a/src/library/scala/beans/meta/setter.scala b/src/library/scala/beans/meta/setter.scala new file mode 100644 index 0000000000..5a23b7b53d --- /dev/null +++ b/src/library/scala/beans/meta/setter.scala @@ -0,0 +1,13 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2002-2011, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ +package scala.beans.meta + +/** + * Consult the documentation in package [[scala.beans.meta]]. + */ +final class setter extends annotation.StaticAnnotation diff --git a/src/library/scala/deprecated.scala b/src/library/scala/deprecated.scala index 53f5c456c2..12c36da8d3 100644 --- a/src/library/scala/deprecated.scala +++ b/src/library/scala/deprecated.scala @@ -8,7 +8,7 @@ package scala -import annotation.target._ +import beans.meta._ /** An annotation that designates that a definition is deprecated. * Access to the member then generates a deprecated warning. diff --git a/src/library/scala/deprecatedName.scala b/src/library/scala/deprecatedName.scala index 090ec133fe..53f26573c0 100644 --- a/src/library/scala/deprecatedName.scala +++ b/src/library/scala/deprecatedName.scala @@ -8,7 +8,7 @@ package scala -import annotation.target._ +import beans.meta._ /** * An annotation that designates the name of the parameter to which it is diff --git a/src/library/scala/reflect/BeanDescription.scala b/src/library/scala/reflect/BeanDescription.scala deleted file mode 100644 index d0069cdf79..0000000000 --- a/src/library/scala/reflect/BeanDescription.scala +++ /dev/null @@ -1,19 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2002-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - - -package scala.reflect - -/** Provides a short description that will be included when generating - * bean information. This annotation can be attached to the bean itself, - * or to any member. - * - * @author Ross Judson (rjudson@managedobjects.com) - */ -class BeanDescription(val description: String) extends annotation.Annotation - diff --git a/src/library/scala/reflect/BeanDisplayName.scala b/src/library/scala/reflect/BeanDisplayName.scala deleted file mode 100644 index 5fecee4dc3..0000000000 --- a/src/library/scala/reflect/BeanDisplayName.scala +++ /dev/null @@ -1,18 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2002-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - - -package scala.reflect - -/** Provides a display name when generating bean information. This - * annotation can be attached to the bean itself, or to any member. - * - * @author Ross Judson (rjudson@managedobjects.com) - */ -class BeanDisplayName(val name: String) extends annotation.Annotation - diff --git a/src/library/scala/reflect/BeanInfo.scala b/src/library/scala/reflect/BeanInfo.scala deleted file mode 100644 index 0522377f8e..0000000000 --- a/src/library/scala/reflect/BeanInfo.scala +++ /dev/null @@ -1,20 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2002-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - -package scala.reflect - -/** This annotation indicates that a JavaBean-compliant `BeanInfo` class - * should be generated for this annotated Scala class. - * - * - A `'''val'''` becomes a read-only property. - * - A `'''var'''` becomes a read-write property. - * - A `'''def'''` becomes a method. - * - * @author Ross Judson (rjudson@managedobjects.com) - */ -class BeanInfo extends annotation.Annotation diff --git a/src/library/scala/reflect/BeanInfoSkip.scala b/src/library/scala/reflect/BeanInfoSkip.scala deleted file mode 100644 index 40596865c0..0000000000 --- a/src/library/scala/reflect/BeanInfoSkip.scala +++ /dev/null @@ -1,18 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2002-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - - -package scala.reflect - -/** This annotation indicates that bean information should - * not be generated for the val, var, or def that it is - * attached to. - * - * @author Ross Judson (rjudson@managedobjects.com) - */ -class BeanInfoSkip extends annotation.Annotation diff --git a/src/library/scala/reflect/BeanProperty.scala b/src/library/scala/reflect/BeanProperty.scala deleted file mode 100644 index b52774cdff..0000000000 --- a/src/library/scala/reflect/BeanProperty.scala +++ /dev/null @@ -1,28 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2002-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - -package scala.reflect - -import annotation.target._ - -/** When attached to a field, this annotation adds a setter and a getter - * method following the Java Bean convention. For example: - * {{{ - * @BeanProperty - * var status = "" - * }}} - * adds the following methods to the class: - * {{{ - * def setStatus(s: String) { this.status = s } - * def getStatus: String = this.status - * }}} - * For fields of type `Boolean`, if you need a getter named `isStatus`, - * use the `scala.reflect.BooleanBeanProperty` annotation instead. - */ -@field -class BeanProperty extends annotation.StaticAnnotation diff --git a/src/library/scala/reflect/BooleanBeanProperty.scala b/src/library/scala/reflect/BooleanBeanProperty.scala deleted file mode 100644 index 97c05ffb7c..0000000000 --- a/src/library/scala/reflect/BooleanBeanProperty.scala +++ /dev/null @@ -1,18 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2002-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - -package scala.reflect - -import annotation.target._ - -/** This annotation has the same functionality as - * `scala.reflect.BeanProperty`, but the generated Bean getter will be - * named `isFieldName` instead of `getFieldName`. - */ -@field -class BooleanBeanProperty extends annotation.StaticAnnotation diff --git a/src/library/scala/reflect/ScalaBeanInfo.scala b/src/library/scala/reflect/ScalaBeanInfo.scala deleted file mode 100644 index bcb76c38bc..0000000000 --- a/src/library/scala/reflect/ScalaBeanInfo.scala +++ /dev/null @@ -1,46 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2002-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - - -package scala.reflect - -/** Provides some simple runtime processing necessary to create - * JavaBean descriptors for Scala entities. The compiler creates - * subclasses of this class automatically when the BeanInfo annotation is - * attached to a class. - * - * @author Ross Judson (rjudson@managedobjects.com) - */ -abstract class ScalaBeanInfo(clazz: java.lang.Class[_], - props: Array[String], - methods: Array[String]) extends java.beans.SimpleBeanInfo { - - import java.beans._ - - private val pd = new Array[PropertyDescriptor](props.length / 3) - private val md = - for (m <- clazz.getMethods if methods.exists(_ == m.getName)) - yield new MethodDescriptor(m) - - init - - override def getPropertyDescriptors() = pd - override def getMethodDescriptors() = md - - // override def getAdditionalBeanInfo() = Array(Introspector getBeanInfo clazz.getSuperclass) - - private def init() { - var i = 0; - while (i < props.length) { - pd(i/3) = new PropertyDescriptor(props(i), clazz, props(i+1), props(i+2)) - i = i + 3; - } - } - -} - diff --git a/src/library/scala/reflect/package.scala b/src/library/scala/reflect/package.scala index ad541ce46e..d18924c409 100644 --- a/src/library/scala/reflect/package.scala +++ b/src/library/scala/reflect/package.scala @@ -17,4 +17,18 @@ package object reflect extends ReflectionUtils { type Type = mirror.Type type Tree = mirror.Tree */ + @deprecated("Use `@scala.beans.BeanDescription` instead", "2.10.0") + type BeanDescription = scala.beans.BeanDescription + @deprecated("Use `@scala.beans.BeanDisplayName` instead", "2.10.0") + type BeanDisplayName = scala.beans.BeanDisplayName + @deprecated("Use `@scala.beans.BeanInfo` instead", "2.10.0") + type BeanInfo = scala.beans.BeanInfo + @deprecated("Use `@scala.beans.BeanInfoSkip` instead", "2.10.0") + type BeanInfoSkip = scala.beans.BeanInfoSkip + @deprecated("Use `@scala.beans.BeanProperty` instead", "2.10.0") + type BeanProperty = scala.beans.BeanProperty + @deprecated("Use `@scala.beans.BooleanBeanProperty` instead", "2.10.0") + type BooleanBeanProperty = scala.beans.BooleanBeanProperty + @deprecated("Use `@scala.beans.ScalaBeanInfo` instead", "2.10.0") + type ScalaBeanInfo = scala.beans.ScalaBeanInfo } diff --git a/src/library/scala/transient.scala b/src/library/scala/transient.scala index c17fab1cb4..fd3c824e81 100644 --- a/src/library/scala/transient.scala +++ b/src/library/scala/transient.scala @@ -10,7 +10,7 @@ package scala -import annotation.target._ +import beans.meta._ @field class transient extends annotation.StaticAnnotation diff --git a/src/library/scala/volatile.scala b/src/library/scala/volatile.scala index 9b47a52766..a45bdf8d14 100644 --- a/src/library/scala/volatile.scala +++ b/src/library/scala/volatile.scala @@ -10,7 +10,7 @@ package scala -import annotation.target._ +import beans.meta._ @field class volatile extends annotation.StaticAnnotation -- cgit v1.2.3