/** Are two annotations equal? */ private boolean annotationEquals(Annotation a, Annotation b) { if (a == b) { return true; } else if (a.getClass() != b.getClass()) { return false; } else { RVMClass annotationInterface = type.resolve().asClass(); RVMMethod[] annotationMethods = annotationInterface.getDeclaredMethods(); AnnotationFactory afB = (AnnotationFactory) Proxy.getInvocationHandler(b); try { for (RVMMethod method : annotationMethods) { String name = method.getName().toUnicodeString(); Object objA = getElementValue(name, method.getReturnType().resolve().getClassForType()); Object objB = afB.getValue(name, method.getReturnType().resolve().getClassForType()); if (!objA.getClass().isArray()) { if (!objA.equals(objB)) { return false; } } else { if (!Arrays.equals((Object[]) objA, (Object[]) objB)) { return false; } } } } catch (java.io.UTFDataFormatException e) { throw new Error(e); } return true; } }
/** * Return a string representation of the annotation of the form "@type(name1=val1, ...nameN=valN)" */ public String toString() { RVMClass annotationInterface = type.resolve().asClass(); RVMMethod[] annotationMethods = annotationInterface.getDeclaredMethods(); String result = "@" + type.resolve().getClassForType().getName() + "("; try { for (int i = 0; i < annotationMethods.length; i++) { String name = annotationMethods[i].getName().toUnicodeString(); Object value = getElementValue(name, annotationMethods[i].getReturnType().resolve().getClassForType()); result += elementString(name, value); if (i < (annotationMethods.length - 1)) { result += ", "; } } } catch (java.io.UTFDataFormatException e) { throw new Error(e); } result += ")"; return result; }
/** Hash code for annotation value */ private int annotationHashCode() { RVMClass annotationInterface = type.resolve().asClass(); RVMMethod[] annotationMethods = annotationInterface.getDeclaredMethods(); String typeString = type.toString(); int result = typeString.substring(1, typeString.length() - 1).hashCode(); try { for (RVMMethod method : annotationMethods) { String name = method.getName().toUnicodeString(); Object value = getElementValue(name, method.getReturnType().resolve().getClassForType()); int part_result = name.hashCode() * 127; if (value.getClass().isArray()) { if (value instanceof Object[]) { part_result ^= Arrays.hashCode((Object[]) value); } else if (value instanceof boolean[]) { part_result ^= Arrays.hashCode((boolean[]) value); } else if (value instanceof byte[]) { part_result ^= Arrays.hashCode((byte[]) value); } else if (value instanceof char[]) { part_result ^= Arrays.hashCode((char[]) value); } else if (value instanceof short[]) { part_result ^= Arrays.hashCode((short[]) value); } else if (value instanceof int[]) { part_result ^= Arrays.hashCode((int[]) value); } else if (value instanceof long[]) { part_result ^= Arrays.hashCode((long[]) value); } else if (value instanceof float[]) { part_result ^= Arrays.hashCode((float[]) value); } else if (value instanceof double[]) { part_result ^= Arrays.hashCode((double[]) value); } } else { part_result ^= value.hashCode(); } result += part_result; } } catch (java.io.UTFDataFormatException e) { throw new Error(e); } return result; }