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:16:22 GMT
Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_4_X e2cd02dba -> 89240663c


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/89240663
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/89240663
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/89240663

Branch: refs/heads/GROOVY_2_4_X
Commit: 89240663c8d329a98e9019eeb34cf4e9dcbc8c4f
Parents: e2cd02d
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:14:26 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/89240663/src/main/groovy/lang/MetaClassImpl.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/lang/MetaClassImpl.java b/src/main/groovy/lang/MetaClassImpl.java
index 79c50c2..24baec7 100644
--- a/src/main/groovy/lang/MetaClassImpl.java
+++ b/src/main/groovy/lang/MetaClassImpl.java
@@ -875,11 +875,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/89240663/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