You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by em...@apache.org on 2021/06/08 17:34:16 UTC

[groovy] branch GROOVY-5245 updated (bbc9659 -> e1c2f54)

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

emilles pushed a change to branch GROOVY-5245
in repository https://gitbox.apache.org/repos/asf/groovy.git.


 discard bbc9659  GROOVY-5245: bean-style property access for boolean "is" category method
     new e1c2f54  GROOVY-5245: bean-style property access for boolean "is" category method

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (bbc9659)
            \
             N -- N -- N   refs/heads/GROOVY-5245 (e1c2f54)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 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:
 .../java/org/codehaus/groovy/runtime/GroovyCategorySupport.java   | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

[groovy] 01/01: GROOVY-5245: bean-style property access for boolean "is" category method

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

emilles pushed a commit to branch GROOVY-5245
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit e1c2f547d5e4d58b12646ba472d8c18bb687aa21
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Tue Jun 8 12:31:10 2021 -0500

    GROOVY-5245: bean-style property access for boolean "is" category method
---
 .../groovy/runtime/GroovyCategorySupport.java        | 20 +++++++++++---------
 src/test/groovy/CategoryTest.groovy                  | 18 ++++++++++++++++++
 .../groovy/groovy/xml/GpathSyntaxTestSupport.groovy  | 12 ++++++------
 3 files changed, 35 insertions(+), 15 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/runtime/GroovyCategorySupport.java b/src/main/java/org/codehaus/groovy/runtime/GroovyCategorySupport.java
index adbfa33..bc1493a 100644
--- a/src/main/java/org/codehaus/groovy/runtime/GroovyCategorySupport.java
+++ b/src/main/java/org/codehaus/groovy/runtime/GroovyCategorySupport.java
@@ -161,22 +161,25 @@ public class GroovyCategorySupport {
             }
         }
 
-        private void cachePropertyAccessor(CategoryMethod method) {
-             String name = method.getName();
-             int parameterLength = method.getParameterTypes().length;
+        private void cachePropertyAccessor(final CategoryMethod method) {
+             final String name = method.getName();
+             final int nameLength = name.length();
+             final int parameterCount = method.getParameterTypes().length;
 
-             if (name.startsWith("get") && name.length() > 3 && parameterLength == 0) {
+             if (name.startsWith("get") && nameLength > 3 && parameterCount == 0) {
                  propertyGetterMap = putPropertyAccessor(3, name, propertyGetterMap);
-             }
-             else if (name.startsWith("set") && name.length() > 3 && parameterLength == 1) {
+             } else if (name.startsWith("is") && nameLength > 2 && parameterCount == 0
+                     && method.getReturnType().equals(boolean.class)) { // GROOVY-5245
+                 propertyGetterMap = putPropertyAccessor(2, name, propertyGetterMap);
+             } else if (name.startsWith("set") && nameLength > 3 && parameterCount == 1) {
                  propertySetterMap = putPropertyAccessor(3, name, propertySetterMap);
              }
         }
 
         // Precondition: accessorName.length() > prefixLength
-        private Map<String, String> putPropertyAccessor(int prefixLength, String accessorName, Map<String, String> map) {
+        private Map<String, String> putPropertyAccessor(final int prefixLength, final String accessorName, Map<String, String> map) {
             if (map == null) {
-                map = new HashMap<String, String>();
+                map = new HashMap<>();
             }
             String property = BeanUtils.decapitalize(accessorName.substring(prefixLength));
             map.put(property, accessorName);
@@ -200,7 +203,6 @@ public class GroovyCategorySupport {
             return level == 0 ? null : get(name);
         }
 
-
         String getPropertyCategoryGetterName(String propertyName) {
             if (propertyGetterMap == null) return null;
             String getter = propertyGetterMap.get(propertyName);
diff --git a/src/test/groovy/CategoryTest.groovy b/src/test/groovy/CategoryTest.groovy
index 2a7f73f..743a5e9 100644
--- a/src/test/groovy/CategoryTest.groovy
+++ b/src/test/groovy/CategoryTest.groovy
@@ -68,6 +68,24 @@ final class CategoryTest extends GroovyTestCase {
         }
     }
 
+    // GROOVY-5245
+    void testCategoryDefinedProperties2() {
+        assertScript '''
+            class Isser {
+                boolean isWorking() { true }
+            }
+            class IsserCat {
+                static boolean getWorking2(Isser b) { true }
+                static boolean isNotWorking(Isser b) { true }
+            }
+            use (IsserCat) {
+                assert new Isser().working
+                assert new Isser().working2
+                assert new Isser().notWorking // MissingPropertyException
+            }
+        '''
+    }
+
     void testCategoryReplacedPropertyAccessMethod() {
         def cth = new CategoryTestHelper()
         cth.aProperty = "aValue"
diff --git a/subprojects/groovy-xml/src/test/groovy/groovy/xml/GpathSyntaxTestSupport.groovy b/subprojects/groovy-xml/src/test/groovy/groovy/xml/GpathSyntaxTestSupport.groovy
index 614a292..f26d20f 100644
--- a/subprojects/groovy-xml/src/test/groovy/groovy/xml/GpathSyntaxTestSupport.groovy
+++ b/subprojects/groovy-xml/src/test/groovy/groovy/xml/GpathSyntaxTestSupport.groovy
@@ -18,12 +18,12 @@
  */
 package groovy.xml
 
-import org.custommonkey.xmlunit.XMLUnit
 import org.custommonkey.xmlunit.Diff
-import groovy.xml.XmlUtil
+import org.custommonkey.xmlunit.XMLUnit
 
 class GpathSyntaxTestSupport {
-    private static final sampleXml = '''
+
+    private static final sampleXml = '''\
 <characters>
     <character id="1" name="Wallace">
         <likes>cheese</likes>
@@ -35,11 +35,11 @@ class GpathSyntaxTestSupport {
     <booleanValue>y</booleanValue>
     <uriValue>http://example.org/</uriValue>
     <urlValue>http://example.org/</urlValue>
-    <empty/>
+    <noValue/>
 </characters>
 '''
 
-    private static final nestedXml = '''
+    private static final nestedXml = '''\
 <root>
     <a><z/><z/><y/></a>
     <b><z/></b>
@@ -100,7 +100,7 @@ class GpathSyntaxTestSupport {
         def unknownAttr = root.'@xxx'
         assert isSlurper(root) || !unknownAttr
         assert !isSlurper(root) || unknownAttr.isEmpty()
-        assert root.'empty'.text() == ''
+        assert root.'noValue'.text() == ''
     }
 
     static void checkCDataText(Closure getRoot) {