Example #1
0
 /** Find the value for an annotation */
 private Object getElementValue(String name, Class<?> valueType) {
   for (AnnotationMember evp : elementValuePairs) {
     String evpFieldName = evp.getName().toString();
     if (name.equals(evpFieldName)) {
       return evp.getValue();
     }
   }
   MethodReference methRef =
       MemberReference.findOrCreate(
               type,
               Atom.findOrCreateAsciiAtom(name),
               Atom.findOrCreateAsciiAtom("()" + TypeReference.findOrCreate(valueType).getName()))
           .asMethodReference();
   try {
     return methRef.resolve().getAnnotationDefault();
   } catch (Throwable t) {
     return NO_VALUE;
   }
 }
Example #2
0
 /** Ordering for sorted annotation members */
 public int compareTo(AnnotationMember am) {
   if (am.meth != this.meth) {
     return am.getName().toString().compareTo(this.getName().toString());
   } else {
     if (value.getClass().isArray()) {
       return Arrays.hashCode((Object[]) value) - Arrays.hashCode((Object[]) am.value);
     } else {
       @SuppressWarnings("unchecked") // True generic programming, we can't type check it in Java
       Comparable<Object> cValue = (Comparable) value;
       return cValue.compareTo(am.value);
     }
   }
 }
Example #3
0
 /**
  * Read an annotation attribute from the class file
  *
  * @param constantPool from constant pool being loaded
  * @param input the data being read
  */
 static RVMAnnotation readAnnotation(
     int[] constantPool, DataInputStream input, ClassLoader classLoader)
     throws IOException, ClassNotFoundException {
   TypeReference type;
   // Read type
   int typeIndex = input.readUnsignedShort();
   type = TypeReference.findOrCreate(classLoader, RVMClass.getUtf(constantPool, typeIndex));
   // Read values
   int numAnnotationMembers = input.readUnsignedShort();
   AnnotationMember[] elementValuePairs = new AnnotationMember[numAnnotationMembers];
   for (int i = 0; i < numAnnotationMembers; i++) {
     elementValuePairs[i] =
         AnnotationMember.readAnnotationMember(type, constantPool, input, classLoader);
   }
   // Arrays.sort(elementValuePairs);
   RVMAnnotation result = new RVMAnnotation(type, elementValuePairs);
   RVMAnnotation unique = uniqueMap.get(result);
   if (unique != null) {
     return unique;
   } else {
     uniqueMap.put(result, result);
     return result;
   }
 }