You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by bl...@apache.org on 2016/08/19 13:59:23 UTC
groovy git commit: GROOVY-7655: track super calls to ensure there
will be a mop helper method for it
Repository: groovy
Updated Branches:
refs/heads/master 5406749fa -> 47ebf7f2b
GROOVY-7655: track super calls to ensure there will be a mop helper method for it
Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/47ebf7f2
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/47ebf7f2
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/47ebf7f2
Branch: refs/heads/master
Commit: 47ebf7f2b71939257a4d54acf1a94d7be67c491d
Parents: 5406749
Author: Jochen Theodorou <bl...@gmx.org>
Authored: Fri Aug 19 15:56:50 2016 +0200
Committer: Jochen Theodorou <bl...@gmx.org>
Committed: Fri Aug 19 15:58:21 2016 +0200
----------------------------------------------------------------------
.../groovy/classgen/asm/InvocationWriter.java | 5 ++
.../codehaus/groovy/classgen/asm/MopWriter.java | 12 ++--
.../groovy/classgen/asm/WriterController.java | 9 ++-
.../gls/invocation/MethodSelectionTest.groovy | 67 ++++++++++++++++++++
4 files changed, 87 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/groovy/blob/47ebf7f2/src/main/org/codehaus/groovy/classgen/asm/InvocationWriter.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/classgen/asm/InvocationWriter.java b/src/main/org/codehaus/groovy/classgen/asm/InvocationWriter.java
index 7485867..5557983 100644
--- a/src/main/org/codehaus/groovy/classgen/asm/InvocationWriter.java
+++ b/src/main/org/codehaus/groovy/classgen/asm/InvocationWriter.java
@@ -334,6 +334,11 @@ public class InvocationWriter {
} else {
sender.visit(acg);
}
+
+ String methodName = getMethodName(message);
+ if (adapter == invokeMethodOnSuper && methodName != null) {
+ controller.getSuperMethodNames().add(methodName);
+ }
// receiver
compileStack.pushImplicitThis(implicitThis);
http://git-wip-us.apache.org/repos/asf/groovy/blob/47ebf7f2/src/main/org/codehaus/groovy/classgen/asm/MopWriter.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/classgen/asm/MopWriter.java b/src/main/org/codehaus/groovy/classgen/asm/MopWriter.java
index 720382f..af65c9d 100644
--- a/src/main/org/codehaus/groovy/classgen/asm/MopWriter.java
+++ b/src/main/org/codehaus/groovy/classgen/asm/MopWriter.java
@@ -79,8 +79,8 @@ public class MopWriter {
return;
}
Set<MopKey> currentClassSignatures = buildCurrentClassSignatureSet(classNode.getMethods());
- visitMopMethodList(classNode.getMethods(), true, Collections.EMPTY_SET);
- visitMopMethodList(classNode.getSuperClass().getAllDeclaredMethods(), false, currentClassSignatures);
+ visitMopMethodList(classNode.getMethods(), true, Collections.EMPTY_SET, Collections.EMPTY_LIST);
+ visitMopMethodList(classNode.getSuperClass().getAllDeclaredMethods(), false, currentClassSignatures, controller.getSuperMethodNames());
}
private static Set<MopKey> buildCurrentClassSignatureSet(List<MethodNode> methods) {
@@ -104,7 +104,7 @@ public class MopWriter {
* @param isThis if true, then we are creating a MOP method on "this", "super" else
* @see #generateMopCalls(LinkedList, boolean)
*/
- private void visitMopMethodList(List<MethodNode> methods, boolean isThis, Set<MopKey> useOnlyIfDeclaredHereToo) {
+ private void visitMopMethodList(List<MethodNode> methods, boolean isThis, Set<MopKey> useOnlyIfDeclaredHereToo, List<String> orNameMentionedHere) {
HashMap<MopKey, MethodNode> mops = new HashMap<MopKey, MethodNode>();
LinkedList<MethodNode> mopCalls = new LinkedList<MethodNode>();
for (MethodNode mn : methods) {
@@ -123,7 +123,11 @@ public class MopWriter {
continue;
}
if (methodName.startsWith("<")) continue;
- if (!useOnlyIfDeclaredHereToo.contains(new MopKey(methodName, mn.getParameters()))) continue;
+ if (!useOnlyIfDeclaredHereToo.contains(new MopKey(methodName, mn.getParameters())) &&
+ !orNameMentionedHere.contains(methodName))
+ {
+ continue;
+ }
String name = getMopMethodName(mn, isThis);
MopKey key = new MopKey(name, mn.getParameters());
if (mops.containsKey(key)) continue;
http://git-wip-us.apache.org/repos/asf/groovy/blob/47ebf7f2/src/main/org/codehaus/groovy/classgen/asm/WriterController.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/classgen/asm/WriterController.java b/src/main/org/codehaus/groovy/classgen/asm/WriterController.java
index e6246b4..6856c07 100644
--- a/src/main/org/codehaus/groovy/classgen/asm/WriterController.java
+++ b/src/main/org/codehaus/groovy/classgen/asm/WriterController.java
@@ -19,10 +19,10 @@
package org.codehaus.groovy.classgen.asm;
import groovy.lang.GroovyRuntimeException;
-
import java.lang.reflect.Constructor;
+import java.util.ArrayList;
+import java.util.List;
import java.util.Map;
-
import org.codehaus.groovy.GroovyBugError;
import org.codehaus.groovy.ast.ClassHelper;
import org.codehaus.groovy.ast.ClassNode;
@@ -83,6 +83,7 @@ public class WriterController {
private int bytecodeVersion = Opcodes.V1_5;
private int lineNumber = -1;
private int helperMethodIndex = 0;
+ private List<String> superMethodNames = new ArrayList<String>();
public void init(AsmClassGenerator asmClassGenerator, GeneratorContext gcon, ClassVisitor cv, ClassNode cn) {
CompilerConfiguration config = cn.getCompileUnit().getConfig();
@@ -406,4 +407,8 @@ public class WriterController {
public int getNextHelperMethodIndex() {
return helperMethodIndex++;
}
+
+ public List<String> getSuperMethodNames() {
+ return superMethodNames;
+ }
}
http://git-wip-us.apache.org/repos/asf/groovy/blob/47ebf7f2/src/test/gls/invocation/MethodSelectionTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/gls/invocation/MethodSelectionTest.groovy b/src/test/gls/invocation/MethodSelectionTest.groovy
index 4fd5331..ae131ea 100644
--- a/src/test/gls/invocation/MethodSelectionTest.groovy
+++ b/src/test/gls/invocation/MethodSelectionTest.groovy
@@ -430,6 +430,73 @@ public class MethodSelectionTest extends CompilableTestSupport {
assert 3 == exp.takeBigInteger(new MyInteger("3"))
'''
}
+
+ // GROOVY-7655
+ void testOverloadAndSuper() {
+ assertScript '''
+ class A {
+ boolean aCalled = false
+ def myMethod( def item ) {
+ aCalled = true
+ }
+ }
+
+ class B extends A {
+ boolean bCalled = false
+ def myMethod( def item ) {
+ super.myMethod( item+"B" )
+ bCalled = true
+ }
+ }
+
+ class C extends B {
+ boolean cCalled = false
+ def cMethod( def item ) {
+ super.myMethod( item )
+ cCalled = true
+ }
+ }
+
+ def c = new C()
+ c.cMethod( "stuff" )
+
+ assert c.aCalled
+ assert c.bCalled
+ assert c.cCalled
+ '''
+ assertScript '''
+ class A {
+ boolean aCalled = false
+ def myMethod( def item ) {
+ aCalled = true
+ }
+ }
+
+ class B extends A {
+ boolean bCalled = false
+ def myMethod( def item ) {
+ super.myMethod( item+"B" )
+ bCalled = true
+ }
+ }
+
+ class C extends B { }
+ class D extends C {
+ boolean dCalled = false
+ def dMethod( def item ) {
+ super.myMethod( item )
+ dCalled = true
+ }
+ }
+
+ def d = new D()
+ d.dMethod( "stuff" )
+
+ assert d.aCalled
+ assert d.bCalled
+ assert d.dCalled
+ '''
+ }
}
class Foo3977 {