[1/2] groovy git commit: GROOVY-8732: @CompileStatic refers to private field in parent class (closes #781) Currently JavaBean style getters aren't recognised before some preliminary provisions are made for the case of accessing the private field in place

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[1/2] groovy git commit: GROOVY-8732: @CompileStatic refers to private field in parent class (closes #781) Currently JavaBean style getters aren't recognised before some preliminary provisions are made for the case of accessing the private field in place

paulk
Repository: groovy
Updated Branches:
  refs/heads/master 234724e25 -> d56d9e756


GROOVY-8732: @CompileStatic refers to private field in parent class (closes #781)
Currently JavaBean style getters aren't recognised
before some preliminary provisions are made for the
case of accessing the private field in places where that
is allowed. The change is just not to proceed with those
provisions if the JavaBean getter is detected.


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

Branch: refs/heads/master
Commit: 4c6a8a657ce02a65398942ce51942cdd8110df88
Parents: 234724e
Author: Paul King <[hidden email]>
Authored: Thu Aug 9 18:12:08 2018 +1000
Committer: Paul King <[hidden email]>
Committed: Fri Aug 10 08:21:21 2018 +1000

----------------------------------------------------------------------
 .../stc/StaticTypeCheckingVisitor.java          | 31 ++++++++++++++++++--
 1 file changed, 28 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/4c6a8a65/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
index d51491b..6d1f21c 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -89,6 +89,7 @@ import org.codehaus.groovy.ast.stmt.WhileStatement;
 import org.codehaus.groovy.ast.tools.GenericsUtils;
 import org.codehaus.groovy.ast.tools.WideningCategories;
 import org.codehaus.groovy.classgen.ReturnAdder;
+import org.codehaus.groovy.classgen.Verifier;
 import org.codehaus.groovy.classgen.asm.InvocationWriter;
 import org.codehaus.groovy.control.CompilationUnit;
 import org.codehaus.groovy.control.ErrorCollector;
@@ -487,14 +488,38 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
      * Given a field node, checks if we are accessing or setting a private field from an inner class.
      */
     private void checkOrMarkPrivateAccess(Expression source, FieldNode fn, boolean lhsOfAssignment) {
+        ClassNode enclosingClassNode = typeCheckingContext.getEnclosingClassNode();
+        ClassNode declaringClass = fn.getDeclaringClass();
         if (fn != null && Modifier.isPrivate(fn.getModifiers()) &&
-                (fn.getDeclaringClass() != typeCheckingContext.getEnclosingClassNode() || typeCheckingContext.getEnclosingClosure() != null) &&
-                fn.getDeclaringClass().getModule() == typeCheckingContext.getEnclosingClassNode().getModule()) {
+                (declaringClass != enclosingClassNode || typeCheckingContext.getEnclosingClosure() != null) &&
+                declaringClass.getModule() == enclosingClassNode.getModule()) {
+            if (!lhsOfAssignment && enclosingClassNode.isDerivedFrom(declaringClass)) {
+                // check for a public/protected getter since JavaBean getters haven't been recognised as properties
+                // at this point and we don't want private field access for that case which will be handled later
+                boolean isPrimBool = fn.getOriginType().equals(ClassHelper.boolean_TYPE);
+                String suffix = Verifier.capitalize(fn.getName());
+                MethodNode getterNode = findValidGetter(enclosingClassNode, "get" + suffix);
+                if (getterNode == null && isPrimBool) {
+                    getterNode = findValidGetter(enclosingClassNode, "is" + suffix);
+                }
+                if (getterNode != null) {
+                    source.setNodeMetaData(StaticTypesMarker.INFERRED_TYPE, getterNode.getReturnType());
+                    return;
+                }
+            }
             StaticTypesMarker marker = lhsOfAssignment ? StaticTypesMarker.PV_FIELDS_MUTATION : StaticTypesMarker.PV_FIELDS_ACCESS;
-            addPrivateFieldOrMethodAccess(source, fn.getDeclaringClass(), marker, fn);
+            addPrivateFieldOrMethodAccess(source, declaringClass, marker, fn);
         }
     }
 
+    private MethodNode findValidGetter(ClassNode classNode, String name) {
+        MethodNode getterMethod = classNode.getGetterMethod(name);
+        if (getterMethod != null && (getterMethod.isPublic() || getterMethod.isProtected())) {
+            return getterMethod;
+        }
+        return null;
+    }
+
     /**
      * Given a method node, checks if we are calling a private method from an inner class.
      */

Reply | Threaded
Open this post in threaded view
|

[2/2] groovy git commit: GROOVY-8718: handle new quit handler param

paulk
GROOVY-8718: handle new quit handler param


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

Branch: refs/heads/master
Commit: d56d9e756b29f0f5913808e495611b105c0e1fdf
Parents: 4c6a8a6
Author: Paul King <[hidden email]>
Authored: Fri Aug 10 09:29:22 2018 +1000
Committer: Paul King <[hidden email]>
Committed: Fri Aug 10 09:29:22 2018 +1000

----------------------------------------------------------------------
 .../groovy-console/src/main/groovy/groovy/ui/Console.groovy      | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/d56d9e75/subprojects/groovy-console/src/main/groovy/groovy/ui/Console.groovy
----------------------------------------------------------------------
diff --git a/subprojects/groovy-console/src/main/groovy/groovy/ui/Console.groovy b/subprojects/groovy-console/src/main/groovy/groovy/ui/Console.groovy
index a4704c9..8a1708d 100644
--- a/subprojects/groovy-console/src/main/groovy/groovy/ui/Console.groovy
+++ b/subprojects/groovy-console/src/main/groovy/groovy/ui/Console.groovy
@@ -679,8 +679,8 @@ class Console implements CaretListener, HyperlinkListener, ComponentListener, Fo
         runThread?.interrupt()
     }
 
-    void exit(EventObject evt = null) {
-        if(askToInterruptScript()) {
+    void exit(EventObject evt = null, desktopQuitResponse = null) {
+        if (askToInterruptScript()) {
             if (askToSaveFile()) {
                 if (frame instanceof Window) {
                     frame.hide()