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

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


The following commit(s) were added to refs/heads/GROOVY_3_0_X by this push:
     new eb30684  GROOVY-10522: stubgen: no isser for Boolean property if one 
was declared
eb30684 is described below

commit eb30684e24710135e9a515b075c9b930429ee168
Author: Eric Milles <[email protected]>
AuthorDate: Mon Mar 7 16:20:57 2022 -0600

    GROOVY-10522: stubgen: no isser for Boolean property if one was declared
---
 .../org/codehaus/groovy/classgen/Verifier.java     | 18 +++++----
 .../groovy/tools/stubgenerator/Groovy10522.groovy  | 47 ++++++++++++++++++++++
 2 files changed, 58 insertions(+), 7 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/classgen/Verifier.java 
b/src/main/java/org/codehaus/groovy/classgen/Verifier.java
index 603fcef..492c559 100644
--- a/src/main/java/org/codehaus/groovy/classgen/Verifier.java
+++ b/src/main/java/org/codehaus/groovy/classgen/Verifier.java
@@ -679,20 +679,20 @@ public class Verifier implements GroovyClassVisitor, 
Opcodes {
         int accessorModifiers = adjustPropertyModifiersForMethod(node);
 
         Statement getterBlock = node.getGetterBlock();
-        if (getterBlock == null) {
+        if (getterBlock == null && !node.isPrivate()) {
             MethodNode getter = classNode.getGetterMethod(getterName, 
!node.isStatic());
             if (getter == null && 
node.getType().equals(ClassHelper.boolean_TYPE)) {
                 getter = classNode.getGetterMethod("is" + capitalize(name));
             }
-            if (!node.isPrivate() && methodNeedsReplacement(getter)) {
+            if (methodNeedsReplacement(getter)) {
                 getterBlock = createGetterBlock(node, field);
             }
         }
         Statement setterBlock = node.getSetterBlock();
-        if (setterBlock == null) {
-            // 2nd arg false below: though not usual, allow setter with 
non-void return type
-            MethodNode setter = classNode.getSetterMethod(setterName, false);
-            if (!node.isPrivate() && !isFinal(accessorModifiers) && 
methodNeedsReplacement(setter)) {
+        if (setterBlock == null && !node.isPrivate() && 
!isFinal(accessorModifiers)) {
+            boolean voidOnly = false; // accept setter with non-void return 
type
+            MethodNode setter = classNode.getSetterMethod(setterName, 
voidOnly);
+            if (methodNeedsReplacement(setter)) {
                 setterBlock = createSetterBlock(node, field);
             }
         }
@@ -706,7 +706,11 @@ public class Verifier implements GroovyClassVisitor, 
Opcodes {
             visitGetter(node, getterBlock, getterModifiers, getterName);
 
             if (node.getType().equals(ClassHelper.boolean_TYPE) || 
node.getType().equals(ClassHelper.Boolean_TYPE)) {
-                visitGetter(node, getterBlock, getterModifiers, "is" + 
capitalize(name));
+                String isserName = "is" + capitalize(name);
+                MethodNode isser = classNode.getGetterMethod(isserName, 
!node.isStatic());
+                if (methodNeedsReplacement(isser)) {
+                    visitGetter(node, getterBlock, getterModifiers, isserName);
+                }
             }
         }
         if (setterBlock != null) {
diff --git 
a/src/test/org/codehaus/groovy/tools/stubgenerator/Groovy10522.groovy 
b/src/test/org/codehaus/groovy/tools/stubgenerator/Groovy10522.groovy
new file mode 100644
index 0000000..310ecd4
--- /dev/null
+++ b/src/test/org/codehaus/groovy/tools/stubgenerator/Groovy10522.groovy
@@ -0,0 +1,47 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.codehaus.groovy.tools.stubgenerator
+
+final class Groovy10522 extends StringSourcesStubTestCase {
+
+    Map<String, String> provideSources() {
+        [
+            'Main.java': '''
+                public class Main {
+                    public static void main(String[] args) {
+                        Pogo pogo = new Pogo();
+                    }
+                }
+            ''',
+            'Pogo.groovy': '''
+                class Pogo {
+                    Boolean x
+                    boolean isX() { x }
+                }
+            '''
+        ]
+    }
+
+    void verifyStubs() {
+        String stub = stubJavaSourceFor('Pogo')
+        assert stub.contains('Boolean getX(')
+        assert !stub.contains('Boolean isX(')
+        assert stub.contains('boolean isX(')
+    }
+}

Reply via email to