Permalink
Browse files

Added a check for synthetic methods during MetaRecord introspection

Fixed #986
  • Loading branch information...
davewhittaker committed Apr 26, 2011
1 parent 0e17bce commit da2686e3a76cf9d5a1adb939551df040ac257782
@@ -98,7 +98,8 @@ trait MetaRecord[BaseRecord <: Record[BaseRecord]] {
protected val rootClass = this.getClass.getSuperclass
private def isLifecycle(m: Method) = classOf[LifecycleCallbacks].isAssignableFrom(m.getReturnType)
- private def isField(m: Method) = classOf[Field[_, _]].isAssignableFrom(m.getReturnType)
+
+ private def isField(m: Method) = !m.isSynthetic && classOf[Field[_, _]].isAssignableFrom(m.getReturnType)
def introspect(rec: BaseRecord, methods: Array[Method])(f: (Method, Field[_, BaseRecord]) => Any) = {
for (v <- methods if isField(v)) {
@@ -289,7 +290,9 @@ trait MetaRecord[BaseRecord <: Record[BaseRecord]] {
setFieldsFromJsonString(inst, json) map (_ => inst)
}
- /** Set from a Json String using the lift-json parser **/
+ /**
+ * Set from a Json String using the lift-json parser
+ */
def setFieldsFromJsonString(inst: BaseRecord, json: String): Box[Unit] =
setFieldsFromJValue(inst, JsonParser.parse(json))
@@ -236,3 +236,19 @@ class FieldTypeTestRecord private () extends Record[FieldTypeTestRecord] {
object FieldTypeTestRecord extends FieldTypeTestRecord with MetaRecord[FieldTypeTestRecord]
+trait SyntheticTestTrait{
+
+ val genericField: StringField[_]
+
+}
+
+class SyntheticTestRecord extends Record[SyntheticTestRecord] with SyntheticTestTrait{
+
+ object genericField extends StringField(this, 1024)
+
+ def meta = SyntheticTestRecord
+
+}
+
+object SyntheticTestRecord extends SyntheticTestRecord with MetaRecord[SyntheticTestRecord]
+
@@ -55,6 +55,11 @@ object RecordSpec extends Specification("Record Specification") {
rec.fieldByName("x" + name + "y") must not(verify(_.isDefined))
}
}
+
+ "ignore synthetic methods" in {
+ SyntheticTestRecord.metaFields.size must_== 1
+ }
+
}
"Record lifecycle callbacks" should {

0 comments on commit da2686e

Please sign in to comment.