]> source.dussan.org Git - aspectj.git/commitdiff
superinterface cache
authoraclement <aclement>
Fri, 13 Nov 2009 18:28:15 +0000 (18:28 +0000)
committeraclement <aclement>
Fri, 13 Nov 2009 18:28:15 +0000 (18:28 +0000)
weaver/src/org/aspectj/weaver/bcel/BcelObjectType.java

index 9bb4cb26613df927b6f21e48ff8db047a5cedb0c..60a1a54495ebea17a78c6bf250c68dc76d2e42d8 100644 (file)
@@ -110,6 +110,7 @@ public class BcelObjectType extends AbstractReferenceTypeDelegate {
        // above!
 
        private WeakReference<ResolvedType> superTypeReference = new WeakReference<ResolvedType>(null);
+       private WeakReference<ResolvedType[]> superInterfaceReferences = new WeakReference<ResolvedType[]>(null);
 
        private int bitflag = 0x0000;
 
@@ -134,7 +135,6 @@ public class BcelObjectType extends AbstractReferenceTypeDelegate {
         * that's a bigger piece of work. XXX
         */
 
-       // ------------------ construction and initialization
        BcelObjectType(ReferenceType resolvedTypeX, JavaClass javaClass, boolean exposedToWeaver) {
                super(resolvedTypeX, exposedToWeaver);
                this.javaClass = javaClass;
@@ -169,6 +169,11 @@ public class BcelObjectType extends AbstractReferenceTypeDelegate {
                initializeFromJavaclass();
        }
 
+       @Override
+       public boolean isCacheable() {
+               return true;
+       }
+
        private void initializeFromJavaclass() {
                isInterface = javaClass.isInterface();
                isEnum = javaClass.isEnum();
@@ -240,29 +245,35 @@ public class BcelObjectType extends AbstractReferenceTypeDelegate {
         * is used to work out the types - this gets around the results of erasure when the class was originally compiled.
         */
        public ResolvedType[] getDeclaredInterfaces() {
-               ensureGenericSignatureUnpacked();
-               ResolvedType[] interfaceTypes = null;
-               if (interfaceSignatures == null) {
-                       String[] names = javaClass.getInterfaceNames();
-                       if (names.length == 0) {
-                               interfaceSignatures = NO_INTERFACE_SIGS;
-                               interfaceTypes = ResolvedType.NONE;
+
+               ResolvedType[] cachedInterfaceTypes = superInterfaceReferences.get();
+               if (cachedInterfaceTypes == null) {
+                       ensureGenericSignatureUnpacked();
+                       ResolvedType[] interfaceTypes = null;
+                       if (interfaceSignatures == null) {
+                               String[] names = javaClass.getInterfaceNames();
+                               if (names.length == 0) {
+                                       interfaceSignatures = NO_INTERFACE_SIGS;
+                                       interfaceTypes = ResolvedType.NONE;
+                               } else {
+                                       interfaceSignatures = new String[names.length];
+                                       interfaceTypes = new ResolvedType[names.length];
+                                       for (int i = 0, len = names.length; i < len; i++) {
+                                               interfaceTypes[i] = getResolvedTypeX().getWorld().resolve(UnresolvedType.forName(names[i]));
+                                               interfaceSignatures[i] = interfaceTypes[i].getSignature();
+                                       }
+                               }
                        } else {
-                               interfaceSignatures = new String[names.length];
-                               interfaceTypes = new ResolvedType[names.length];
-                               for (int i = 0, len = names.length; i < len; i++) {
-                                       interfaceTypes[i] = getResolvedTypeX().getWorld().resolve(UnresolvedType.forName(names[i]));
-                                       interfaceSignatures[i] = interfaceTypes[i].getSignature();
+                               interfaceTypes = new ResolvedType[interfaceSignatures.length];
+                               for (int i = 0, len = interfaceSignatures.length; i < len; i++) {
+                                       interfaceTypes[i] = getResolvedTypeX().getWorld().resolve(UnresolvedType.forSignature(interfaceSignatures[i]));
                                }
                        }
+                       superInterfaceReferences = new WeakReference<ResolvedType[]>(interfaceTypes);
+                       return interfaceTypes;
                } else {
-                       interfaceTypes = new ResolvedType[interfaceSignatures.length];
-                       for (int i = 0, len = interfaceSignatures.length; i < len; i++) {
-                               interfaceTypes[i] = getResolvedTypeX().getWorld().resolve(UnresolvedType.forSignature(interfaceSignatures[i]));
-                       }
+                       return cachedInterfaceTypes;
                }
-
-               return interfaceTypes;
        }
 
        public ResolvedMember[] getDeclaredMethods() {