Last active
August 29, 2015 13:59
-
-
Save cowtowncoder/10593062 to your computer and use it in GitHub Desktop.
Trying to grok how implicits bind so that 'properties' is essentially passed/shared
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ModelPropertyParser(cls: Class[_], t: Map[String, String] = Map.empty) (implicit properties: LinkedHashMap[String, ModelProperty]) { | |
// ... | |
def parse = Option(cls).map(parseRecursive(_)) | |
def parseRecursive(hostClass: Class[_]): Unit = { | |
// ... and way, way deeper down the call stack | |
properties += name -> param | |
} | |
... | |
} | |
class XxxConverter extends ModelConverter { | |
def read(cls: Class[_], typeMap: Map[String, String]): Option[Model] = { | |
Option(cls).flatMap({ | |
cls => { | |
implicit val properties = new LinkedHashMap[String, ModelProperty]() | |
new ModelPropertyParser(cls, typeMap).parse | |
val newProperties = mutable.Buffer.empty[(String, ModelProperty)] | |
cls.getDeclaredFields.filter(field => Modifier.isPrivate(field.getModifiers)).map(_.getName).flatMap { field => | |
properties.get(field).map { value => | |
properties -= field | |
newProperties += field -> value | |
} | |
} | |
newProperties ++= properties | |
val p = (for((key, value) <- newProperties) | |
yield (value.position, key, value) | |
).toList | |
// ... and so forth | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment