7 Replies Latest reply on Jun 10, 2009 11:52 AM by alesj

    DeclaredMethodSignature for annotation handling

    jaikiran

      While scanning for annotations, the CommonAnnotationAdapter does this:

      1) CommonAnnotationAdapter for each MethodInfo creates a MethodSignature. The MethodInfo has the method name, the params and even the declaring class. However the MethodSignature can hold information only about the name and the params but not the declaring.

      2) The CommonAnnotaionAdapter then passes this MethodSignature to AnnotatedElementMetadataLoader.getComponentMetaDataRetrieval.

      3) Since the MethodSignature does not have information about the declaring class, this call ultimately leads to a ReflectionUtils which first gets all declared methods in the class hierarchy and then does method comparison to find the right method.

      Effectively, even though we have enough information about which method on which class to look for, we have ended up losing that information in the call hierarchy.

      Instead, if the CommonAnnotationAdapter created a DeclaredMethodSignature which has the ability to hold the declaring class, all the additional reflection logic can be reduced a lot. So:

      Index: src/main/java/org/jboss/kernel/plugins/annotations/CommonAnnotationAdapter.java
      ===================================================================
      --- src/main/java/org/jboss/kernel/plugins/annotations/CommonAnnotationAdapter.java (revision 89526)
      +++ src/main/java/org/jboss/kernel/plugins/annotations/CommonAnnotationAdapter.java (working copy)
      @@ -41,6 +41,7 @@
       import org.jboss.logging.Logger;
       import org.jboss.metadata.spi.MetaData;
       import org.jboss.metadata.spi.signature.ConstructorSignature;
      +import org.jboss.metadata.spi.signature.DeclaredMethodSignature;
       import org.jboss.metadata.spi.signature.FieldSignature;
       import org.jboss.metadata.spi.signature.MethodSignature;
       import org.jboss.metadata.spi.signature.Signature;
      @@ -341,7 +342,7 @@
       // direct == check is OK
       if (declaringCI != objectTI && visitedMethods.contains(mi) == false)
       {
      - Signature mis = new MethodSignature(mi);
      + Signature mis = new DeclaredMethodSignature(mi);
       MetaData cmdr = retrieval.getComponentMetaData(mis);
       if (cmdr != null)
       {
      


      can be helpful (note that there are some other places within that class which need similar change - the above is just an example).

      Additionally, the AnnotatedElementMetadataLoader too needs a minor change to use a simpler API in jboss-reflect whose implementation does *not* scan for all methods when it can just do a class.getDeclaredMethod(name,params):

      else if (signature instanceof DeclaredMethodSignature)
       {
       DeclaredMethodSignature methodSignature = (DeclaredMethodSignature) signature;
       Method method = methodSignature.getMethod();
       if (method == null)
       {
       clazz = getDeclaringClass(clazz, methodSignature.getDeclaringClass());
       if (clazz == null)
       return null;
       // Jaikiran: This needs change too, since ultimately this calls leads to jboss-reflect which
       // first gets all declared methods and then starts iterating over them to match the correct one.
       // Instead there should be a new API like findDeclaredMethod
       method = SecurityActions.findMethod(clazz, signature.getName(), signature.getParametersTypes(clazz));
      



      Any thoughts on this?

      P.S: The same could apply to fields (i.e. DeclaredFieldSignature instead of FieldSignature), but i don't see any DeclaredFieldSignature available. Any reason why this isn't available?