Revision: 6095 Author: [email protected] Date: Tue Sep 8 09:08:10 2009 Log: Fixes bugs where a cloned JMethodCall fails to preserve an overridden return type.
Hopefully by adding a copy constructor, we can avoid these bugs in the future. Review by: cromwellian http://code.google.com/p/google-web-toolkit/source/detail?r=6095 Modified: /trunk/dev/core/src/com/google/gwt/dev/jjs/ast/JMethodCall.java /trunk/dev/core/src/com/google/gwt/dev/jjs/impl/CloneExpressionVisitor.java /trunk/dev/core/src/com/google/gwt/dev/jjs/impl/Pruner.java ======================================= --- /trunk/dev/core/src/com/google/gwt/dev/jjs/ast/JMethodCall.java Thu Apr 9 08:41:34 2009 +++ /trunk/dev/core/src/com/google/gwt/dev/jjs/ast/JMethodCall.java Tue Sep 8 09:08:10 2009 @@ -32,6 +32,20 @@ private final JMethod method; private final JType overrideReturnType; private boolean staticDispatchOnly = false; + + /** + * Initialize a new method call equivalent to another one. A new instance must + * be specified, and the new object has not arguments on initialization. This + * forces the caller to potentially deal with cloning objects if needed. + */ + public JMethodCall(JMethodCall other, JExpression instance) { + super(other.getSourceInfo()); + this.instance = instance; + this.cannotBePolymorphic = other.cannotBePolymorphic; + this.method = other.method; + this.overrideReturnType = other.overrideReturnType; + this.staticDispatchOnly = other.staticDispatchOnly; + } public JMethodCall(SourceInfo info, JExpression instance, JMethod method) { super(info); @@ -39,18 +53,8 @@ assert (instance != null || method.isStatic()); this.instance = instance; this.method = method; - this.staticDispatchOnly = false; this.overrideReturnType = null; } - - public JMethodCall(SourceInfo info, JExpression instance, JMethod method, - boolean staticDispatchOnly) { - super(info); - this.instance = instance; - this.method = method; - this.staticDispatchOnly = staticDispatchOnly; - this.overrideReturnType = null; - } /** * Create a method call whose type is overridden to the specified type, @@ -66,6 +70,8 @@ public JMethodCall(SourceInfo info, JExpression instance, JMethod method, JType overrideReturnType) { super(info); + assert (method != null); + assert (instance != null || method.isStatic()); this.instance = instance; this.method = method; assert (overrideReturnType != null); ======================================= --- /trunk/dev/core/src/com/google/gwt/dev/jjs/impl/CloneExpressionVisitor.java Fri May 29 15:31:48 2009 +++ /trunk/dev/core/src/com/google/gwt/dev/jjs/impl/CloneExpressionVisitor.java Tue Sep 8 09:08:10 2009 @@ -219,14 +219,9 @@ @Override public boolean visit(JMethodCall x, Context ctx) { - JMethodCall newMethodCall = new JMethodCall(x.getSourceInfo(), - cloneExpression(x.getInstance()), x.getTarget()); - if (!x.canBePolymorphic()) { - newMethodCall.setCannotBePolymorphic(); - } - + JMethodCall newMethodCall = new JMethodCall(x, + cloneExpression(x.getInstance())); newMethodCall.addArgs(cloneExpressions(x.getArgs())); - expression = newMethodCall; return false; } ======================================= --- /trunk/dev/core/src/com/google/gwt/dev/jjs/impl/Pruner.java Mon Jul 6 14:45:31 2009 +++ /trunk/dev/core/src/com/google/gwt/dev/jjs/impl/Pruner.java Tue Sep 8 09:08:10 2009 @@ -189,12 +189,7 @@ // This must be a static method assert method.isStatic(); - JMethodCall newCall = new JMethodCall(x.getSourceInfo(), - x.getInstance(), method); - if (!x.canBePolymorphic()) { - newCall.setCannotBePolymorphic(); - } - + JMethodCall newCall = new JMethodCall(x, x.getInstance()); List<JParameter> originalParams = methodToOriginalParamsMap.get(method); JMultiExpression currentMulti = null; for (int i = 0, c = x.getArgs().size(); i < c; ++i) { --~--~---------~--~----~------------~-------~--~----~ http://groups.google.com/group/Google-Web-Toolkit-Contributors -~----------~----~----~----~------~----~------~--~---
