View Javadoc

1   /***************************************************************************************
2    * Copyright (c) Jonas BonŽr, Alexandre Vasseur. All rights reserved.                 *
3    * http://aspectwerkz.codehaus.org                                                    *
4    * ---------------------------------------------------------------------------------- *
5    * The software in this package is published under the terms of the LGPL license      *
6    * a copy of which has been included with this distribution in the license.txt file.  *
7    **************************************************************************************/
8   package org.codehaus.aspectwerkz.reflect.impl.asm;
9   
10  import org.codehaus.aspectwerkz.annotation.instrumentation.asm.CustomAttribute;
11  import org.codehaus.aspectwerkz.annotation.instrumentation.asm.CustomAttributeHelper;
12  import org.codehaus.aspectwerkz.annotation.AnnotationInfo;
13  import org.codehaus.aspectwerkz.reflect.ClassInfo;
14  import org.codehaus.aspectwerkz.reflect.MemberInfo;
15  import org.codehaus.aspectwerkz.transform.inlining.AsmHelper;
16  import org.objectweb.asm.Attribute;
17  import org.objectweb.asm.attrs.RuntimeInvisibleAnnotations;
18  import org.objectweb.asm.attrs.Annotation;
19  import org.objectweb.asm.attrs.RuntimeVisibleAnnotations;
20  
21  import java.lang.ref.WeakReference;
22  import java.util.*;
23  
24  /***
25   * ASM implementation of the MemberInfo interface.
26   *
27   * @author <a href="mailto:jboner@codehaus.org">Jonas BonŽr </a>
28   */
29  public abstract class AsmMemberInfo implements MemberInfo {
30  
31      /***
32       * The member info.
33       */
34      protected final MemberStruct m_member;
35  
36      /***
37       * The class loader wrapped in a weak ref.
38       */
39      protected final WeakReference m_loaderRef;
40  
41      /***
42       * The declaring type name.
43       */
44      protected final String m_declaringTypeName;
45  
46      /***
47       * The declaring type.
48       */
49      protected ClassInfo m_declaringType;
50  
51      /***
52       * The annotations.
53       */
54      protected List m_annotations = null;
55  
56      /***
57       * The class info repository.
58       */
59      protected final AsmClassInfoRepository m_classInfoRepository;
60  
61      /***
62       * Creates a new member meta data instance.
63       *
64       * @param member
65       * @param declaringType
66       * @param loader
67       */
68      AsmMemberInfo(final MemberStruct member, final String declaringType, final ClassLoader loader) {
69          if (member == null) {
70              throw new IllegalArgumentException("member can not be null");
71          }
72          if (declaringType == null) {
73              throw new IllegalArgumentException("declaring type can not be null");
74          }
75          m_member = member;
76          m_loaderRef = new WeakReference(loader);
77          m_declaringTypeName = declaringType.replace('/', '.');
78          m_classInfoRepository = AsmClassInfoRepository.getRepository(loader);
79      }
80  
81      /***
82       * Returns the name.
83       *
84       * @return the name
85       */
86      public String getName() {
87          return m_member.name;
88      }
89  
90      /***
91       * Returns the modifiers.
92       *
93       * @return the modifiers
94       */
95      public int getModifiers() {
96          return m_member.modifiers;
97      }
98  
99      /***
100      * Returns the declaring type.
101      *
102      * @return the declaring type
103      */
104     public ClassInfo getDeclaringType() {
105         if (m_declaringType == null) {
106             m_declaringType = m_classInfoRepository.getClassInfo(m_declaringTypeName);
107         }
108         return m_declaringType;
109     }
110 }