summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPhilipp Haller <hallerp@gmail.com>2009-01-16 16:12:35 +0000
committerPhilipp Haller <hallerp@gmail.com>2009-01-16 16:12:35 +0000
commit8047e3e1096e3d00c7dcc9fde0da480ab134fb4d (patch)
tree8cacfa81f9f0b1d2f9dba4638f86f6a26dbc748d /src
parentbc7db60a2535a38300b8eabe99bc0b95d3d2efe4 (diff)
downloadscala-8047e3e1096e3d00c7dcc9fde0da480ab134fb4d.tar.gz
scala-8047e3e1096e3d00c7dcc9fde0da480ab134fb4d.tar.bz2
scala-8047e3e1096e3d00c7dcc9fde0da480ab134fb4d.zip
Cleaned up addition of serializable annotations.
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/tools/nsc/symtab/Symbols.scala21
-rw-r--r--src/compiler/scala/tools/nsc/transform/CleanUp.scala35
2 files changed, 19 insertions, 37 deletions
diff --git a/src/compiler/scala/tools/nsc/symtab/Symbols.scala b/src/compiler/scala/tools/nsc/symtab/Symbols.scala
index e1afd43171..4e65e6deab 100644
--- a/src/compiler/scala/tools/nsc/symtab/Symbols.scala
+++ b/src/compiler/scala/tools/nsc/symtab/Symbols.scala
@@ -209,17 +209,8 @@ trait Symbols {
final def newAnonymousClass(pos: Position) =
newClass(pos, nme.ANON_CLASS_NAME.toTypeName)
- final def newAnonymousFunctionClass(pos: Position) = {
- val anonfun = newClass(pos, nme.ANON_FUN_NAME.toTypeName)
- def firstNonSynOwner(chain: List[Symbol]): Symbol = (chain: @unchecked) match {
- case o :: os => if (o != this && !(o hasFlag SYNTHETIC) && o.isClass) o else firstNonSynOwner(os)
- }
- val ownerSerial = firstNonSynOwner(ownerChain) hasAttribute SerializableAttr
- if (ownerSerial)
- anonfun.attributes =
- AnnotationInfo(definitions.SerializableAttr.tpe, List(), List()) :: anonfun.attributes
- anonfun
- }
+ final def newAnonymousFunctionClass(pos: Position) =
+ newClass(pos, nme.ANON_FUN_NAME.toTypeName)
/** Refinement types P { val x: String; type T <: Number }
* also have symbols, they are refinementClasses
@@ -521,6 +512,14 @@ trait Symbols {
else if (isContravariant) -1
else 0
+ def isSerializable: Boolean = isMethod || {
+ val typeSym = info.typeSymbol
+ isValueType(typeSym) ||
+ typeSym.hasAttribute(SerializableAttr) ||
+ (info.baseClasses exists { bc => (bc hasAttribute SerializableAttr) || (bc == SerializableClass) }) ||
+ (isClass && info.members.forall(_.isSerializable))
+ }
+
// Flags, owner, and name attributes --------------------------------------------------------------
def owner: Symbol = rawowner
diff --git a/src/compiler/scala/tools/nsc/transform/CleanUp.scala b/src/compiler/scala/tools/nsc/transform/CleanUp.scala
index 0f6759cbb4..91d83b4460 100644
--- a/src/compiler/scala/tools/nsc/transform/CleanUp.scala
+++ b/src/compiler/scala/tools/nsc/transform/CleanUp.scala
@@ -731,35 +731,18 @@ abstract class CleanUp extends Transform {
val res = Block(List(ValDef(tempVar, EmptyTree), newTry), Ident(tempVar))
localTyper.typed(res)
- /* Adds @serializable annotation to anonymous function classes
- * which do not have references to classes
- * which are not marked @serializable.
- */
+ /* Adds @serializable annotation to anonymous function classes */
case cdef @ ClassDef(mods, name, tparams, impl) =>
- val sym = cdef.symbol
- // is this an anonymous function class?
- if (!sym.hasAttribute(SerializableAttr) && sym.hasFlag(SYNTHETIC) &&
- (sym.name.toString.indexOf("anonfun") != -1)) {
- // check whether all of its field members are of serializable type
- val serializable =
- sym.info.members forall { m =>
- m.isMethod || {
- val typeSym = m.info.typeSymbol
- // Value types are assumed to be serializable,
- // reference types must be marked as such.
- isValueType(typeSym) ||
- typeSym.hasAttribute(SerializableAttr) ||
- (m.info.baseClasses exists { bc => (bc hasAttribute SerializableAttr) || (bc == serialIFace) })
- }
- }
-
- if (serializable)
+ if (settings.target.value == "jvm-1.4" || settings.target.value == "jvm-1.5") {
+ val sym = cdef.symbol
+ // is this an anonymous function class?
+ if (sym.hasFlag(SYNTHETIC) && (sym.name.toString.indexOf("anonfun") != -1) &&
+ !sym.hasAttribute(SerializableAttr) &&
+ sym.isSerializable)
sym.attributes =
AnnotationInfo(definitions.SerializableAttr.tpe, List(), List()) :: sym.attributes
-
- super.transform(tree)
- } else
- super.transform(tree)
+ }
+ super.transform(tree)
case _ =>
super.transform(tree)