groovy git commit: Documentation updated: added static methodMissing and propertyMissing variants description (closes #794)

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

groovy git commit: Documentation updated: added static methodMissing and propertyMissing variants description (closes #794)

paulk
Repository: groovy
Updated Branches:
  refs/heads/master 96c543dd0 -> b255db420


Documentation updated: added static methodMissing and propertyMissing variants description (closes #794)


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

Branch: refs/heads/master
Commit: b255db4201cc98f48277098027bd31bc7e3ecb30
Parents: 96c543d
Author: Szymon Stępniak <[hidden email]>
Authored: Mon Sep 10 19:42:49 2018 +0200
Committer: Paul King <[hidden email]>
Committed: Thu Sep 13 16:42:16 2018 +1000

----------------------------------------------------------------------
 src/spec/doc/core-metaprogramming.adoc          | 22 +++++++++++--
 ...icPropertyMissingAndMethodMissingTest.groovy | 33 ++++++++++++++++++++
 2 files changed, 52 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/b255db42/src/spec/doc/core-metaprogramming.adoc
----------------------------------------------------------------------
diff --git a/src/spec/doc/core-metaprogramming.adoc b/src/spec/doc/core-metaprogramming.adoc
index da25e57..dc165d9 100644
--- a/src/spec/doc/core-metaprogramming.adoc
+++ b/src/spec/doc/core-metaprogramming.adoc
@@ -187,9 +187,25 @@ include::{projectdir}/src/spec/test/metaprogramming/MethodPropertyMissingTest.gr
 As with `methodMissing` it is best practice to dynamically register new properties at runtime to improve the overall lookup
 performance.
 
-[NOTE]
-`methodMissing` and `propertyMissing` methods that deal with static methods and properties can be added via
-the <<core-metaprogramming.adoc#metaprogramming_emc,ExpandoMetaClass>>.
+=== static methodMissing
+
+Static variant of `methodMissing` method can be added via the <<core-metaprogramming.adoc#metaprogramming_emc,ExpandoMetaClass>>
+or can be implemented at the class level with `$static_methodMissing` method.
+
+[source,groovy]
+----
+include::{projectdir}/src/spec/test/metaprogramming/StaticPropertyMissingAndMethodMissingTest.groovy[tags=static_method_missing,indent=0]
+----
+
+=== static propertyMissing
+
+Static variant of `propertyMissing` method can be added via the <<core-metaprogramming.adoc#metaprogramming_emc,ExpandoMetaClass>>
+or can be implemented at the class level with `$static_propertyMissing` method.
+
+[source,groovy]
+----
+include::{projectdir}/src/spec/test/metaprogramming/StaticPropertyMissingAndMethodMissingTest.groovy[tags=static_property_missing,indent=0]
+----
 
 === GroovyInterceptable
 The gapi:groovy.lang.GroovyInterceptable[] interface is marker interface that extends `GroovyObject` and is used to notify the Groovy runtime that all methods should be intercepted through the method dispatcher mechanism of the Groovy runtime.

http://git-wip-us.apache.org/repos/asf/groovy/blob/b255db42/src/spec/test/metaprogramming/StaticPropertyMissingAndMethodMissingTest.groovy
----------------------------------------------------------------------
diff --git a/src/spec/test/metaprogramming/StaticPropertyMissingAndMethodMissingTest.groovy b/src/spec/test/metaprogramming/StaticPropertyMissingAndMethodMissingTest.groovy
new file mode 100644
index 0000000..dbeff95
--- /dev/null
+++ b/src/spec/test/metaprogramming/StaticPropertyMissingAndMethodMissingTest.groovy
@@ -0,0 +1,33 @@
+package metaprogramming
+
+class StaticPropertyMissingAndMethodMissingTest extends GroovyTestCase {
+
+    void testStaticMethodMissing() {
+        assertScript '''
+            // tag::static_method_missing[]
+            class Foo {
+                static def $static_methodMissing(String name, Object args) {
+                    return "Missing static method name is $name"
+                }
+            }
+
+            assert Foo.bar() == 'Missing static method name is bar'
+            // end::static_method_missing[]
+'''
+    }
+
+    void testStaticPropertyMissing() {
+
+        assertScript '''
+            // tag::static_property_missing[]
+            class Foo {
+                static def $static_propertyMissing(String name) {
+                    return "Missing static property name is $name"
+                }
+            }
+
+            assert Foo.foobar == 'Missing static property name is foobar'
+            // end::static_property_missing[]
+'''
+    }
+}