groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jwagenleit...@apache.org
Subject groovy git commit: GROOVY-7723 - propertyMissing(String, Object) called for missing getter (closes #307)
Date Sat, 09 Apr 2016 17:17:06 GMT
Repository: groovy
Updated Branches:
  refs/heads/master d7f4e9362 -> a8a73ee28


GROOVY-7723 - propertyMissing(String,Object) called for missing getter (closes #307)


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/a8a73ee2
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/a8a73ee2
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/a8a73ee2

Branch: refs/heads/master
Commit: a8a73ee281c18e1ef69345997d23bff7f7c4f86e
Parents: d7f4e93
Author: John Wagenleitner <jwagenleitner@apache.org>
Authored: Sat Apr 9 02:56:08 2016 -0700
Committer: John Wagenleitner <jwagenleitner@apache.org>
Committed: Sat Apr 9 10:12:23 2016 -0700

----------------------------------------------------------------------
 src/main/groovy/lang/MetaClassImpl.java         |  9 ++++--
 src/test/groovy/lang/PropertyMissingTest.groovy | 29 ++++++++++++++++++++
 2 files changed, 35 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/a8a73ee2/src/main/groovy/lang/MetaClassImpl.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/lang/MetaClassImpl.java b/src/main/groovy/lang/MetaClassImpl.java
index ea80aa1..c0d1d7c 100644
--- a/src/main/groovy/lang/MetaClassImpl.java
+++ b/src/main/groovy/lang/MetaClassImpl.java
@@ -872,11 +872,14 @@ public class MetaClassImpl implements MetaClass, MutableMetaClass {
 
         try {
             if (!(instance instanceof Class)) {
-                if (isGetter && propertyMissingGet != null) {
-                    return propertyMissingGet.invoke(instance, new Object[]{propertyName});
+                if (isGetter) {
+                    if (propertyMissingGet != null) {
+                        return propertyMissingGet.invoke(instance, new Object[]{propertyName});
+                    }
                 } else {
-                    if (propertyMissingSet != null)
+                    if (propertyMissingSet != null) {
                         return propertyMissingSet.invoke(instance, new Object[]{propertyName,
optionalValue});
+                    }
                 }
             }
         } catch (InvokerInvocationException iie) {

http://git-wip-us.apache.org/repos/asf/groovy/blob/a8a73ee2/src/test/groovy/lang/PropertyMissingTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/groovy/lang/PropertyMissingTest.groovy b/src/test/groovy/lang/PropertyMissingTest.groovy
index 9cf6371..9ef4ae8 100644
--- a/src/test/groovy/lang/PropertyMissingTest.groovy
+++ b/src/test/groovy/lang/PropertyMissingTest.groovy
@@ -75,6 +75,28 @@ class PropertyMissingTest extends GroovyTestCase {
         assertEquals "FOO", PMTest1.FOO
     }
 
+    // GROOVY-7723
+    void testPropertyMissingSetterWithNoGetter() {
+        def t = new PMTest3()
+
+        assert t.foo == 'bar'
+
+        shouldFail(MissingPropertyException) {
+            t.notfound
+        }
+
+        assert t.foo == 'bar'
+
+        t.notfound = 'baz'
+        assert t.foo == 'notfound-baz'
+
+        t.metaClass.propertyMissing = { String name ->
+            "get-${foo}"
+        }
+        assert t.notfound == 'get-notfound-baz'
+
+    }
+
 }
 
 class PMTest1 {
@@ -90,4 +112,11 @@ class PMTest1 {
 
 class PMTest2 {
     String foo = "bar"
+}
+
+class PMTest3 {
+    String foo = 'bar'
+    void propertyMissing(String name, value) {
+        foo = "${name}-${value}"
+    }
 }
\ No newline at end of file


Mime
View raw message