1 16 package com.google.gwt.dev.jjs.ast; 17 18 import com.google.gwt.dev.jjs.SourceInfo; 19 20 import java.util.ArrayList ; 21 22 25 public class JMethodCall extends JExpression { 26 27 private ArrayList args = new ArrayList (); 28 private JExpression instance; 29 private final JMethod method; 30 private final JType overrideReturnType; 31 private boolean staticDispatchOnly = false; 32 33 public JMethodCall(JProgram program, SourceInfo info, JExpression instance, 34 JMethod method) { 35 super(program, info); 36 assert (instance != null || method.isStatic()); 37 this.instance = instance; 38 this.method = method; 39 this.staticDispatchOnly = false; 40 this.overrideReturnType = null; 41 } 42 43 54 public JMethodCall(JProgram program, SourceInfo info, JExpression instance, 55 JMethod method, JType overrideReturnType) { 56 super(program, info); 57 this.instance = instance; 58 this.method = method; 59 assert (overrideReturnType != null); 60 this.overrideReturnType = overrideReturnType; 61 } 62 63 public JMethodCall(JProgram program, SourceInfo info, JExpression instance, 64 JMethod method, boolean staticDispatchOnly) { 65 super(program, info); 66 this.instance = instance; 67 this.method = method; 68 this.staticDispatchOnly = staticDispatchOnly; 69 this.overrideReturnType = null; 70 } 71 72 public boolean canBePolymorphic() { 73 return !staticDispatchOnly && !method.isFinal() && !method.isStatic(); 74 } 75 76 public ArrayList getArgs() { 77 return args; 78 } 79 80 public JExpression getInstance() { 81 return instance; 82 } 83 84 public JMethod getTarget() { 85 return method; 86 } 87 88 public JType getType() { 89 if (overrideReturnType != null) { 90 return overrideReturnType; 91 } else { 92 return method.getType(); 93 } 94 } 95 96 public boolean hasSideEffects() { 97 return true; 99 } 100 101 public boolean isStaticDispatchOnly() { 102 return staticDispatchOnly; 103 } 104 105 public void setStaticDispatchOnly() { 106 this.staticDispatchOnly = true; 107 } 108 109 public void traverse(JVisitor visitor, Context ctx) { 110 if (visitor.visit(this, ctx)) { 111 if (instance != null) { 112 instance = visitor.accept(instance); 113 } 114 visitor.accept(args); 115 } 116 visitor.endVisit(this, ctx); 117 } 118 119 } 120 | Popular Tags |