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.ConstructorInfo; 30 import org.jboss.reflect.spi.MethodInfo; 31 import org.jboss.reflect.spi.ParameterInfo; 32 import org.jboss.reflect.spi.TypeInfo; 33 import org.jboss.util.JBossStringBuilder; 34 import org.jboss.util.NotImplementedException; 35 36 42 public class ConstructorInfoImpl extends AnnotationHolder implements ConstructorInfo 43 { 44 45 private static final long serialVersionUID = 3256727273163272758L; 46 47 48 protected ClassInfo declaringClass; 49 50 51 protected TypeInfo[] parameterTypes; 52 53 54 protected ParameterInfo[] parameters; 55 56 57 protected ClassInfo[] exceptionTypes; 58 59 60 protected int modifiers; 61 62 63 protected int hash; 64 65 68 public ConstructorInfoImpl() 69 { 70 } 71 72 82 public ConstructorInfoImpl(AnnotationValue[] annotations, TypeInfo[] parameterTypes, AnnotationValue[][] parameterAnnotations, ClassInfo[] exceptionTypes, int modifiers, ClassInfo declaring) 83 { 84 super(annotations); 85 if (parameterTypes == null) 86 { 87 this.parameterTypes = MethodInfo.NO_PARAMS_TYPES; 88 this.parameters = MethodInfo.NO_PARAMS; 89 } 90 else 91 { 92 this.parameterTypes = parameterTypes; 93 this.parameters = new ParameterInfoImpl[parameterTypes.length]; 94 for (int i = 0; i < parameterTypes.length; ++i) 95 this.parameters[i] = new ParameterInfoImpl(parameterAnnotations[i], null, parameterTypes[i]); 96 } 97 if (exceptionTypes == null) 98 this.exceptionTypes = MethodInfo.NO_EXCEPTIONS; 99 else 100 this.exceptionTypes = exceptionTypes; 101 this.modifiers = modifiers; 102 this.declaringClass = declaring; 103 calculateHash(); 104 } 105 106 115 public ConstructorInfoImpl(AnnotationValue[] annotations, ParameterInfo[] parameters, ClassInfo[] exceptionTypes, int modifiers, ClassInfo declaring) 116 { 117 super(annotations); 118 if (parameters == null || parameters.length == 0) 119 { 120 this.parameterTypes = MethodInfo.NO_PARAMS_TYPES; 121 this.parameters = MethodInfo.NO_PARAMS; 122 } 123 else 124 { 125 this.parameters = parameters; 126 this.parameterTypes = new TypeInfo[parameters.length]; 127 for (int i = 0; i < parameters.length; ++i) 128 this.parameterTypes[i] = parameters[i].getParameterType(); 129 } 130 if (exceptionTypes == null || exceptionTypes.length == 0) 131 this.exceptionTypes = MethodInfo.NO_EXCEPTIONS; 132 else 133 this.exceptionTypes = exceptionTypes; 134 this.modifiers = modifiers; 135 this.declaringClass = declaring; 136 calculateHash(); 137 } 138 139 public ClassInfo getDeclaringClass() 140 { 141 return declaringClass; 142 } 143 144 public TypeInfo[] getParameterTypes() 145 { 146 return parameterTypes; 147 } 148 149 public ParameterInfo[] getParameters() 150 { 151 return parameters; 152 } 153 154 public ClassInfo[] getExceptionTypes() 155 { 156 return exceptionTypes; 157 } 158 159 public int getModifiers() 160 { 161 return modifiers; 162 } 163 164 public boolean isStatic() 165 { 166 return Modifier.isStatic(modifiers); 167 } 168 169 public boolean isPublic() 170 { 171 return Modifier.isPublic(modifiers); 172 } 173 174 public Object newInstance(Object [] args) throws Throwable 175 { 176 throw new NotImplementedException("newInstance"); 177 } 178 179 protected void toString(JBossStringBuilder buffer) 180 { 181 buffer.append(Arrays.asList(parameterTypes)); 182 } 183 184 public boolean equals(Object obj) 185 { 186 if (this == obj) 187 return true; 188 if (obj == null || obj instanceof ConstructorInfo == false) 189 return false; 190 191 final ConstructorInfo other = (ConstructorInfo) obj; 192 193 if (declaringClass.equals(other.getDeclaringClass()) == false) 194 return false; 195 return (Arrays.equals(parameterTypes, other.getParameterTypes())); 196 } 197 198 public int hashCode() 199 { 200 return hash; 201 } 202 203 protected void calculateHash() 204 { 205 int result = declaringClass.hashCode(); 206 if (parameterTypes != null) 207 { 208 for (int i = 0; i < parameterTypes.length; i++) 209 { 210 result = 29 * result + parameterTypes[i].hashCode(); 211 } 212 } 213 hash = result; 214 } 215 } 216 | Popular Tags |