]> source.dussan.org Git - aspectj.git/commitdiff
258510: promoted additional annotation/class/interface storage from delegate to refer...
authoraclement <aclement>
Tue, 20 Jan 2009 22:41:25 +0000 (22:41 +0000)
committeraclement <aclement>
Tue, 20 Jan 2009 22:41:25 +0000 (22:41 +0000)
weaver/src/org/aspectj/weaver/bcel/BcelObjectType.java
weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java
weaver/src/org/aspectj/weaver/bcel/BcelWeaver.java
weaver/src/org/aspectj/weaver/bcel/BcelWorld.java
weaver/src/org/aspectj/weaver/bcel/LazyClassGen.java

index e267ffb2ed5d0e215d525d952c5ab4ad0dbd22ab..a02b6e19a261d5246b1fc163045b1127e39a14db 100644 (file)
@@ -113,7 +113,6 @@ public class BcelObjectType extends AbstractReferenceTypeDelegate {
        private static final int DISCOVERED_ANNOTATION_TARGET_KINDS = 0x0008;
        private static final int DISCOVERED_DECLARED_SIGNATURE = 0x0010;
        private static final int DISCOVERED_WHETHER_ANNOTATION_STYLE = 0x0020;
-       private static final int DAMAGED = 0x0040; // see note(2) below
 
        private static final String[] NO_INTERFACE_SIGS = new String[] {};
 
@@ -453,12 +452,6 @@ public class BcelObjectType extends AbstractReferenceTypeDelegate {
                return javaClass;
        }
 
-       public void ensureDelegateConsistent() {
-               if ((bitflag & DAMAGED) != 0) {
-                       resetState();
-               }
-       }
-
        public void resetState() {
                if (javaClass == null) {
                        // we might store the classname and allow reloading?
@@ -545,36 +538,6 @@ public class BcelObjectType extends AbstractReferenceTypeDelegate {
                return wvInfo;
        }
 
-       public void addParent(ResolvedType newParent) {
-               bitflag |= DAMAGED;
-               if (newParent.isClass()) {
-                       superclassSignature = newParent.getSignature();
-                       superclassName = newParent.getName();
-                       // superClass = newParent;
-               } else {
-                       ResolvedType[] oldInterfaceNames = getDeclaredInterfaces();
-                       int exists = -1;
-                       for (int i = 0; i < oldInterfaceNames.length; i++) {
-                               ResolvedType type = oldInterfaceNames[i];
-                               if (type.equals(newParent)) {
-                                       exists = i;
-                                       break;
-                               }
-                       }
-                       if (exists == -1) {
-
-                               int len = interfaceSignatures.length;
-                               String[] newInterfaceSignatures = new String[len + 1];
-                               System.arraycopy(interfaceSignatures, 0, newInterfaceSignatures, 0, len);
-                               newInterfaceSignatures[len] = newParent.getSignature();
-                               interfaceSignatures = newInterfaceSignatures;
-                       }
-               }
-               // System.err.println("javaClass: " +
-               // Arrays.asList(javaClass.getInterfaceNames()) + " super " +
-               // superclassName);
-               // if (lazyClassGen != null) lazyClassGen.print();
-       }
 
        // -- annotation related
 
@@ -598,21 +561,6 @@ public class BcelObjectType extends AbstractReferenceTypeDelegate {
                return false;
        }
 
-       // evil mutator - adding state not stored in the java class
-       public void addAnnotation(AnnotationAJ annotation) {
-               bitflag |= DAMAGED;
-               int len = annotations.length;
-               AnnotationAJ[] ret = new AnnotationAJ[len + 1];
-               System.arraycopy(annotations, 0, ret, 0, len);
-               ret[len] = annotation;
-               annotations = ret;
-
-               len = annotationTypes.length;
-               ResolvedType[] ret2 = new ResolvedType[len + 1];
-               System.arraycopy(annotationTypes, 0, ret2, 0, len);
-               ret2[len] = getResolvedTypeX().getWorld().resolve(UnresolvedType.forName(annotation.getTypeName()));
-               annotationTypes = ret2;
-       }
 
        public boolean isAnnotationWithRuntimeRetention() {
                return (getRetentionPolicy() == null ? false : getRetentionPolicy().equals("RUNTIME"));
@@ -895,48 +843,6 @@ public class BcelObjectType extends AbstractReferenceTypeDelegate {
                        getSourceContext().tidy();
        }
 
-       // --- methods for testing
-
-       // for testing - if we have this attribute, return it - will return null if
-       // it doesnt know anything
-       // public AjAttribute[] getAttributes(String name) {
-       // List results = new ArrayList();
-       // List l =
-       // BcelAttributes.readAjAttributes(javaClass.getClassName(),javaClass
-       // .getAttributes(),
-       // getResolvedTypeX().getSourceContext(),getResolvedTypeX().getWorld(),
-       // AjAttribute.WeaverVersionInfo.UNKNOWN);
-       // for (Iterator iter = l.iterator(); iter.hasNext();) {
-       // AjAttribute element = (AjAttribute) iter.next();
-       // if (element.getNameString().equals(name)) results.add(element);
-       // }
-       // if (results.size()>0) {
-       // return (AjAttribute[])results.toArray(new AjAttribute[]{});
-       // }
-       // return null;
-       // }
-       //      
-       // // for testing - use with the method above - this returns *all* including
-       // those that are not Aj attributes
-       // public String[] getAttributeNames() {
-       // Attribute[] as = javaClass.getAttributes();
-       // String[] strs = new String[as.length];
-       // for (int j = 0; j < as.length; j++) {
-       // strs[j] = as[j].getName();
-       // }
-       // return strs;
-       // }
-
-       // for testing
-       public void addPointcutDefinition(ResolvedPointcutDefinition d) {
-               bitflag |= DAMAGED;
-               int len = pointcuts.length;
-               ResolvedPointcutDefinition[] ret = new ResolvedPointcutDefinition[len + 1];
-               System.arraycopy(pointcuts, 0, ret, 0, len);
-               ret[len] = d;
-               pointcuts = ret;
-       }
-
        public boolean hasBeenWoven() {
                return hasBeenWoven;
        }
index d34571af20c164bdb651fcb48d1f52c07456604d..3a50e7c763053562563b6f8a75b0132ad9694145 100644 (file)
@@ -441,7 +441,7 @@ public class BcelTypeMunger extends ConcreteTypeMunger {
         * The main part of implementing declare parents extends. Modify super ctor calls to target the new type.
         */
        public boolean attemptToModifySuperCalls(BcelClassWeaver weaver, LazyClassGen newParentTarget, ResolvedType newParent) {
-               String currentParent = newParentTarget.getSuperClassname();
+               String currentParent = newParentTarget.getSuperClass().getName();// getName();
                if (newParent.getGenericType() != null)
                        newParent = newParent.getGenericType(); // target new super calls at
                // the generic type if its
@@ -692,7 +692,7 @@ public class BcelTypeMunger extends ConcreteTypeMunger {
 
                        gen.addMethodGen(mg1);
 
-                       gen.addInterface(munger.getInterfaceType(), getSourceLocation());
+                       gen.addInterface(munger.getInterfaceType().resolve(weaver.getWorld()), getSourceLocation());
 
                        return true;
                } else {
index 52ecf1336684cfe6795a133e535a498cd7ac3d03..f207dd1d7f8400aad2d2cae58822c4dfca08ada9 100644 (file)
@@ -1128,9 +1128,7 @@ public class BcelWeaver {
                        String className = classFile.getClassName();
                        ResolvedType theType = world.resolve(className);
                        if (theType != null) {
-                               BcelObjectType classType = BcelWorld.getBcelObjectType(theType);
-                               if (classType != null)
-                                       classType.ensureDelegateConsistent();
+                               theType.ensureConsistent();
                        }
                }
 
@@ -1672,7 +1670,8 @@ public class BcelWeaver {
                                // itself
                                // (like transform super calls) - that is done in
                                // BcelTypeMunger.mungeNewParent()
-                               classType.addParent(newParent);
+                               // classType.addParent(newParent);
+                               onType.addParent(newParent);
                                ResolvedTypeMunger newParentMunger = new NewParentTypeMunger(newParent);
                                newParentMunger.setSourceLocation(p.getSourceLocation());
                                onType.addInterTypeMunger(new BcelTypeMunger(newParentMunger, xcutSet.findAspectDeclaringParents(p)));
index 47f15a22cffa1705e713c37b6657f4eea423e59c..1ed1ca608acd6f5dc09fbb873691d197d6ac3bb9 100644 (file)
@@ -613,7 +613,8 @@ public class BcelWorld extends World implements Repository {
                if (!result.isExposedToWeaver())
                        return; // cant need resetting
                ReferenceType rt = (ReferenceType) result;
-               rt.getDelegate().ensureDelegateConsistent();
+               rt.ensureConsistent();
+               // rt.getDelegate().ensureDelegateConsistent();
                // If we want to rebuild it 'from scratch' then:
                // ClassParser cp = new ClassParser(new
                // ByteArrayInputStream(newbytes),new String(cs));
@@ -645,7 +646,8 @@ public class BcelWorld extends World implements Repository {
                                // itself
                                // (like transform super calls) - that is done in
                                // BcelTypeMunger.mungeNewParent()
-                               classType.addParent(newParent);
+                               // classType.addParent(newParent);
+                               onType.addParent(newParent);
                                ResolvedTypeMunger newParentMunger = new NewParentTypeMunger(newParent);
                                newParentMunger.setSourceLocation(p.getSourceLocation());
                                onType.addInterTypeMunger(new BcelTypeMunger(newParentMunger, getCrosscuttingMembersSet()
index 14c82f50bb380f6a88406dec8afa92b593aa8076..e4e8cdf793123a65195a1fbaa65f2a2392d0398b 100644 (file)
@@ -105,6 +105,9 @@ public final class LazyClassGen {
        private long calculatedSerialVersionUID;
        private boolean hasClinit = false;
 
+       private ResolvedType[] extraSuperInterfaces = null;
+       private ResolvedType superclass = null;
+
        // ---
 
        static class InlinedSourceFileInfo {
@@ -504,25 +507,35 @@ public final class LazyClassGen {
        }
 
        /**
-        * When working with 1.5 generics, a signature attribute is attached to the type which indicates how it was declared. This
-        * routine ensures the signature attribute for what we are about to write out is correct. Basically its responsibilities are: 1.
-        * Checking whether the attribute needs changing (i.e. did weaving change the type hierarchy) 2. If it did, removing the old
-        * attribute 3. Check if we need an attribute at all, are we generic? are our supertypes parameterized/generic? 4. Build the new
-        * attribute which includes all typevariable, supertype and superinterface information
+        * When working with Java generics, a signature attribute is attached to the type which indicates how it was declared. This
+        * routine ensures the signature attribute for the class we are about to write out is correct. Basically its responsibilities
+        * are:
+        * <ol>
+        * <li>
+        * Checking whether the attribute needs changing (ie. did weaving change the type hierarchy) - if it did, remove the old
+        * attribute
+        * <li>
+        * Check if we need an attribute at all, are we generic? are our supertypes parameterized/generic?
+        * <li>
+        * Build the new attribute which includes all typevariable, supertype and superinterface information
+        * </ol>
         */
        private void fixupGenericSignatureAttribute() {
 
-               if (getWorld() != null && !getWorld().isInJava5Mode())
+               if (getWorld() != null && !getWorld().isInJava5Mode()) {
                        return;
+               }
 
                // TODO asc generics Temporarily assume that types we generate dont need a signature attribute (closure/etc).. will need
                // revisiting no doubt...
-               if (myType == null)
+               if (myType == null) {
                        return;
+               }
 
                // 1. Has anything changed that would require us to modify this attribute?
-               if (!regenerateGenericSignatureAttribute)
+               if (!regenerateGenericSignatureAttribute) {
                        return;
+               }
 
                // 2. Find the old attribute
                Signature sigAttr = null;
@@ -544,9 +557,16 @@ public final class LazyClassGen {
                                if (typeX.isGenericType() || typeX.isParameterizedType())
                                        needAttribute = true;
                        }
+                       if (extraSuperInterfaces != null) {
+                               for (int i = 0; i < extraSuperInterfaces.length; i++) {
+                                       ResolvedType interfaceType = extraSuperInterfaces[i];
+                                       if (interfaceType.isGenericType() || interfaceType.isParameterizedType())
+                                               needAttribute = true;
+                               }
+                       }
 
                        // check the supertype
-                       ResolvedType superclassRTX = myType.getSuperclass();
+                       ResolvedType superclassRTX = getSuperClass();
                        if (superclassRTX.isGenericType() || superclassRTX.isParameterizedType())
                                needAttribute = true;
                }
@@ -564,15 +584,22 @@ public final class LazyClassGen {
                                signature.append(">");
                        }
                        // now the supertype
-                       String supersig = myType.getSuperclass().getSignatureForAttribute();
+                       String supersig = getSuperClass().getSignatureForAttribute();
                        signature.append(supersig);
                        ResolvedType[] interfaceRTXs = myType.getDeclaredInterfaces();
                        for (int i = 0; i < interfaceRTXs.length; i++) {
                                String s = interfaceRTXs[i].getSignatureForAttribute();
                                signature.append(s);
                        }
-                       if (sigAttr != null)
+                       if (extraSuperInterfaces != null) {
+                               for (int i = 0; i < extraSuperInterfaces.length; i++) {
+                                       String s = extraSuperInterfaces[i].getSignatureForAttribute();
+                                       signature.append(s);
+                               }
+                       }
+                       if (sigAttr != null) {
                                myGen.removeAttribute(sigAttr);
+                       }
                        myGen.addAttribute(createSignatureAttribute(signature.toString()));
                }
        }
@@ -632,27 +659,41 @@ public final class LazyClassGen {
                classGens.add(newClass);
        }
 
-       public void addInterface(UnresolvedType typeX, ISourceLocation sourceLocation) {
+       public void addInterface(ResolvedType newInterface, ISourceLocation sourceLocation) {
                regenerateGenericSignatureAttribute = true;
-               myGen.addInterface(typeX.getRawName());
-               if (!typeX.equals(UnresolvedType.SERIALIZABLE))
-                       warnOnAddedInterface(typeX.getName(), sourceLocation);
+
+               if (extraSuperInterfaces == null) {
+                       extraSuperInterfaces = new ResolvedType[1];
+                       extraSuperInterfaces[0] = newInterface;
+               } else {
+                       ResolvedType[] x = new ResolvedType[extraSuperInterfaces.length + 1];
+                       System.arraycopy(extraSuperInterfaces, 0, x, 1, extraSuperInterfaces.length);
+                       x[0] = newInterface;
+                       extraSuperInterfaces = x;
+               }
+               myGen.addInterface(newInterface.getRawName());
+               if (!newInterface.equals(UnresolvedType.SERIALIZABLE))
+                       warnOnAddedInterface(newInterface.getName(), sourceLocation);
        }
 
-       public void setSuperClass(ResolvedType typeX) {
+       public void setSuperClass(ResolvedType newSuperclass) {
                regenerateGenericSignatureAttribute = true;
-               myType.addParent(typeX); // used for the attribute
-               if (typeX.getGenericType() != null)
-                       typeX = typeX.getGenericType();
-               myGen.setSuperclassName(typeX.getName()); // used in the real class data
+               superclass = newSuperclass;
+               // myType.addParent(typeX); // used for the attribute
+               if (newSuperclass.getGenericType() != null) {
+                       newSuperclass = newSuperclass.getGenericType();
+               }
+               myGen.setSuperclassName(newSuperclass.getName()); // used in the real class data
        }
 
-       public String getSuperClassname() {
-               return myGen.getSuperclassName();
-       }
+       // public String getSuperClassname() {
+       // return myGen.getSuperclassName();
+       // }
 
-       // FIXME asc not great that some of these ask the gen and some ask the type ! (see the related setters too)
        public ResolvedType getSuperClass() {
+               if (superclass != null) {
+                       return superclass;
+               }
                return myType.getSuperclass();
        }
 
@@ -665,7 +706,6 @@ public final class LazyClassGen {
                List ret = new ArrayList();
                ret.add(this);
                ret.addAll(classGens);
-
                return ret;
        }