示例#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;
   }
 }
示例#2
0
 /**
  * Read the pair from the input stream and create object
  *
  * @param constantPool the constant pool for the class being read
  * @param input stream to read from
  * @param classLoader the class loader being used to load this annotation
  * @return a newly created annotation member
  */
 static AnnotationMember readAnnotationMember(
     TypeReference type, int[] constantPool, DataInputStream input, ClassLoader classLoader)
     throws IOException, ClassNotFoundException {
   // Read name of pair
   int elemNameIndex = input.readUnsignedShort();
   Atom name = RVMClass.getUtf(constantPool, elemNameIndex);
   MethodReference meth;
   Object value;
   if (type.isResolved()) {
     meth = type.resolve().asClass().findDeclaredMethod(name).getMemberRef().asMethodReference();
     value = RVMAnnotation.readValue(meth.getReturnType(), constantPool, input, classLoader);
   } else {
     value = RVMAnnotation.readValue(null, constantPool, input, classLoader);
     meth =
         MemberReference.findOrCreate(
                 type,
                 name,
                 Atom.findOrCreateAsciiAtom(
                     "()" + TypeReference.findOrCreate(value.getClass()).getName()))
             .asMethodReference();
   }
   return new AnnotationMember(meth, value);
 }