blackdrag commented on code in PR #2495:
URL: https://github.com/apache/groovy/pull/2495#discussion_r3159896730


##########
src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesWriterController.java:
##########
@@ -87,15 +94,77 @@ public void init(final AsmClassGenerator asmClassGenerator, 
final GeneratorConte
     @Override
     public void setMethodNode(final MethodNode mn) {
         isInStaticallyCheckedMethod = isStaticallyCompiled(mn);
+        methodHasDynamicResolution = isInStaticallyCheckedMethod && 
hasDynamicResolution(mn);
         super.setMethodNode(mn);
     }
 
     @Override
     public void setConstructorNode(final ConstructorNode cn) {
         isInStaticallyCheckedMethod = isStaticallyCompiled(cn);
+        methodHasDynamicResolution = isInStaticallyCheckedMethod && 
hasDynamicResolution(cn);
         super.setConstructorNode(cn);
     }
 
+    /**
+     * GROOVY-11968: returns {@code true} when the current statically compiled 
method
+     * contains one or more sub-expressions that will be routed through the 
regular
+     * (non-static) call site writer via {@link #getCallSiteWriterFor}. The 
regular
+     * writer's per-method state must then be initialized at method entry.
+     */
+    public boolean methodHasDynamicResolution() {
+        return methodHasDynamicResolution;
+    }
+
+    private static boolean hasDynamicResolution(final MethodNode mn) {
+        if (mn == null) return false;
+        if (mn.getNodeMetaData(DYNAMIC_RESOLUTION) != null) return true;
+        if (mn.getCode() == null) return false;
+        var scanner = new DynamicResolutionScanner();
+        mn.getCode().visit(scanner);
+        return scanner.found;
+    }
+
+    private static class DynamicResolutionScanner extends CodeVisitorSupport {
+        boolean found;
+
+        @Override
+        public void visitMethodCallExpression(final MethodCallExpression call) 
{
+            if (mark(call)) return;
+            super.visitMethodCallExpression(call);
+        }
+
+        @Override
+        public void visitStaticMethodCallExpression(final 
StaticMethodCallExpression call) {
+            if (mark(call)) return;
+            super.visitStaticMethodCallExpression(call);
+        }
+
+        @Override
+        public void visitPropertyExpression(final PropertyExpression 
expression) {
+            if (mark(expression)) return;
+            super.visitPropertyExpression(expression);
+        }
+
+        @Override
+        public void visitAttributeExpression(final AttributeExpression 
expression) {
+            if (mark(expression)) return;
+            super.visitAttributeExpression(expression);
+        }
+
+        @Override
+        public void visitVariableExpression(final VariableExpression 
expression) {
+            if (mark(expression)) return;
+            super.visitVariableExpression(expression);
+        }
+
+        private boolean mark(final Expression e) {

Review Comment:
   not wanting to nitpick, but mark is something you do. This is a check. 
isMakedDynamic or something like that would express the intend of the method 
better



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to