Permalink
Browse files

Mapper: delete commented code that was moved from MetaMapper to Field…

…Finder
  • Loading branch information...
1 parent 77f6e67 commit 439c79e0a27af4ad54528ef4b4d266dd8111fc38 @nafg nafg committed May 25, 2011
Showing with 1 addition and 83 deletions.
  1. +1 −83 persistence/mapper/src/main/scala/net/liftweb/mapper/MetaMapper.scala
@@ -1091,90 +1091,8 @@ trait MetaMapper[A<:Mapper[A]] extends BaseMetaMapper with Mapper[A] {
logger.debug("Initializing MetaMapper for %s".format(internalTableName_$_$))
val tArray = new ListBuffer[FieldHolder]
def isLifecycle(m: Method) = classOf[LifecycleCallbacks].isAssignableFrom(m.getReturnType)
- /*
- def isMagicObject(m: Method) = m.getReturnType.getName.endsWith("$"+m.getName+"$") && m.getParameterTypes.length == 0
- //this is not currently used
- //def isMappedField(m: Method) = classOf[MappedField[Nothing, A]].isAssignableFrom(m.getReturnType)
-
- import java.lang.reflect.Modifier
-
- /**
- * Find the magic mapper fields on the superclass
- */
- def findMagicFields(onMagic: Mapper[A], staringClass: Class[_]): List[Method] = {
- // If a class name ends in $module, it's a subclass created for scala object instances
- def deMod(in: String): String =
- if (in.endsWith("$module")) in.substring(0, in.length - 7)
- else in
-
- // find the magic fields for the given superclass
- def findForClass(clz: Class[_]): List[Method] = clz match {
- case null => Nil
- case c =>
- // get the fields
-
- val fields = Map(c.getDeclaredFields.
- // filter(f => Modifier.isPrivate(f.getModifiers)). // Issue 513 -- modifiers changed in Scala 2.8
- filter(f => classOf[MappedField[_, _]].isAssignableFrom(f.getType)).
- map(f => (deMod(f.getName), f)) :_*)
-
- // this method will find all the super classes and super-interfaces
- def getAllSupers(clz: Class[_]): List[Class[_]] = clz match {
- case null => Nil
- case c =>
- c :: c.getInterfaces.toList.flatMap(getAllSupers) :::
- getAllSupers(c.getSuperclass)
- }
-
- // does the method return an actual instance of an actual class that's
- // associated with this Mapper class
- def validActualType(meth: Method): Boolean = {
- try {
- // invoke the method
- meth.invoke(onMagic) match {
- case null =>
- logger.debug("Not a valid mapped field: %s".format(meth.getName))
- false
- case inst =>
- // do we get a MappedField of some sort back?
- if (!classOf[MappedField[_, _]].isAssignableFrom(inst.getClass)) false
- else {
- // find out if the class name of the actual thing starts
- // with the name of this class or some superclass...
- // basically, is an inner class of this class
- getAllSupers(clz).find{
- c =>
- inst.getClass.getName.startsWith(c.getName)}.isDefined
- }
- }
-
- } catch {
- case e =>
- logger.debug("Not a valid mapped field: %s, got exception: %s".format(meth.getName, e))
- false
- }
- }
-
- // find all the declared methods
- val meths = c.getDeclaredMethods.toList.
- filter(_.getParameterTypes.length == 0). // that take no parameters
- filter(m => Modifier.isPublic(m.getModifiers)). // that are public
- filter(m => fields.contains(m.getName) && // that are associated with private fields
- fields(m.getName).getType == m.getReturnType).
- filter(validActualType) // and have a validated type
-
- meths ::: findForClass(clz.getSuperclass)
- }
-
- val ret = findForClass(staringClass).distinct
-
- ret
- }
- val mapperAccessMethods = findMagicFields(this, this.getClass.getSuperclass)
- */
- val finder = new FieldFinder[MappedField[_,_]](this, logger)
- val mapperAccessMethods = finder.accessorMethods
+ val mapperAccessMethods = new FieldFinder[MappedField[_,_]](this, logger).accessorMethods
mappedCallbacks = mapperAccessMethods.filter(isLifecycle).map(v => (v.getName, v))

0 comments on commit 439c79e

Please sign in to comment.