1 17 18 package org.objectweb.jac.core.rtti; 19 20 import java.lang.reflect.*; 21 28 29 public abstract class MemberItem extends MetaItemDelegate { 30 31 36 public static MemberItem getMemberFromFullName(String str) throws Exception { 37 MemberItem ret=null; 38 int index = -1; 39 int paren = str.indexOf("("); 40 if (paren==-1) 41 index = str.lastIndexOf("."); 42 else 43 index = str.lastIndexOf(".",paren); 44 if (index!=-1) { 45 ClassItem classItem = 46 ClassRepository.get().getClass 47 (str.substring(0,index)); 48 ret = classItem.getMember(str.substring(index+1)); 49 } else { 50 new Exception ("Failed to convert "+str+ 51 " into a class member"); 52 } 53 return ret; 54 } 55 56 static Class wrappeeClass = ClassRepository.wrappeeClass; 57 58 public MemberItem(ClassItem parent) { 59 this.parent = parent; 60 } 61 62 public MemberItem(Object delegate, ClassItem parent) throws InvalidDelegateException { 63 super(delegate); 64 this.parent = parent; 65 } 66 67 public abstract Class getType(); 68 69 public final ClassItem getTypeItem() { 70 return ClassRepository.get().getClass(getType()); 71 } 72 73 74 public final ClassItem getClassItem() { 75 return (ClassItem)getParent(); 76 } 77 78 MethodItem[] dependentMethods = MethodItem.emptyArray; 79 82 public final void addDependentMethod(MethodItem method) { 83 MethodItem[] tmp = new MethodItem[dependentMethods.length+1]; 84 System.arraycopy(dependentMethods, 0, tmp, 0, dependentMethods.length); 85 tmp[dependentMethods.length] = method; 86 dependentMethods = tmp; 87 ClassItem superClass = getClassItem().getSuperclass(); 88 if (superClass!=null) { 89 FieldItem superField = superClass.getFieldNoError(getName()); 90 if (superField!=null) 91 superField.addDependentMethod(method); 92 } 93 } 94 98 public final MethodItem[] getDependentMethods() { 99 return dependentMethods; 100 } 101 102 103 protected boolean role; 104 105 111 112 public boolean isRole() { 113 return role; 114 } 115 116 protected ClassItem roleClassType = null; 117 protected String roleType = null; 118 protected String roleName = null; 119 120 129 public void setRole(ClassItem roleClassType, String roleType, String roleName) { 130 this.role = true; 131 this.roleClassType = roleClassType; 132 this.roleType = roleType; 133 this.roleName = roleName; 134 } 135 136 139 public String getLongName() { 140 return parent!=null ? parent.getName()+"."+getName() : "???"; 141 } 142 143 public int getModifiers() { 144 return ((Member)delegate).getModifiers(); 145 } 146 147 public String toString() { 148 return getLongName()+":"+getType().getName(); 149 } 150 151 155 public boolean equals(Object o) { 156 if (!(o instanceof MemberItem)) 157 return false; 158 MemberItem m = (MemberItem)o; 159 return (m.getClassItem().isSubClassOf(getClassItem()) || 160 getClassItem().isSubClassOf(m.getClassItem())) 161 && getName().equals(m.getName()); 162 } 163 } 164 | Popular Tags |