1 46 package org.codehaus.groovy.ast.expr; 47 48 import groovy.lang.Closure; 49 50 import org.codehaus.groovy.ast.GroovyCodeVisitor; 51 import org.codehaus.groovy.classgen.AsmClassGenerator; 52 53 62 public class MethodPointerExpression extends Expression { 63 64 private Expression expression; 65 private String methodName; 66 67 public MethodPointerExpression(Expression expression, String methodName) { 68 this.expression = expression; 69 this.methodName = methodName; 70 } 71 72 public Expression getExpression() { 73 if (expression == null) 74 return VariableExpression.THIS_EXPRESSION; 75 else 76 return expression; 77 } 78 79 public String getMethodName() { 80 return methodName; 81 } 82 83 public void visit(GroovyCodeVisitor visitor) { 84 visitor.visitMethodPointerExpression(this); 85 } 86 87 public Expression transformExpression(ExpressionTransformer transformer) { 88 if (expression == null) 89 return new MethodPointerExpression(VariableExpression.THIS_EXPRESSION, methodName); 90 else 91 return new MethodPointerExpression(transformer.transform(expression), methodName); 92 } 93 94 protected void resolveType(AsmClassGenerator resolver) { 95 if (expression != null) { 96 expression.resolve(resolver); 97 setTypeClass(expression.getTypeClass()); 98 } 99 } 100 101 public String getText() { 102 if (expression == null) 103 return "&" + methodName; 104 else 105 return expression.getText() + ".&" + methodName; 106 } 107 108 public String getType() { 109 return "groovy.lang.Closure"; 110 } 111 112 public boolean isDynamic() { 113 return false; 114 } 115 116 public Class getTypeClass() { 117 return Closure.class; 118 } 119 } 120 | Popular Tags |