You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2020/04/04 11:54:36 UTC

[groovy] branch master updated (5b1c03e -> d93d19f)

This is an automated email from the ASF dual-hosted git repository.

paulk pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git.


    from 5b1c03e  GROOVY-9497: Bump asm to 8.0.1
     new 82816bd  fix whitespace only
     new d93d19f  GROOVY-9495: groovy.transform.NullCheck not mentioned in release notes or language documentation

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../org/codehaus/groovy/control/ProcessingUnit.java  |  3 ++-
 src/spec/doc/core-metaprogramming.adoc               | 14 ++++++++++++++
 src/spec/test/CodeGenerationASTTransformsTest.groovy | 20 ++++++++++++++++++++
 3 files changed, 36 insertions(+), 1 deletion(-)


[groovy] 02/02: GROOVY-9495: groovy.transform.NullCheck not mentioned in release notes or language documentation

Posted by pa...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

paulk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit d93d19fdb39b881fe6a3b06f6bdbb8fd05725d8b
Author: Paul King <pa...@asert.com.au>
AuthorDate: Sat Apr 4 21:54:28 2020 +1000

    GROOVY-9495: groovy.transform.NullCheck not mentioned in release notes or language documentation
---
 src/spec/doc/core-metaprogramming.adoc               | 14 ++++++++++++++
 src/spec/test/CodeGenerationASTTransformsTest.groovy | 20 ++++++++++++++++++++
 2 files changed, 34 insertions(+)

diff --git a/src/spec/doc/core-metaprogramming.adoc b/src/spec/doc/core-metaprogramming.adoc
index e5e614b..5d34f41 100644
--- a/src/spec/doc/core-metaprogramming.adoc
+++ b/src/spec/doc/core-metaprogramming.adoc
@@ -1729,6 +1729,20 @@ It is also worthwhile examining the equivalent generated code where the `next` m
 include::{projectdir}/src/spec/test/CodeGenerationASTTransformsTest.groovy[tags=autoimplement_code_equiv,indent=0]
 ----
 
+[[xform-NullCheck]]
+===== `@groovy.transform.NullCheck`
+
+The `@NullCheck` AST transformation adds null-check guard statements to constructors and methods
+which cause those methods to fail early when supplied with null arguments.
+It can be seen as a form of defensive programming.
+The annotation can be added to individual methods or constructors, or to the class
+in which case it will apply to all methods/constructors.
+
+[source,groovy]
+----
+include::{projectdir}/src/spec/test/CodeGenerationASTTransformsTest.groovy[tags=nullcheck,indent=0]
+----
+
 ==== Class design annotations
 
 This category of annotations are aimed at simplifying the implementation of well-known design patterns (delegation,
diff --git a/src/spec/test/CodeGenerationASTTransformsTest.groovy b/src/spec/test/CodeGenerationASTTransformsTest.groovy
index b19775d..0d13450 100644
--- a/src/spec/test/CodeGenerationASTTransformsTest.groovy
+++ b/src/spec/test/CodeGenerationASTTransformsTest.groovy
@@ -1678,4 +1678,24 @@ class EmptyIterator implements java.util.Iterator<String> {
 */
         '''
     }
+
+    void testNullCheck() {
+        assertScript '''
+ import groovy.transform.NullCheck
+ import static groovy.test.GroovyAssert.shouldFail
+
+// tag::nullcheck[]
+@NullCheck
+String longerOf(String first, String second) {
+    first.size() >= second.size() ? first : second
+}
+
+assert longerOf('cat', 'canary') == 'canary'
+def ex = shouldFail(IllegalArgumentException) {
+    longerOf('cat', null)
+}
+assert ex.message == 'second cannot be null'
+// end::nullcheck[]
+'''
+    }
 }


[groovy] 01/02: fix whitespace only

Posted by pa...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

paulk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit 82816bd88cc45f19b122d3d97295fb1f10bbb372
Author: Paul King <pa...@asert.com.au>
AuthorDate: Sat Apr 4 20:05:55 2020 +1000

    fix whitespace only
---
 src/main/java/org/codehaus/groovy/control/ProcessingUnit.java | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/codehaus/groovy/control/ProcessingUnit.java b/src/main/java/org/codehaus/groovy/control/ProcessingUnit.java
index 162fa6c..0b12ebf 100644
--- a/src/main/java/org/codehaus/groovy/control/ProcessingUnit.java
+++ b/src/main/java/org/codehaus/groovy/control/ProcessingUnit.java
@@ -60,7 +60,8 @@ public abstract class ProcessingUnit {
      * Initializes the ProcessingUnit to the empty state.
      */
     public ProcessingUnit(final CompilerConfiguration configuration, final GroovyClassLoader classLoader, final ErrorCollector errorCollector) {
-        setConfiguration(configuration != null ? configuration : CompilerConfiguration.DEFAULT); setClassLoader(classLoader);
+        setConfiguration(configuration != null ? configuration : CompilerConfiguration.DEFAULT);
+        setClassLoader(classLoader);
         this.errorCollector = errorCollector != null ? errorCollector : new ErrorCollector(getConfiguration());
         configure(getConfiguration());
     }