1 22 package org.jboss.reflect.plugins; 23 24 import java.lang.reflect.Modifier ; 25 import java.util.Arrays ; 26 27 import org.jboss.reflect.spi.AnnotationValue; 28 import org.jboss.reflect.spi.ClassInfo; 29 import org.jboss.reflect.spi.MethodInfo; 30 import org.jboss.reflect.spi.ParameterInfo; 31 import org.jboss.reflect.spi.TypeInfo; 32 import org.jboss.util.JBossStringBuilder; 33 import org.jboss.util.NotImplementedException; 34 35 41 public class MethodInfoImpl extends AnnotationHolder implements MethodInfo 42 { 43 44 private static final long serialVersionUID = 3257007670035756341L; 45 46 47 protected String name; 48 49 50 protected ClassInfo declaringClass; 51 52 53 protected TypeInfo[] parameterTypes; 54 55 56 protected ParameterInfo[] parameters; 57 58 59 protected ClassInfo[] exceptionTypes; 60 61 62 protected int modifiers; 63 64 65 protected TypeInfo returnType; 66 67 68 protected int hash; 69 70 73 public MethodInfoImpl() 74 { 75 } 76 77 89 public MethodInfoImpl(AnnotationValue[] annotations, String name, TypeInfo returnType, TypeInfo[] parameterTypes, AnnotationValue[][] parameterAnnotations, ClassInfo[] exceptionTypes, int modifiers, ClassInfo declaring) 90 { 91 super(annotations); 92 this.name = name; 93 if (parameterTypes == null) 94 { 95 this.parameterTypes = MethodInfo.NO_PARAMS_TYPES; 96 this.parameters = MethodInfo.NO_PARAMS; 97 } 98 else 99 { 100 this.parameterTypes = parameterTypes; 101 this.parameters = new ParameterInfoImpl[parameterTypes.length]; 102 for (int i = 0; i < parameterTypes.length; ++i) 103 this.parameters[i] = new ParameterInfoImpl(parameterAnnotations[i], null, parameterTypes[i]); 104 } 105 if (exceptionTypes == null) 106 this.exceptionTypes = MethodInfo.NO_EXCEPTIONS; 107 else 108 this.exceptionTypes = exceptionTypes; 109 this.modifiers = modifiers; 110 this.declaringClass = declaring; 111 this.returnType = returnType; 112 calculateHash(); 113 } 114 115 126 public MethodInfoImpl(AnnotationValue[] annotations, String name, TypeInfo returnType, ParameterInfo[] parameters, ClassInfo[] exceptionTypes, int modifiers, ClassInfo declaring) 127 { 128 super(annotations); 129 this.name = name; 130 if (parameters == null || parameters.length == 0) 131 { 132 this.parameterTypes = MethodInfo.NO_PARAMS_TYPES; 133 this.parameters = MethodInfo.NO_PARAMS; 134 } 135 else 136 { 137 this.parameters = parameters; 138 this.parameterTypes = new TypeInfo[parameters.length]; 139 for (int i = 0; i < parameters.length; ++i) 140 this.parameterTypes[i] = parameters[i].getParameterType(); 141 } 142 if (exceptionTypes == null || exceptionTypes.length == 0) 143 this.exceptionTypes = MethodInfo.NO_EXCEPTIONS; 144 else 145 this.exceptionTypes = exceptionTypes; 146 this.modifiers = modifiers; 147 this.declaringClass = declaring; 148 this.returnType = returnType; 149 calculateHash(); 150 } 151 152 public String getName() 153 { 154 return name; 155 } 156 157 public ClassInfo getDeclaringClass() 158 { 159 return declaringClass; 160 } 161 162 public TypeInfo[] getParameterTypes() 163 { 164 return parameterTypes; 165 } 166 167 public ParameterInfo[] getParameters() 168 { 169 return parameters; 170 } 171 172 public ClassInfo[] getExceptionTypes() 173 { 174 return exceptionTypes; 175 } 176 177 public TypeInfo getReturnType() 178 { 179 return returnType; 180 } 181 182 public int getModifiers() 183 { 184 return modifiers; 185 } 186 187 public boolean isStatic() 188 { 189 return Modifier.isStatic(modifiers); 190 } 191 192 public boolean isPublic() 193 { 194 return Modifier.isPublic(modifiers); 195 } 196 197 public Object invoke(Object target, Object [] args) throws Throwable 198 { 199 throw new NotImplementedException("invoke"); 200 } 201 202 protected void toString(JBossStringBuilder buffer) 203 { 204 buffer.append("name=").append(name); 205 buffer.append(Arrays.asList(parameterTypes)); 206 buffer.append(" return=").append(returnType); 207 } 208 209 public void toShortString(JBossStringBuilder buffer) 210 { 211 buffer.append(name); 212 } 213 214 public boolean equals(Object obj) 215 { 216 if (this == obj) return true; 217 if (obj == null || obj instanceof MethodInfo == false) 218 return false; 219 220 final MethodInfo other = (MethodInfo) obj; 221 222 if (name.equals(other.getName()) == false) 223 return false; 224 if (declaringClass.equals(other.getDeclaringClass()) == false) 225 return false; 226 if (returnType.equals(other.getReturnType()) == false) 227 return false; 228 return Arrays.equals(parameterTypes, other.getParameterTypes()); 229 } 230 231 public int hashCode() 232 { 233 return hash; 234 } 235 236 239 protected void calculateHash() 240 { 241 hash = name.hashCode(); 242 } 243 } 244 | Popular Tags |