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

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-8718: handle new quit handler param

paulk
Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_5_X ed0815e5b -> dc3918b4f


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/dc3918b4
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/dc3918b4
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/dc3918b4

Branch: refs/heads/GROOVY_2_5_X
Commit: dc3918b4f2a81a8ad1f42b056dc17f7716cc08e3
Parents: 3bf1b9f
Author: Paul King <[hidden email]>
Authored: Fri Aug 10 09:29:22 2018 +1000
Committer: Paul King <[hidden email]>
Committed: Fri Aug 10 09:30:10 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/dc3918b4/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 2acc046..14106bd 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()

Reply | Threaded
Open this post in threaded view
|

[2/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
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/3bf1b9fd
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/3bf1b9fd
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/3bf1b9fd

Branch: refs/heads/GROOVY_2_5_X
Commit: 3bf1b9fd35b14509dae94fcb23292eb42da1c04a
Parents: ed0815e
Author: Paul King <[hidden email]>
Authored: Thu Aug 9 18:12:08 2018 +1000
Committer: Paul King <[hidden email]>
Committed: Fri Aug 10 09:30:10 2018 +1000

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


http://git-wip-us.apache.org/repos/asf/groovy/blob/3bf1b9fd/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 6bdcb36..98ab3e5 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -88,6 +88,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;
@@ -482,14 +483,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.
      */