1 46 package org.codehaus.groovy.ast.expr; 47 48 import java.lang.reflect.Field ; 49 import java.lang.reflect.Method ; 50 import java.lang.reflect.Modifier ; 51 52 import org.codehaus.groovy.ast.GroovyCodeVisitor; 53 import org.codehaus.groovy.classgen.AsmClassGenerator2; 54 55 61 public class PropertyExpression extends Expression { 62 63 private Expression objectExpression; 64 private String property; 65 private boolean safe; 66 private boolean isStatic = false; 67 68 private Method getter = null; 69 private Method setter = null; 70 71 private Field field = null; 72 private int access = -1; 73 74 public boolean isStatic() { 75 return isStatic; 76 } 77 78 public PropertyExpression(Expression objectExpression, String property) { 79 this(objectExpression, property, false); 80 } 81 82 public PropertyExpression(Expression objectExpression, String property, boolean safe) { 83 this.objectExpression = objectExpression; 84 this.property = property; 85 this.safe = safe; 86 } 87 88 public void visit(GroovyCodeVisitor visitor) { 89 visitor.visitPropertyExpression(this); 90 } 91 92 public boolean isDynamic() { 93 return true; 94 } 95 96 public Expression transformExpression(ExpressionTransformer transformer) { 97 return this; 98 } 99 100 protected void resolveType(AsmClassGenerator2 resolver) { 101 objectExpression.resolve(resolver); 102 resolver.resolve(this); 103 } 104 105 public Expression getObjectExpression() { 106 return objectExpression; 107 } 108 109 public String getProperty() { 110 return property; 111 } 112 113 public String getText() { 114 return objectExpression.getText() + "." + property; 115 } 116 117 121 public boolean isSafe() { 122 return safe; 123 } 124 125 public String toString() { 126 return super.toString() + "[object: " + objectExpression + " property: " + property + "]"; 127 } 128 129 public void setStatic(boolean aStatic) { 130 this.isStatic = aStatic; 131 } 132 133 public void setGetter(Method meth) { 134 Class returntype = meth.getReturnType(); 135 Class oldType = getTypeClass(); 136 if (oldType != null && oldType != Object .class && oldType != returntype) { 137 } 145 else { 146 getter = meth; 147 setTypeClass(returntype); 148 setTypeResolved(true); 149 } 150 } 151 152 public Method getGetter() { 153 return getter; 154 } 155 156 public void setSetter(Method method) { 157 Class paramType = method.getParameterTypes()[0]; 158 Class wasType = getTypeClass(); 159 if (wasType != null && wasType != Object .class && wasType != paramType) { 160 } 168 else { 169 setter = method; 170 setTypeClass(paramType); 171 setTypeResolved(true); 172 } 173 } 174 public Method getSetter() { 175 return setter; 176 } 177 178 public void setField(Field fld) { 179 field = fld; 180 setStatic(Modifier.isStatic(fld.getModifiers())); 181 setTypeClass(fld.getType()); 182 } 183 public Field getField() { 184 return field; 185 } 186 187 public void setAccess(int access) { 188 this.access = access; 189 } 190 191 public int getAccess() { 192 return access; 193 } 194 } 195 | Popular Tags |