1 5 package com.tc.object.field; 6 7 import com.tc.object.LiteralValues; 8 import com.tc.object.TCClass; 9 import com.tc.util.Assert; 10 11 import java.lang.reflect.Field ; 12 import java.lang.reflect.Modifier ; 13 14 17 public class GenericTCField implements TCField { 18 19 private static final LiteralValues literalValues = new LiteralValues(); 20 21 private final TCClass tcClass; 22 private final boolean isPortable; 23 private final String fieldName; 24 private final boolean isFinal; 25 private final boolean isArray; 26 private final boolean canBeReference; 27 28 protected GenericTCField(TCClass tcClass, Field field, boolean portable) { 29 Assert.eval(tcClass != null); 30 Assert.eval(field != null); 31 this.tcClass = tcClass; 32 this.fieldName = (tcClass.getName() + "." + field.getName()).intern(); 33 34 portable = portable || fieldName.equals(tcClass.getParentFieldName()); 36 this.isPortable = portable && !field.getType().getName().startsWith("com.tc."); 37 38 this.isFinal = Modifier.isFinal(field.getModifiers()); 39 this.isArray = field.getType().isArray(); 40 this.canBeReference = isReferenceField(field); 41 } 42 43 private static boolean isReferenceField(Field field) { 44 if (Modifier.isStatic(field.getModifiers())) return false; 45 Class type = field.getType(); 46 47 if (literalValues.isLiteral(type.getName())) { 48 return !type.isPrimitive(); 49 } 50 51 return true; 52 } 53 54 public TCClass getDeclaringTCClass() { 55 return tcClass; 56 } 57 58 public boolean isFinal() { 59 return isFinal; 60 } 61 62 public boolean isPortable() { 63 return isPortable; 64 } 65 66 public boolean isArray() { 67 return this.isArray; 68 } 69 70 public String getName() { 71 return fieldName; 72 } 73 74 public boolean canBeReference() { 75 return this.canBeReference; 76 } 77 78 public String toString() { 79 return getClass().getName() + "(" + getName() + ")"; 80 } 81 } 82 | Popular Tags |