]> source.dussan.org Git - aspectj.git/commitdiff
major refactoring - writeup to follow...
authoraclement <aclement>
Mon, 12 Feb 2007 09:34:27 +0000 (09:34 +0000)
committeraclement <aclement>
Mon, 12 Feb 2007 09:34:27 +0000 (09:34 +0000)
33 files changed:
weaver/src/org/aspectj/weaver/AbstractReferenceTypeDelegate.java
weaver/src/org/aspectj/weaver/AjAttribute.java
weaver/src/org/aspectj/weaver/AnnotationX.java
weaver/src/org/aspectj/weaver/AsmRelationshipProvider.java
weaver/src/org/aspectj/weaver/FakeAnnotation.java
weaver/src/org/aspectj/weaver/JoinPointSignature.java
weaver/src/org/aspectj/weaver/JoinPointSignatureIterator.java
weaver/src/org/aspectj/weaver/Member.java
weaver/src/org/aspectj/weaver/MemberImpl.java
weaver/src/org/aspectj/weaver/ResolvedMemberImpl.java
weaver/src/org/aspectj/weaver/SourceContextImpl.java
weaver/src/org/aspectj/weaver/UnresolvedType.java
weaver/src/org/aspectj/weaver/World.java
weaver/src/org/aspectj/weaver/bcel/AtAjAttributes.java
weaver/src/org/aspectj/weaver/bcel/BcelAccessForInlineMunger.java
weaver/src/org/aspectj/weaver/bcel/BcelAdvice.java
weaver/src/org/aspectj/weaver/bcel/BcelAttributes.java
weaver/src/org/aspectj/weaver/bcel/BcelCflowCounterFieldAdder.java
weaver/src/org/aspectj/weaver/bcel/BcelCflowStackFieldAdder.java
weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java
weaver/src/org/aspectj/weaver/bcel/BcelField.java
weaver/src/org/aspectj/weaver/bcel/BcelMethod.java
weaver/src/org/aspectj/weaver/bcel/BcelObjectType.java
weaver/src/org/aspectj/weaver/bcel/BcelPerClauseAspectAdder.java
weaver/src/org/aspectj/weaver/bcel/BcelShadow.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
weaver/src/org/aspectj/weaver/bcel/LazyMethodGen.java
weaver/src/org/aspectj/weaver/bcel/Range.java
weaver/src/org/aspectj/weaver/bcel/ShadowRange.java
weaver/src/org/aspectj/weaver/bcel/Utility.java

index 305dad5d0fe05b401dc6ca3f7734d951cb29eb48..ee6b7a057518f19d261246b546aa4d315abbc9c7 100644 (file)
@@ -258,6 +258,9 @@ public abstract class AbstractReferenceTypeDelegate implements ReferenceTypeDele
                                this.sourcefilename = pname.replace('.', '/') + '/' + sourceFileName;
                        }
                }
+               if (this.sourcefilename!=null && sourceContext instanceof SourceContextImpl) {
+                       ((SourceContextImpl)sourceContext).setSourceFileName(this.sourcefilename);
+               }
     }
     
        public ISourceLocation getSourceLocation() {
index a1fc5fcc4dd9d208906d24616da189c62fa9eb11..dd3fd932f99a32d6f1b58adfa7d4696f3f67e0ef 100644 (file)
@@ -222,6 +222,8 @@ public abstract class AjAttribute {
                
                public static final WeaverVersionInfo UNKNOWN = 
                        new WeaverVersionInfo(WEAVER_VERSION_MAJOR_UNKNOWN,WEAVER_VERSION_MINOR_UNKNOWN);
+               public static final WeaverVersionInfo CURRENT = 
+                       new WeaverVersionInfo(CURRENT_VERSION_MAJOR,CURRENT_VERSION_MINOR);
                
                // These are the versions read in from a particular class file.
                private short major_version; 
index 66a5eaff0ad7d674445126c2317c47c8aaf9fce5..4e3263d41408a2f5eb0ad017d64a1f0251351a98 100644 (file)
@@ -15,12 +15,12 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
 
-import org.aspectj.apache.bcel.classfile.annotation.Annotation;
-import org.aspectj.apache.bcel.classfile.annotation.ArrayElementValue;
-import org.aspectj.apache.bcel.classfile.annotation.ElementNameValuePair;
-import org.aspectj.apache.bcel.classfile.annotation.ElementValue;
-import org.aspectj.apache.bcel.classfile.annotation.EnumElementValue;
 import org.aspectj.apache.bcel.classfile.Utility;
+import org.aspectj.apache.bcel.classfile.annotation.AnnotationGen;
+import org.aspectj.apache.bcel.classfile.annotation.ArrayElementValueGen;
+import org.aspectj.apache.bcel.classfile.annotation.ElementNameValuePairGen;
+import org.aspectj.apache.bcel.classfile.annotation.ElementValueGen;
+import org.aspectj.apache.bcel.classfile.annotation.EnumElementValueGen;
 
 /**
  * AnnotationX instances are holders for an annotation from either Bcel or
@@ -31,7 +31,7 @@ public class AnnotationX {
        
   public static final AnnotationX[] NONE = new AnnotationX[0];
   
-  private Annotation theRealBcelAnnotation;
+  private AnnotationGen theRealBcelAnnotation;
   private AnnotationAJ theRealASMAnnotation;
   private int mode = -1;
   private final static int MODE_ASM = 1;
@@ -44,7 +44,7 @@ public class AnnotationX {
   private AnnotationX atTargetAnnotation          = null;
   private Set         supportedTargets            = null;
   
-  public AnnotationX(Annotation a,World world) {
+  public AnnotationX(AnnotationGen a,World world) {
        theRealBcelAnnotation = a;
        signature = UnresolvedType.forSignature(theRealBcelAnnotation.getTypeSignature()).resolve(world);
        mode = MODE_BCEL;
@@ -56,7 +56,7 @@ public class AnnotationX {
                mode= MODE_ASM;
   }
 
-  public Annotation getBcelAnnotation() {
+  public AnnotationGen getBcelAnnotation() {
        return theRealBcelAnnotation;
   }
   
@@ -168,11 +168,11 @@ public class AnnotationX {
          Set supportedTargets = new HashSet();
          if (mode==MODE_BCEL) {
            List values = getBcelAnnotation().getValues();
-               ElementNameValuePair envp = (ElementNameValuePair)values.get(0);
-               ArrayElementValue aev = (ArrayElementValue)envp.getValue();
-               ElementValue[] evs = aev.getElementValuesArray();
+               ElementNameValuePairGen envp = (ElementNameValuePairGen)values.get(0);
+               ArrayElementValueGen aev = (ArrayElementValueGen)envp.getValue();
+               ElementValueGen[] evs = aev.getElementValuesArray();
                for (int i = 0; i < evs.length; i++) {
-                       EnumElementValue ev = (EnumElementValue)evs[i];
+                       EnumElementValueGen ev = (EnumElementValueGen)evs[i];
                        supportedTargets.add(ev.getEnumValueString());
                }
          } else {
index e2bd4d09d064855cce09bc754090c6268386d81f..d90cb565a4ca93651a7fb87aac4e3a8a0e643ba5 100644 (file)
@@ -16,7 +16,6 @@ package org.aspectj.weaver;
 import java.util.Iterator;
 import java.util.List;
 
-import org.aspectj.apache.bcel.classfile.Field;
 import org.aspectj.apache.bcel.classfile.Method;
 import org.aspectj.apache.bcel.classfile.Utility;
 import org.aspectj.apache.bcel.generic.Type;
@@ -431,7 +430,7 @@ public class AsmRelationshipProvider {
      * the fields' type in order to locate it.  Currently just fails silently if any of the lookup code
      * doesn't find anything...
      */
-       public void addDeclareAnnotationRelationship(ISourceLocation sourceLocation, String typename,Field field) {
+       public void addDeclareAnnotationRelationship(ISourceLocation sourceLocation, String typename,String fieldName) {
            if (!AsmManager.isCreatingModel()) return;
            
            String pkg  = null;
@@ -445,7 +444,7 @@ public class AsmRelationshipProvider {
         IProgramElement typeElem = AsmManager.getDefault().getHierarchy().findElementForType(pkg,type);
         if (typeElem == null) return;
         
-        IProgramElement fieldElem = AsmManager.getDefault().getHierarchy().findElementForSignature(typeElem,IProgramElement.Kind.FIELD,field.getName());
+        IProgramElement fieldElem = AsmManager.getDefault().getHierarchy().findElementForSignature(typeElem,IProgramElement.Kind.FIELD,fieldName);
         if (fieldElem== null) return;
 
                String targetHandle = fieldElem.getHandleIdentifier();
index ea36cea30e4840d9276560f3ea1675e3c2c916d8..c908e3cd52da8373a32f36bef68aa940b7ebb221 100644 (file)
@@ -15,8 +15,8 @@ import java.io.DataOutputStream;
 import java.io.IOException;
 import java.util.List;
 
-import org.aspectj.apache.bcel.classfile.annotation.Annotation;
-import org.aspectj.apache.bcel.classfile.annotation.ElementNameValuePair;
+import org.aspectj.apache.bcel.classfile.annotation.AnnotationGen;
+import org.aspectj.apache.bcel.classfile.annotation.ElementNameValuePairGen;
 
 /**
  * For implementing declare @type interacting with declare @parents during compilation - we need to be 
@@ -27,14 +27,14 @@ import org.aspectj.apache.bcel.classfile.annotation.ElementNameValuePair;
  * this will allow type resolution to succeed correctly.  The FakeAnnotation never makes it to disk, since the weaver
  * does the job properly, attaching a real annotation.
  */
-public class FakeAnnotation extends Annotation {
+public class FakeAnnotation extends AnnotationGen {
 
        private String name;
        private String sig;
        private boolean isRuntimeVisible;
        
        public FakeAnnotation(String name,String sig,boolean isRuntimeVisible) {
-               super(0,null,true);
+               super(null,null,true,null);
                this.name = name;
                this.sig = sig;
                this.isRuntimeVisible = isRuntimeVisible;
@@ -48,11 +48,11 @@ public class FakeAnnotation extends Annotation {
                return sig;
        }
 
-       public void addElementNameValuePair(ElementNameValuePair evp) {
+       public void addElementNameValuePair(ElementNameValuePairGen evp) {
                // doesnt need to know about name/value pairs
        }
 
-       protected void dump(DataOutputStream dos) throws IOException {
+       public void dump(DataOutputStream dos) throws IOException {
                // should be serialized
        }
 
@@ -68,7 +68,7 @@ public class FakeAnnotation extends Annotation {
                return isRuntimeVisible;
        }
 
-       protected void isRuntimeVisible(boolean b) {
+       protected void setIsRuntimeVisible(boolean b) {
        }
 
        public String toShortString() {
index 246de45f3e3341f8e0b97b857e4b6ad3a31aa933..cb495c3b75b387df8165cbbbba23d566e5d94c68 100644 (file)
@@ -406,4 +406,8 @@ public class JoinPointSignature implements ResolvedMember {
        }
 
        public void evictWeavingState() { realMember.evictWeavingState(); }
+
+       public Member slimline() {
+               return this;
+       }
 }
index 7bc20794fccb6fe7a2c6327dcd5d9a9121ffeea0..7d3de983f82eee83b142c0983f89b15a03da5315 100644 (file)
@@ -189,8 +189,8 @@ public class JoinPointSignatureIterator implements Iterator {
                                                additionalSignatures.add(member);  // for this time
                                        }                                       
                                        // if this was a parameterized type, look in the generic type that backs it too
-                                       if (superType.isParameterizedType() && (foundMember.backingGenericMember != null)) {
-                                               ResolvedMember member =new JoinPointSignature(foundMember.backingGenericMember,foundMember.declaringType.resolve(world)); 
+                                       if (superType.isParameterizedType() && foundMember.hasBackingGenericMember()) {
+                                               ResolvedMember member =new JoinPointSignature(foundMember.getBackingGenericMember(),foundMember.declaringType.resolve(world)); 
                                                discoveredSignatures.add(member);  // for next time we are reset
                                                if (additionalSignatures==Collections.EMPTY_LIST) additionalSignatures=new ArrayList();
                                                additionalSignatures.add(member);  // for this time
index 2b4d9d6d7037775ea2a376c9d29aabce526c4c84..b6db208ec75effd675fcb3e4b3a9a09fbe17ae0d 100644 (file)
@@ -148,4 +148,6 @@ public interface Member {
 
        public String[] getParameterNames(World world);
 
+       public Member slimline();
+
 }
\ No newline at end of file
index 65050638cbd2cd01b97b81c29470c5544600c39b..e4ab17f71aa282730823a16852feee5dd98b86c0 100644 (file)
@@ -24,10 +24,10 @@ import java.util.List;
 public class MemberImpl implements Comparable, AnnotatedElement,Member {
     
     protected Kind kind;
-    protected UnresolvedType declaringType;
     protected int modifiers; 
-    protected UnresolvedType returnType;
+    protected UnresolvedType declaringType;
     protected String name;
+    protected UnresolvedType returnType;
     protected UnresolvedType[] parameterTypes;
     private final String signature;
     private String paramSignature;
@@ -982,5 +982,9 @@ public class MemberImpl implements Comparable, AnnotatedElement,Member {
                }
     }
 
+       public Member slimline() {
+               return this;
+       }
+
 }
    
index d1bff981621239189a4cc67d638c66d9f2d8657c..8c72c371a21eb401d9bb6bc9646fdd5f47002c8c 100644 (file)
@@ -31,30 +31,61 @@ import org.aspectj.bridge.ISourceLocation;
  * This is the declared member, i.e. it will always correspond to an
  * actual method/... declaration
  */
+
+
+
 public class ResolvedMemberImpl extends MemberImpl implements IHasPosition, AnnotatedElement, TypeVariableDeclaringElement, ResolvedMember {
-    
+
+       // TESTAPI - controlling whether parameter names come out in the debug string (for testing purposes)
+       public static boolean showParameterNames = true;
+
     private String[] parameterNames = null;
     protected UnresolvedType[] checkedExceptions = UnresolvedType.NONE;
+//     private boolean isAjSynthetic = false;    
+       protected int start, end;
+       protected ISourceContext sourceContext = null;
+    
+       private int bits;
+       private static final int HAS_BACKING_GENERIC_MEMBER = 0x0001;
+       private static final int IS_ANNOTATED_ELSEWHERE     = 0x0002;
+       private static final int IS_ANNOTATED_ELSEWHERE_INV = 0x0ffd;
+       private static final int HAVE_CALCULATED_MY_ERASURE = 0x0004;
+       private static final int HAS_ERASURE                = 0x0008;
+       private static final int IS_AJ_SYNTHETIC            = 0x0010;
+       private static final int IS_AJ_SYNTHETIC_INV        = 0x0fef;
+       
+       protected RMMetaInfo metaInfo;
+       
+       protected static class RMMetaInfo {
+               public ResolvedMember backingGenericMember;
+               public ResolvedMember myErasure;
+       }
     /**
      * if this member is a parameterized version of a member in a generic type,
      * then this field holds a reference to the member we parameterize.
      */
-    protected ResolvedMember backingGenericMember = null;
+  //   protected ResolvedMember backingGenericMember = null;
         
     protected Set annotationTypes = null;
        // Some members are 'created' to represent other things (for example ITDs).  These
        // members have their annotations stored elsewhere, and this flag indicates that is
        // the case.  It is up to the caller to work out where that is!
        // Once determined the caller may choose to stash the annotations in this member...
-       private boolean isAnnotatedElsewhere = false; // this field is not serialized.
-       private boolean isAjSynthetic = false;
-    
+//     private boolean isAnnotatedElsewhere = false; // this field is not serialized.
     // generic methods have type variables
        protected TypeVariable[] typeVariables;
-    
-    // these three fields hold the source location of this member
-       protected int start, end;
-       protected ISourceContext sourceContext = null;
+       /** converts e.g. <T extends Number>.... List<T>  to just Ljava/util/List<T;>;
+        * whereas the full signature would be Ljava/util/List<T:Ljava/lang/Number;>;
+        */
+       private String myParameterSignatureWithBoundsRemoved = null;
+       /**
+        * converts e.g. <T extends Number>.... List<T>  to just Ljava/util/List;
+        */
+       private String myParameterSignatureErasure = null;
+//     private ResolvedMember myErasure = null;
+//     private boolean calculatedMyErasure = false;
+               
+       
     
     //XXX deprecate this in favor of the constructor below
        public ResolvedMemberImpl(
@@ -94,8 +125,11 @@ public class ResolvedMemberImpl extends MemberImpl implements IHasPosition, Anno
                        ResolvedMember backingGenericMember) 
                {
                        this(kind, declaringType, modifiers, returnType, name, parameterTypes,checkedExceptions);
-                       this.backingGenericMember = backingGenericMember;
-                       this.isAjSynthetic = backingGenericMember.isAjSynthetic();
+                       metaInfo= new RMMetaInfo();
+                       bits|=HAS_BACKING_GENERIC_MEMBER;
+                       metaInfo.backingGenericMember = backingGenericMember;
+                       if (backingGenericMember.isAjSynthetic()) bits|=IS_AJ_SYNTHETIC;
+//                     this.isAjSynthetic = backingGenericMember.isAjSynthetic();
                }
        
        public ResolvedMemberImpl(
@@ -221,8 +255,8 @@ public class ResolvedMemberImpl extends MemberImpl implements IHasPosition, Anno
                                                ResolvedMember member = foundMember.withSubstituteDeclaringType(declaringType);
                                                foundMembers.add(member);
                                        }                                       
-                                       if (toLookIn.isParameterizedType() && (foundMember.backingGenericMember != null)) {
-                                               foundMembers.add(new JoinPointSignature(foundMember.backingGenericMember,foundMember.declaringType.resolve(toLookIn.getWorld())));
+                                       if (toLookIn.isParameterizedType() && foundMember.hasBackingGenericMember()) {
+                                               foundMembers.add(new JoinPointSignature(foundMember.getBackingGenericMember(),foundMember.declaringType.resolve(toLookIn.getWorld())));
                                        }
                                        accumulateMembersMatching(foundMember,toLookIn.getDirectSupertypes(),typesAlreadyVisited,foundMembers);
                                        // if this was a parameterized type, look in the generic type that backs it too
@@ -274,10 +308,15 @@ public class ResolvedMemberImpl extends MemberImpl implements IHasPosition, Anno
     
     // ??? true or false?
     public boolean isAjSynthetic() {
-       return isAjSynthetic;
+       return (bits&IS_AJ_SYNTHETIC)!=0;
+//     return isAjSynthetic;
     }
     
-    protected void setAjSynthetic(boolean b) {isAjSynthetic= b;}
+    protected void setAjSynthetic(boolean b) {
+       if (b) bits|=IS_AJ_SYNTHETIC;
+       else   bits&=IS_AJ_SYNTHETIC_INV;
+//     isAjSynthetic= b;
+    }
        
        public boolean hasAnnotations() {
                return  (annotationTypes!=null);
@@ -302,7 +341,8 @@ public class ResolvedMemberImpl extends MemberImpl implements IHasPosition, Anno
     }
     
     public AnnotationX[] getAnnotations() {
-       if (backingGenericMember != null) return backingGenericMember.getAnnotations();
+       if ((bits&HAS_BACKING_GENERIC_MEMBER)!=0 && metaInfo.backingGenericMember!=null) return metaInfo.backingGenericMember.getAnnotations();
+//     if (backingGenericMember != null) return backingGenericMember.getAnnotations();
        return super.getAnnotations();
     }
     
@@ -571,11 +611,14 @@ public class ResolvedMemberImpl extends MemberImpl implements IHasPosition, Anno
        }
 
        public void setAnnotatedElsewhere(boolean b) {
-               isAnnotatedElsewhere = b;
+               if (b) bits|=IS_ANNOTATED_ELSEWHERE;
+               else  bits&=IS_ANNOTATED_ELSEWHERE_INV;
+//             isAnnotatedElsewhere = b;
        }
 
        public boolean isAnnotatedElsewhere() {
-               return isAnnotatedElsewhere;
+               return (bits&IS_ANNOTATED_ELSEWHERE)!=0;
+//             return isAnnotatedElsewhere;
        }
        
        /**
@@ -710,8 +753,14 @@ public class ResolvedMemberImpl extends MemberImpl implements IHasPosition, Anno
         * A type is a supertype of itself.
         */
        public ResolvedMember getErasure() {
-               if (calculatedMyErasure) return myErasure;
-               calculatedMyErasure = true;
+               if ((bits&HAVE_CALCULATED_MY_ERASURE)!=0) {
+                       if ((bits&HAS_ERASURE)!=0) return metaInfo.myErasure;
+                       return null;
+//                     return myErasure;
+               }
+               bits|=HAVE_CALCULATED_MY_ERASURE;
+//             if (calculatedMyErasure) return myErasure;
+//             calculatedMyErasure = true;
                ResolvedType resolvedDeclaringType = (ResolvedType) getDeclaringType();
                // this next test is fast, and the result is cached.
                if (!resolvedDeclaringType.hasParameterizedSuperType()) {
@@ -726,8 +775,13 @@ public class ResolvedMemberImpl extends MemberImpl implements IHasPosition, Anno
                                        // we've found the (a?) parameterized type that defines this member.
                                        // now get the erasure of it
                                        ResolvedMemberImpl matchingMember = (ResolvedMemberImpl) aDeclaringType.lookupMemberNoSupers(this);
-                                       if (matchingMember != null && matchingMember.backingGenericMember != null) {
-                                               myErasure = matchingMember.backingGenericMember;
+                                       if (matchingMember != null && matchingMember.hasBackingGenericMember()) {
+                                               ResolvedMember myErasure = matchingMember.getBackingGenericMember();
+                                               if (myErasure!=null) {
+                                                       bits|=HAS_ERASURE;
+                                                       if (metaInfo == null) metaInfo = new RMMetaInfo();
+                                                       metaInfo.myErasure = myErasure;
+                                               }
                                                return myErasure;
                                        }
                                }
@@ -736,15 +790,15 @@ public class ResolvedMemberImpl extends MemberImpl implements IHasPosition, Anno
                return null;
        }
        
-       private ResolvedMember myErasure = null;
-       private boolean calculatedMyErasure = false;
        
        public boolean hasBackingGenericMember() {
-               return backingGenericMember!=null;
+               if ((bits&HAS_BACKING_GENERIC_MEMBER)==0) return false;
+               return metaInfo.backingGenericMember!=null;
        }
        
        public ResolvedMember getBackingGenericMember() {
-               return backingGenericMember;
+               if ((bits&HAS_BACKING_GENERIC_MEMBER)==0) return null;
+               return metaInfo.backingGenericMember;
        }
        
        /**
@@ -792,14 +846,6 @@ public class ResolvedMemberImpl extends MemberImpl implements IHasPosition, Anno
                }
        }
        
-       /** converts e.g. <T extends Number>.... List<T>  to just Ljava/util/List<T;>;
-        * whereas the full signature would be Ljava/util/List<T:Ljava/lang/Number;>;
-        */
-       private String myParameterSignatureWithBoundsRemoved = null;
-       /**
-        * converts e.g. <T extends Number>.... List<T>  to just Ljava/util/List;
-        */
-       private String myParameterSignatureErasure = null;
        
        // does NOT produce a meaningful java signature, but does give a unique string suitable for
        // comparison.
@@ -898,9 +944,6 @@ public class ResolvedMemberImpl extends MemberImpl implements IHasPosition, Anno
           return r.toString();
    }
    
-   // SECRETAPI - controlling whether parameter names come out in the debug string (for testing purposes)
-   public static boolean showParameterNames = true;
-       
    public String toGenericString() {
        StringBuffer buf = new StringBuffer();
        buf.append(getGenericReturnType().getSimpleName());
index 6ab69094ba132a7d1e566b7434c909f5c7e3d863..76f0dbd62f93737b0a8c70cc5eb464932932e9bd 100644 (file)
@@ -21,20 +21,28 @@ import org.aspectj.bridge.SourceLocation;
 
 public class SourceContextImpl implements ISourceContext {
        
-       private AbstractReferenceTypeDelegate delegate;
+//     private AbstractReferenceTypeDelegate delegate;
        private int[] lineBreaks;
+       String sfname;
        
        public SourceContextImpl(AbstractReferenceTypeDelegate delegate) {
-               this.delegate = delegate;               
+//             this.delegate = delegate;
+               sfname = delegate.getSourcefilename();
        }
        
        public void configureFromAttribute(String name,int []linebreaks) { 
-               this.delegate.setSourcefilename(name);
+//             this.delegate.setSourcefilename(name);
+               sfname = name;
                this.lineBreaks = linebreaks;
        }
        
+       public void setSourceFileName(String name) {
+               sfname = name;
+       }
+       
        private File getSourceFile() {
-               return new File(delegate.getSourcefilename());
+               return new File(sfname);
+//             return new File(delegate.getSourcefilename());
        }
        
        public void tidy() {}
index 817a07e1d84b4efa3da4b2aaca89f8fe7a09d9fe..ea913c60be16a4040e8cbddebe64e3bcdee88baa 100644 (file)
@@ -664,7 +664,7 @@ public class UnresolvedType implements Traceable, TypeVariableDeclaringElement {
 
     // ---- helpers
     
-    private static String signatureToName(String signature) {
+    public static String signatureToName(String signature) {
         switch (signature.charAt(0)) {
             case 'B': return "byte";
             case 'C': return "char";
index db432e01498a17e5ff1dbd78af3fc7317fb60945..0b6cfc325e51fdbd804514fcc37444b05f8e6c13 100644 (file)
@@ -23,7 +23,7 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
-import java.util.WeakHashMap;
+import java.util.Set;
 
 import org.aspectj.asm.IHierarchy;
 import org.aspectj.bridge.IMessageHandler;
@@ -40,6 +40,7 @@ import org.aspectj.weaver.patterns.Pointcut;
 import org.aspectj.weaver.reflect.ReflectionBasedReferenceTypeDelegate;
 import org.aspectj.weaver.tools.Trace;
 import org.aspectj.weaver.tools.TraceFactory;
+import java.util.*;
 
 /**
  * A World is a collection of known types and crosscutting members.
@@ -816,6 +817,7 @@ public abstract class World implements Dump.INode {
        public boolean isJoinpointArrayConstructionEnabled() {
                return optionalJoinpoint_ArrayConstruction;
        }
+
        public boolean isJoinpointSynchronizationEnabled() {
                return optionalJoinpoint_Synchronization;
        }
@@ -848,14 +850,84 @@ public abstract class World implements Dump.INode {
                public static int USE_SOFT_REFS = 2; // Collected when short on memory
                
                // SECRETAPI - Can switch to a policy of choice ;)
-               public static int policy  = USE_SOFT_REFS; 
+               public static int policy  = DONT_USE_REFS; 
 
                // Map of types that never get thrown away
                private Map /* String -> ResolvedType */ tMap = new HashMap();
                
                // Map of types that may be ejected from the cache if we need space
-               private Map expendableMap = new WeakHashMap();
+               private Map expendableMap = new SoftHashMap();
                
+               public static class SoftHashMap extends AbstractMap {
+                         private Map map;
+                         private ReferenceQueue rq = new ReferenceQueue(); 
+                         
+                     public SoftHashMap(Map map) { this.map = map; }
+                         public SoftHashMap() { this(new HashMap()); }
+                         public SoftHashMap(Map map, boolean b) { this(map); }
+                       
+                         class SpecialValue extends SoftReference {
+                                 private final Object key;
+                                 SpecialValue(Object k,Object v) {
+                                   super(v,rq);
+                                   this.key = k;
+                                 }
+                         }  
+
+                         private void processQueue() {
+                               SpecialValue sv = null;
+                               while ((sv = (SpecialValue)rq.poll())!=null) {
+                                       map.remove(sv.key);
+                               }
+                         }
+                       
+                         public Object get(Object key) {
+                               SpecialValue value = (SpecialValue)map.get(key);
+                               if (value==null) return null;
+                               if (value.get()==null) {
+                                       // it got GC'd
+                                       map.remove(value.key);
+                                       return null;
+                               } else {
+                                       return value.get();
+                               }
+                         }
+
+                         public Object put(Object k, Object v) {
+                               processQueue();
+                               return map.put(k, new SpecialValue(k,v));
+                         }
+
+                         public Set entrySet() {
+                               return map.entrySet();
+                         }
+                       
+                         public void clear() {
+                               processQueue();
+                               Set keys = map.keySet();
+                               keys.clear();
+//                             for (Iterator iterator = keys.iterator(); iterator.hasNext();) {
+//                                     Object name = (Object) iterator.next();
+//                                     map.remove(name);
+//                             }
+                         }
+                       
+                         public int size() {
+                               processQueue();
+                               return map.size();
+                         }
+                       
+                         public Object remove(Object k) {
+                               processQueue();
+                               SpecialValue value = (SpecialValue)map.remove(k);
+                               if (value==null) return null;
+                               if (value.get()!=null) {
+                                       return value.get();
+                               }
+                               return null;
+                         }
+                 }
+
                private World w;
 
                // profiling tools...
@@ -934,10 +1006,36 @@ public abstract class World implements Dump.INode {
                                }
                            return type;
                        } else {
+                               newkeys.add(key);
                                return (ResolvedType) tMap.put(key,type);
                        }
                }
                
+               List /*<String> keys*/ newkeys = new ArrayList();
+               
+               public void demote() {
+                       // If unaffected by ITDs, get rid of it
+                       int count =0;
+                       for (Iterator iter = newkeys.iterator(); iter.hasNext();) {
+                               String key = (String) iter.next();
+                               ResolvedType type = (ResolvedType)tMap.get(key);
+                               if (type==null) continue;//throw new RuntimeException("Unexpected!! "+key);
+                               if (type.isAspect() ) continue;
+                               if (type.equals(UnresolvedType.OBJECT)) continue;
+                               if (type.isPrimitiveType()) continue;
+                               List typeMungers = type.getInterTypeMungers();
+                               if (typeMungers==null || typeMungers.size()==0) {
+                                       // demote - we can recover this
+                                       tMap.remove(key);
+                                       // extreme demotion if you dont use these next two lines!
+//                                     if (memoryProfiling) expendableMap.put(key,new SoftReference(type,rq));
+//                                     else                 expendableMap.put(key,new SoftReference(type));
+                                       count++;
+                               }
+                       }
+//                     System.out.print(count+" ");
+                       newkeys.clear();
+               }
                public void report() {
                        if (!memoryProfiling) return;
                        checkq();
@@ -1044,6 +1142,10 @@ public abstract class World implements Dump.INode {
            }
        }       
        
+       public void demote() {
+               typeMap.demote();
+       }
+       
        /** Reference types we don't intend to weave may be ejected from
         * the cache if we need the space.
         */
@@ -1055,6 +1157,7 @@ public abstract class World implements Dump.INode {
                                  (!type.isPrimitiveType())
                                );
        }
+       
 
        /**
         * This class is used to compute and store precedence relationships between
index 61ecd9696fcf4acb4d5ec725cc3faf94e7e0c651..96d393126a2a00925ecd9fcf9ca9eb359f13fa1f 100644 (file)
@@ -27,9 +27,9 @@ import org.aspectj.apache.bcel.classfile.JavaClass;
 import org.aspectj.apache.bcel.classfile.LocalVariable;
 import org.aspectj.apache.bcel.classfile.LocalVariableTable;
 import org.aspectj.apache.bcel.classfile.Method;
-import org.aspectj.apache.bcel.classfile.annotation.Annotation;
-import org.aspectj.apache.bcel.classfile.annotation.ClassElementValue;
-import org.aspectj.apache.bcel.classfile.annotation.ElementNameValuePair;
+import org.aspectj.apache.bcel.classfile.annotation.AnnotationGen;
+import org.aspectj.apache.bcel.classfile.annotation.ClassElementValueGen;
+import org.aspectj.apache.bcel.classfile.annotation.ElementNameValuePairGen;
 import org.aspectj.apache.bcel.classfile.annotation.RuntimeAnnotations;
 import org.aspectj.apache.bcel.classfile.annotation.RuntimeVisibleAnnotations;
 import org.aspectj.apache.bcel.generic.Type;
@@ -486,7 +486,7 @@ public class AtAjAttributes {
      * @return true if found
      */
     private static boolean handleAspectAnnotation(RuntimeAnnotations runtimeAnnotations, AjAttributeStruct struct) {
-        Annotation aspect = getAnnotation(runtimeAnnotations, AjcMemberMaker.ASPECT_ANNOTATION);
+        AnnotationGen aspect = getAnnotation(runtimeAnnotations, AjcMemberMaker.ASPECT_ANNOTATION);
         if (aspect != null) {
             // semantic check for inheritance (only one level up)
             boolean extendsAspect = false;
@@ -498,7 +498,7 @@ public class AtAjAttributes {
                 extendsAspect = struct.enclosingType.getSuperclass().isAspect();
             }
 
-            ElementNameValuePair aspectPerClause = getAnnotationElement(aspect, VALUE);
+            ElementNameValuePairGen aspectPerClause = getAnnotationElement(aspect, VALUE);
             final PerClause perClause;
             if (aspectPerClause == null) {
                 // empty value means singleton unless inherited
@@ -606,9 +606,9 @@ public class AtAjAttributes {
      * @return true if found
      */
     private static boolean handlePrecedenceAnnotation(RuntimeAnnotations runtimeAnnotations, AjAttributeStruct struct) {
-        Annotation aspect = getAnnotation(runtimeAnnotations, AjcMemberMaker.DECLAREPRECEDENCE_ANNOTATION);
+        AnnotationGen aspect = getAnnotation(runtimeAnnotations, AjcMemberMaker.DECLAREPRECEDENCE_ANNOTATION);
         if (aspect != null) {
-            ElementNameValuePair precedence = getAnnotationElement(aspect, VALUE);
+            ElementNameValuePairGen precedence = getAnnotationElement(aspect, VALUE);
             if (precedence != null) {
                 String precedencePattern = precedence.getValue().stringifyValue();
                 PatternParser parser = new PatternParser(precedencePattern);
@@ -630,7 +630,7 @@ public class AtAjAttributes {
 //    private static boolean handleDeclareImplementsAnnotation(RuntimeAnnotations runtimeAnnotations, AjAttributeFieldStruct struct) {//, ResolvedPointcutDefinition preResolvedPointcut) {
 //        Annotation deci = getAnnotation(runtimeAnnotations, AjcMemberMaker.DECLAREIMPLEMENTS_ANNOTATION);
 //        if (deci != null) {
-//            ElementNameValuePair deciPatternNVP = getAnnotationElement(deci, VALUE);
+//            ElementNameValuePairGen deciPatternNVP = getAnnotationElement(deci, VALUE);
 //            String deciPattern = deciPatternNVP.getValue().stringifyValue();
 //            if (deciPattern != null) {
 //                TypePattern typePattern = parseTypePattern(deciPattern, struct);
@@ -670,9 +670,9 @@ public class AtAjAttributes {
      * @return true if found
      */
     private static boolean handleDeclareParentsAnnotation(RuntimeAnnotations runtimeAnnotations, AjAttributeFieldStruct struct) {//, ResolvedPointcutDefinition preResolvedPointcut) {
-        Annotation decp = getAnnotation(runtimeAnnotations, AjcMemberMaker.DECLAREPARENTS_ANNOTATION);
+        AnnotationGen decp = getAnnotation(runtimeAnnotations, AjcMemberMaker.DECLAREPARENTS_ANNOTATION);
         if (decp != null) {
-            ElementNameValuePair decpPatternNVP = getAnnotationElement(decp, VALUE);
+            ElementNameValuePairGen decpPatternNVP = getAnnotationElement(decp, VALUE);
             String decpPattern = decpPatternNVP.getValue().stringifyValue();
             if (decpPattern != null) {
                 TypePattern typePattern = parseTypePattern(decpPattern, struct);
@@ -697,9 +697,9 @@ public class AtAjAttributes {
 
                     // do we have a defaultImpl=xxx.class (ie implementation)
                     String defaultImplClassName = null;
-                    ElementNameValuePair defaultImplNVP = getAnnotationElement(decp, "defaultImpl");
+                    ElementNameValuePairGen defaultImplNVP = getAnnotationElement(decp, "defaultImpl");
                     if (defaultImplNVP != null) {
-                        ClassElementValue defaultImpl = (ClassElementValue) defaultImplNVP.getValue();
+                        ClassElementValueGen defaultImpl = (ClassElementValueGen) defaultImplNVP.getValue();
                         defaultImplClassName = UnresolvedType.forSignature(defaultImpl.getClassString()).getName();
                         if (defaultImplClassName.equals("org.aspectj.lang.annotation.DeclareParents")) {
                             defaultImplClassName = null;
@@ -797,9 +797,9 @@ public class AtAjAttributes {
      * @return true if found
      */
     private static boolean handleBeforeAnnotation(RuntimeAnnotations runtimeAnnotations, AjAttributeMethodStruct struct, ResolvedPointcutDefinition preResolvedPointcut) {
-        Annotation before = getAnnotation(runtimeAnnotations, AjcMemberMaker.BEFORE_ANNOTATION);
+        AnnotationGen before = getAnnotation(runtimeAnnotations, AjcMemberMaker.BEFORE_ANNOTATION);
         if (before != null) {
-            ElementNameValuePair beforeAdvice = getAnnotationElement(before, VALUE);
+            ElementNameValuePairGen beforeAdvice = getAnnotationElement(before, VALUE);
             if (beforeAdvice != null) {
                 // this/target/args binding
                 FormalBinding[] bindings = new org.aspectj.weaver.patterns.FormalBinding[0];
@@ -853,9 +853,9 @@ public class AtAjAttributes {
      * @return true if found
      */
     private static boolean handleAfterAnnotation(RuntimeAnnotations runtimeAnnotations, AjAttributeMethodStruct struct, ResolvedPointcutDefinition preResolvedPointcut) {
-        Annotation after = getAnnotation(runtimeAnnotations, AjcMemberMaker.AFTER_ANNOTATION);
+        AnnotationGen after = getAnnotation(runtimeAnnotations, AjcMemberMaker.AFTER_ANNOTATION);
         if (after != null) {
-            ElementNameValuePair afterAdvice = getAnnotationElement(after, VALUE);
+            ElementNameValuePairGen afterAdvice = getAnnotationElement(after, VALUE);
             if (afterAdvice != null) {
                 // this/target/args binding
                 FormalBinding[] bindings = new org.aspectj.weaver.patterns.FormalBinding[0];
@@ -914,11 +914,11 @@ public class AtAjAttributes {
             BcelMethod owningMethod)
     throws ReturningFormalNotDeclaredInAdviceSignatureException
     {
-        Annotation after = getAnnotation(runtimeAnnotations, AjcMemberMaker.AFTERRETURNING_ANNOTATION);
+        AnnotationGen after = getAnnotation(runtimeAnnotations, AjcMemberMaker.AFTERRETURNING_ANNOTATION);
         if (after != null) {
-            ElementNameValuePair annValue = getAnnotationElement(after, VALUE);
-            ElementNameValuePair annPointcut = getAnnotationElement(after, POINTCUT);
-            ElementNameValuePair annReturned = getAnnotationElement(after, RETURNING);
+            ElementNameValuePairGen annValue = getAnnotationElement(after, VALUE);
+            ElementNameValuePairGen annPointcut = getAnnotationElement(after, POINTCUT);
+            ElementNameValuePairGen annReturned = getAnnotationElement(after, RETURNING);
 
             // extract the pointcut and returned type/binding - do some checks
             String pointcut = null;
@@ -1011,11 +1011,11 @@ public class AtAjAttributes {
             BcelMethod owningMethod)
     throws ThrownFormalNotDeclaredInAdviceSignatureException
     {
-        Annotation after = getAnnotation(runtimeAnnotations, AjcMemberMaker.AFTERTHROWING_ANNOTATION);
+        AnnotationGen after = getAnnotation(runtimeAnnotations, AjcMemberMaker.AFTERTHROWING_ANNOTATION);
         if (after != null) {
-            ElementNameValuePair annValue = getAnnotationElement(after, VALUE);
-            ElementNameValuePair annPointcut = getAnnotationElement(after, POINTCUT);
-            ElementNameValuePair annThrown = getAnnotationElement(after, THROWING);
+            ElementNameValuePairGen annValue = getAnnotationElement(after, VALUE);
+            ElementNameValuePairGen annPointcut = getAnnotationElement(after, POINTCUT);
+            ElementNameValuePairGen annThrown = getAnnotationElement(after, THROWING);
 
             // extract the pointcut and throwned type/binding - do some checks
             String pointcut = null;
@@ -1102,9 +1102,9 @@ public class AtAjAttributes {
      * @return true if found
      */
     private static boolean handleAroundAnnotation(RuntimeAnnotations runtimeAnnotations, AjAttributeMethodStruct struct, ResolvedPointcutDefinition preResolvedPointcut) {
-        Annotation around = getAnnotation(runtimeAnnotations, AjcMemberMaker.AROUND_ANNOTATION);
+        AnnotationGen around = getAnnotation(runtimeAnnotations, AjcMemberMaker.AROUND_ANNOTATION);
         if (around != null) {
-            ElementNameValuePair aroundAdvice = getAnnotationElement(around, VALUE);
+            ElementNameValuePairGen aroundAdvice = getAnnotationElement(around, VALUE);
             if (aroundAdvice != null) {
                 // this/target/args binding
                 FormalBinding[] bindings = new org.aspectj.weaver.patterns.FormalBinding[0];
@@ -1156,9 +1156,9 @@ public class AtAjAttributes {
      * @param struct
      */
     private static void handlePointcutAnnotation(RuntimeAnnotations runtimeAnnotations, AjAttributeMethodStruct struct) {
-        Annotation pointcut = getAnnotation(runtimeAnnotations, AjcMemberMaker.POINTCUT_ANNOTATION);
+        AnnotationGen pointcut = getAnnotation(runtimeAnnotations, AjcMemberMaker.POINTCUT_ANNOTATION);
         if (pointcut != null) {
-            ElementNameValuePair pointcutExpr = getAnnotationElement(pointcut, VALUE);
+            ElementNameValuePairGen pointcutExpr = getAnnotationElement(pointcut, VALUE);
 
             // semantic check: the method must return void, or be "public static boolean" for if() support
             if (!(Type.VOID.equals(struct.method.getReturnType())
@@ -1241,10 +1241,10 @@ public class AtAjAttributes {
      * @return true if found
      */
     private static boolean handleDeclareErrorOrWarningAnnotation(RuntimeAnnotations runtimeAnnotations, AjAttributeFieldStruct struct) {
-        Annotation error = getAnnotation(runtimeAnnotations, AjcMemberMaker.DECLAREERROR_ANNOTATION);
+        AnnotationGen error = getAnnotation(runtimeAnnotations, AjcMemberMaker.DECLAREERROR_ANNOTATION);
         boolean hasError = false;
         if (error != null) {
-            ElementNameValuePair declareError = getAnnotationElement(error, VALUE);
+            ElementNameValuePairGen declareError = getAnnotationElement(error, VALUE);
             if (declareError != null) {
                 if (!STRING_DESC.equals(struct.field.getSignature()) || struct.field.getConstantValue() == null) {
                     reportError("@DeclareError used on a non String constant field", struct);
@@ -1261,10 +1261,10 @@ public class AtAjAttributes {
                 }
             }
         }
-        Annotation warning = getAnnotation(runtimeAnnotations, AjcMemberMaker.DECLAREWARNING_ANNOTATION);
+        AnnotationGen warning = getAnnotation(runtimeAnnotations, AjcMemberMaker.DECLAREWARNING_ANNOTATION);
         boolean hasWarning = false;
         if (warning != null) {
-            ElementNameValuePair declareWarning = getAnnotationElement(warning, VALUE);
+            ElementNameValuePairGen declareWarning = getAnnotationElement(warning, VALUE);
             if (declareWarning != null) {
                 if (!STRING_DESC.equals(struct.field.getSignature()) || struct.field.getConstantValue() == null) {
                     reportError("@DeclareWarning used on a non String constant field", struct);
@@ -1464,10 +1464,10 @@ public class AtAjAttributes {
      * @param annotationType
      * @return annotation
      */
-    private static Annotation getAnnotation(RuntimeAnnotations rvs, UnresolvedType annotationType) {
+    private static AnnotationGen getAnnotation(RuntimeAnnotations rvs, UnresolvedType annotationType) {
         final String annotationTypeName = annotationType.getName();
         for (Iterator iterator = rvs.getAnnotations().iterator(); iterator.hasNext();) {
-            Annotation rv = (Annotation) iterator.next();
+            AnnotationGen rv = (AnnotationGen) iterator.next();
             if (annotationTypeName.equals(rv.getTypeName())) {
                 return rv;
             }
@@ -1483,9 +1483,9 @@ public class AtAjAttributes {
      * @param elementName
      * @return annotation NVP
      */
-    private static ElementNameValuePair getAnnotationElement(Annotation annotation, String elementName) {
+    private static ElementNameValuePairGen getAnnotationElement(AnnotationGen annotation, String elementName) {
         for (Iterator iterator1 = annotation.getValues().iterator(); iterator1.hasNext();) {
-            ElementNameValuePair element = (ElementNameValuePair) iterator1.next();
+            ElementNameValuePairGen element = (ElementNameValuePairGen) iterator1.next();
             if (elementName.equals(element.getNameString())) {
                 return element;
             }
index 35456fe8dd69c6c580dfec6132347b03ecfa21e8..fbed9cd5948523ff204b3f0d2042a03ba9673322 100644 (file)
  *******************************************************************************/
 package org.aspectj.weaver.bcel;
 
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
 import org.aspectj.apache.bcel.Constants;
-import org.aspectj.apache.bcel.generic.ConstantPoolGen;
 import org.aspectj.apache.bcel.generic.FieldInstruction;
-import org.aspectj.apache.bcel.generic.GETFIELD;
-import org.aspectj.apache.bcel.generic.GETSTATIC;
 import org.aspectj.apache.bcel.generic.Instruction;
 import org.aspectj.apache.bcel.generic.InstructionConstants;
 import org.aspectj.apache.bcel.generic.InstructionFactory;
 import org.aspectj.apache.bcel.generic.InstructionHandle;
 import org.aspectj.apache.bcel.generic.InstructionList;
 import org.aspectj.apache.bcel.generic.InvokeInstruction;
+import org.aspectj.apache.bcel.classfile.ConstantPool;
 import org.aspectj.apache.bcel.generic.Type;
 import org.aspectj.weaver.AjAttribute;
 import org.aspectj.weaver.AjcMemberMaker;
@@ -32,13 +37,6 @@ import org.aspectj.weaver.ResolvedType;
 import org.aspectj.weaver.Shadow;
 import org.aspectj.weaver.UnresolvedType;
 
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
-import java.util.List;
-
 /**
  * Looks for all access to method or field that are not public within the body of the around advices and replace
  * the invocations to a wrapper call so that the around advice can further be inlined.
@@ -133,7 +131,7 @@ public class BcelAccessForInlineMunger extends BcelTypeMunger {
     private void openAroundAdvice(LazyMethodGen aroundAdvice) {
         InstructionHandle curr = aroundAdvice.getBody().getStart();
         InstructionHandle end = aroundAdvice.getBody().getEnd();
-        ConstantPoolGen cpg = aroundAdvice.getEnclosingClass().getConstantPoolGen();
+        ConstantPool cpg = aroundAdvice.getEnclosingClass().getConstantPool();
         InstructionFactory factory = aroundAdvice.getEnclosingClass().getFactory();
 
         boolean realizedCannotInline = false;
@@ -205,7 +203,7 @@ public class BcelAccessForInlineMunger extends BcelTypeMunger {
                             && invoke.getSignature(cpg).equals(resolvedMember.getSignature())
                             && !resolvedMember.isPublic()) {
                         final ResolvedMember accessor;
-                        if ((inst instanceof GETFIELD) || (inst instanceof GETSTATIC)) {
+                        if ((inst.opcode==Constants.GETFIELD) || (inst.opcode==Constants.GETSTATIC)) {
                             accessor = createOrGetInlineAccessorForFieldGet(resolvedMember);
                         } else {
                             accessor = createOrGetInlineAccessorForFieldSet(resolvedMember);
@@ -259,13 +257,13 @@ public class BcelAccessForInlineMunger extends BcelTypeMunger {
             // flag it synthetic, AjSynthetic
             method.makeSynthetic();
             method.addAttribute(
-                    BcelAttributes.bcelAttribute(new AjAttribute.AjSynthetic(), m_aspectGen.getConstantPoolGen())
+                    BcelAttributes.bcelAttribute(new AjAttribute.AjSynthetic(), m_aspectGen.getConstantPool())
             );
             // flag the effective signature, so that we can deobfuscate the signature to apply method call pointcut
             method.addAttribute(
                     BcelAttributes.bcelAttribute(
                             new AjAttribute.EffectiveSignatureAttribute(resolvedMember, Shadow.MethodCall, false),
-                            m_aspectGen.getConstantPoolGen()
+                            m_aspectGen.getConstantPool()
                     )
             );
 
@@ -320,13 +318,13 @@ public class BcelAccessForInlineMunger extends BcelTypeMunger {
             // flag it synthetic, AjSynthetic
             method.makeSynthetic();
             method.addAttribute(
-                    BcelAttributes.bcelAttribute(new AjAttribute.AjSynthetic(), m_aspectGen.getConstantPoolGen())
+                    BcelAttributes.bcelAttribute(new AjAttribute.AjSynthetic(), m_aspectGen.getConstantPool())
             );
             // flag the effective signature, so that we can deobfuscate the signature to apply method call pointcut
             method.addAttribute(
                     BcelAttributes.bcelAttribute(
                             new AjAttribute.EffectiveSignatureAttribute(resolvedMember, Shadow.MethodCall, false),
-                            m_aspectGen.getConstantPoolGen()
+                            m_aspectGen.getConstantPool()
                     )
             );
 
@@ -382,13 +380,13 @@ public class BcelAccessForInlineMunger extends BcelTypeMunger {
             // flag it synthetic, AjSynthetic
             method.makeSynthetic();
             method.addAttribute(
-                    BcelAttributes.bcelAttribute(new AjAttribute.AjSynthetic(), m_aspectGen.getConstantPoolGen())
+                    BcelAttributes.bcelAttribute(new AjAttribute.AjSynthetic(), m_aspectGen.getConstantPool())
             );
             // flag the effective signature, so that we can deobfuscate the signature to apply method call pointcut
             method.addAttribute(
                     BcelAttributes.bcelAttribute(
                             new AjAttribute.EffectiveSignatureAttribute(resolvedMember, Shadow.FieldGet, false),
-                            m_aspectGen.getConstantPoolGen()
+                            m_aspectGen.getConstantPool()
                     )
             );
 
@@ -440,13 +438,13 @@ public class BcelAccessForInlineMunger extends BcelTypeMunger {
             // flag it synthetic, AjSynthetic
             method.makeSynthetic();
             method.addAttribute(
-                    BcelAttributes.bcelAttribute(new AjAttribute.AjSynthetic(), m_aspectGen.getConstantPoolGen())
+                    BcelAttributes.bcelAttribute(new AjAttribute.AjSynthetic(), m_aspectGen.getConstantPool())
             );
             // flag the effective signature, so that we can deobfuscate the signature to apply method call pointcut
             method.addAttribute(
                     BcelAttributes.bcelAttribute(
                             new AjAttribute.EffectiveSignatureAttribute(resolvedMember, Shadow.FieldSet, false),
-                            m_aspectGen.getConstantPoolGen()
+                            m_aspectGen.getConstantPool()
                     )
             );
 
index 857f59dea55fde825f2fd2564fa790bdf341ed41..c3c5857fa90315214948c1c24eaaf90ebc3fdda8 100644 (file)
@@ -35,6 +35,7 @@ import org.aspectj.weaver.IEclipseSourceContext;
 import org.aspectj.weaver.ISourceContext;
 import org.aspectj.weaver.Member;
 import org.aspectj.weaver.ResolvedMember;
+import org.aspectj.weaver.ResolvedMemberImpl;
 import org.aspectj.weaver.ResolvedType;
 import org.aspectj.weaver.Shadow;
 import org.aspectj.weaver.ShadowMunger;
@@ -66,7 +67,7 @@ public class BcelAdvice extends Advice {
                Member signature,
                ResolvedType concreteAspect) 
        {
-               super(attribute, pointcut, signature);
+               super(attribute, pointcut, (signature==null?null:signature.slimline()));
                this.concreteAspect = concreteAspect;
        }
 
@@ -76,9 +77,34 @@ public class BcelAdvice extends Advice {
         int start, int end, ISourceContext sourceContext, ResolvedType concreteAspect)
     {
                this(new AjAttribute.AdviceAttribute(kind, pointcut, extraArgumentFlags, start, end, sourceContext), 
-                       pointcut, signature, concreteAspect);
+                       pointcut, (signature==null?null:signature.slimline()), concreteAspect);
                thrownExceptions = Collections.EMPTY_LIST;  //!!! interaction with unit tests
        }
+       
+       /**
+        * We don't always need to represent the signature with a heavyweight BcelMethod object - only if its around advice
+        * and inlining is active
+        * @param concreteAspect 
+        * @param attribute 
+        */
+       private static Member shrink(AdviceKind kind, ResolvedType concreteAspect, Member m) {
+               if (m==null) return null;
+               UnresolvedType dType = m.getDeclaringType();
+               // if it isnt around advice or it is but inlining is turned off then shrink it to a ResolvedMemberImpl
+               if (kind!=AdviceKind.Around  || 
+                       ((dType instanceof ResolvedType) && ((ResolvedType)dType).getWorld().isXnoInline())) {
+                       if (m instanceof BcelMethod) {
+                               BcelMethod bm = (BcelMethod)m;
+                               if (bm.getMethod()!=null && bm.getMethod().getAnnotations()!=null) return m;
+                               ResolvedMemberImpl simplermember = new ResolvedMemberImpl(bm.getKind(),bm.getDeclaringType(),
+                                                                                      bm.getModifiers(),bm.getReturnType(),bm.getName(),
+                                                                                      bm.getParameterTypes());//,bm.getExceptions(),bm.getBackingGenericMember());
+                               simplermember.setParameterNames(bm.getParameterNames());
+                               return simplermember;
+                       }
+               }
+               return m;
+       }
 
     // ---- implementations of ShadowMunger's methods
     
@@ -185,6 +211,7 @@ public class BcelAdvice extends Advice {
 
                if (concreteAspect.getWorld().isXnoInline()) return false;
        //System.err.println("isWoven? " + ((BcelObjectType)concreteAspect).getLazyClassGen().getWeaverState());
+       //      if (BcelWorld.getBcelObjectType(concreteAspect).getJavaClass()==null) return true; // been evicted... CUSTARD
        return BcelWorld.getBcelObjectType(concreteAspect).getLazyClassGen().isWoven();
     }
 
index 5eb7eaaf857223aacc5a01abb01adb9ffe0dfdfd..7aa72675951243ccbb5992bcf1eced966d39ad7a 100644 (file)
@@ -18,7 +18,7 @@ import java.util.List;
 
 import org.aspectj.apache.bcel.classfile.Attribute;
 import org.aspectj.apache.bcel.classfile.Unknown;
-import org.aspectj.apache.bcel.generic.ConstantPoolGen;
+import org.aspectj.apache.bcel.classfile.ConstantPool;
 import org.aspectj.weaver.AjAttribute;
 import org.aspectj.weaver.BCException;
 import org.aspectj.weaver.ISourceContext;
@@ -69,12 +69,12 @@ class BcelAttributes {
                return l;
        }
 
-       public static Attribute bcelAttribute(AjAttribute a, ConstantPoolGen pool) {
+       public static Attribute bcelAttribute(AjAttribute a, ConstantPool pool) {
                int nameIndex = pool.addUtf8(a.getNameString());
                byte[] bytes = a.getBytes();
                int length = bytes.length;
 
-               return new Unknown(nameIndex, length, bytes, pool.getConstantPool());
+               return new Unknown(nameIndex, length, bytes, pool);
 
        }
 
index ceb471cf54bf3074fc856c5b598f951f52b748a1..3566da0d143b92dc92e910de7f30ed13f75951e8 100644 (file)
@@ -13,7 +13,6 @@
 package org.aspectj.weaver.bcel;
 
 import org.aspectj.apache.bcel.Constants;
-import org.aspectj.apache.bcel.classfile.Field;
 import org.aspectj.apache.bcel.generic.FieldGen;
 import org.aspectj.apache.bcel.generic.InstructionFactory;
 import org.aspectj.apache.bcel.generic.InstructionList;
@@ -44,10 +43,10 @@ public class BcelCflowCounterFieldAdder extends BcelTypeMunger {
 
                // Create the field declaration.
                // Something like: "public static final CflowCounter ajc$cflowCounter$0;"
-               Field f = new FieldGen(cflowCounterField.getModifiers(),
+               FieldGen f = new FieldGen(cflowCounterField.getModifiers(),
                    BcelWorld.makeBcelType(cflowCounterField.getReturnType()),
                    cflowCounterField.getName(),
-               gen.getConstantPoolGen()).getField();
+               gen.getConstantPool());
                
        gen.addField(f,getSourceLocation());
 
index c6c1a61d4f0a0031a0b8c41d487e0e67229164cb..5c5e2a86bda96ceca9e4c8b2fb163bd11923d793 100644 (file)
@@ -14,7 +14,6 @@
 package org.aspectj.weaver.bcel;
 
 import org.aspectj.apache.bcel.Constants;
-import org.aspectj.apache.bcel.classfile.Field;
 import org.aspectj.apache.bcel.generic.FieldGen;
 import org.aspectj.apache.bcel.generic.InstructionFactory;
 import org.aspectj.apache.bcel.generic.InstructionList;
@@ -36,10 +35,10 @@ public class BcelCflowStackFieldAdder extends BcelTypeMunger {
                LazyClassGen gen = weaver.getLazyClassGen();
                if (!gen.getType().equals(cflowStackField.getDeclaringType())) return false;
 
-               Field f = new FieldGen(cflowStackField.getModifiers(),
+               FieldGen f = new FieldGen(cflowStackField.getModifiers(),
                    BcelWorld.makeBcelType(cflowStackField.getReturnType()),
                    cflowStackField.getName(),
-               gen.getConstantPoolGen()).getField();
+               gen.getConstantPool());
        gen.addField(f,getSourceLocation());
 
                LazyMethodGen clinit = gen.getAjcPreClinit(); //StaticInitializer();
index 623bfb3360da9b1c5ea1f32b1feed53f73622122..13cc50a7416ec81b3f44c67b1f4edaacc99b46f9 100644 (file)
@@ -27,44 +27,29 @@ import java.util.Properties;
 import java.util.Set;
 
 import org.aspectj.apache.bcel.Constants;
-import org.aspectj.apache.bcel.classfile.Field;
 import org.aspectj.apache.bcel.classfile.Method;
-import org.aspectj.apache.bcel.classfile.annotation.Annotation;
-import org.aspectj.apache.bcel.generic.ANEWARRAY;
-import org.aspectj.apache.bcel.generic.BranchInstruction;
-import org.aspectj.apache.bcel.generic.CPInstruction;
-import org.aspectj.apache.bcel.generic.ConstantPoolGen;
+import org.aspectj.apache.bcel.classfile.ConstantPool;
+import org.aspectj.apache.bcel.classfile.annotation.AnnotationGen;
 import org.aspectj.apache.bcel.generic.FieldGen;
 import org.aspectj.apache.bcel.generic.FieldInstruction;
-import org.aspectj.apache.bcel.generic.GOTO;
-import org.aspectj.apache.bcel.generic.GOTO_W;
-import org.aspectj.apache.bcel.generic.INVOKESPECIAL;
-import org.aspectj.apache.bcel.generic.IndexedInstruction;
 import org.aspectj.apache.bcel.generic.Instruction;
+import org.aspectj.apache.bcel.generic.InstructionBranch;
+import org.aspectj.apache.bcel.generic.InstructionCP;
 import org.aspectj.apache.bcel.generic.InstructionConstants;
 import org.aspectj.apache.bcel.generic.InstructionFactory;
 import org.aspectj.apache.bcel.generic.InstructionHandle;
 import org.aspectj.apache.bcel.generic.InstructionList;
+import org.aspectj.apache.bcel.generic.InstructionSelect;
 import org.aspectj.apache.bcel.generic.InstructionTargeter;
 import org.aspectj.apache.bcel.generic.InvokeInstruction;
 import org.aspectj.apache.bcel.generic.LineNumberTag;
-import org.aspectj.apache.bcel.generic.LocalVariableInstruction;
 import org.aspectj.apache.bcel.generic.LocalVariableTag;
-import org.aspectj.apache.bcel.generic.MONITORENTER;
-import org.aspectj.apache.bcel.generic.MONITOREXIT;
 import org.aspectj.apache.bcel.generic.MULTIANEWARRAY;
 import org.aspectj.apache.bcel.generic.MethodGen;
-import org.aspectj.apache.bcel.generic.NEW;
-import org.aspectj.apache.bcel.generic.NEWARRAY;
 import org.aspectj.apache.bcel.generic.ObjectType;
-import org.aspectj.apache.bcel.generic.PUTFIELD;
-import org.aspectj.apache.bcel.generic.PUTSTATIC;
 import org.aspectj.apache.bcel.generic.RET;
-import org.aspectj.apache.bcel.generic.ReturnInstruction;
-import org.aspectj.apache.bcel.generic.Select;
 import org.aspectj.apache.bcel.generic.Tag;
 import org.aspectj.apache.bcel.generic.Type;
-import org.aspectj.apache.bcel.generic.annotation.AnnotationGen;
 import org.aspectj.bridge.IMessage;
 import org.aspectj.bridge.ISourceLocation;
 import org.aspectj.bridge.Message;
@@ -75,6 +60,7 @@ import org.aspectj.bridge.context.ContextToken;
 import org.aspectj.util.PartialOrder;
 import org.aspectj.weaver.AjAttribute;
 import org.aspectj.weaver.AjcMemberMaker;
+import org.aspectj.weaver.AnnotationX;
 import org.aspectj.weaver.AsmRelationshipProvider;
 import org.aspectj.weaver.BCException;
 import org.aspectj.weaver.ConcreteTypeMunger;
@@ -102,6 +88,10 @@ import org.aspectj.weaver.patterns.ExactTypePattern;
 import org.aspectj.weaver.tools.Trace;
 import org.aspectj.weaver.tools.TraceFactory;
 
+import com.sun.org.apache.bcel.internal.generic.BranchInstruction;
+import com.sun.org.apache.bcel.internal.generic.GOTO;
+import com.sun.org.apache.bcel.internal.generic.GOTO_W;
+
 class BcelClassWeaver implements IClassWeaver {
 
     private static Trace trace = TraceFactory.getTraceFactory().getTrace(BcelClassWeaver.class);
@@ -131,7 +121,7 @@ class BcelClassWeaver implements IClassWeaver {
 
     private final BcelObjectType  ty;    // alias of clazz.getType()
     private final BcelWorld       world; // alias of ty.getWorld()
-    private final ConstantPoolGen cpg;   // alias of clazz.getConstantPoolGen()
+    private final ConstantPool cpg;   // alias of clazz.getConstantPoolGen()
     private final InstructionFactory fact; // alias of clazz.getFactory();
 
     
@@ -174,7 +164,7 @@ class BcelClassWeaver implements IClassWeaver {
                this.typeMungers = typeMungers;
         this.lateTypeMungers = lateTypeMungers;
                this.ty = clazz.getBcelObjectType();
-               this.cpg = clazz.getConstantPoolGen();
+               this.cpg = clazz.getConstantPool();
                this.fact = clazz.getFactory();
                
                fastMatchShadowMungers(shadowMungers);
@@ -797,8 +787,8 @@ class BcelClassWeaver implements IClassWeaver {
                                }
 
                                if (annotationsToAdd==null) annotationsToAdd = new ArrayList();
-                               Annotation a = decaM.getAnnotationX().getBcelAnnotation();
-                               AnnotationGen ag = new AnnotationGen(a,clazz.getConstantPoolGen(),true);
+                               AnnotationGen a = decaM.getAnnotationX().getBcelAnnotation();
+                               AnnotationGen ag = new AnnotationGen(a,clazz.getConstantPool(),true);
                                annotationsToAdd.add(ag);
                                mg.addAnnotation(decaM.getAnnotationX());
                                
@@ -830,8 +820,8 @@ class BcelClassWeaver implements IClassWeaver {
                                        }
                                        
                                        if (annotationsToAdd==null) annotationsToAdd = new ArrayList();
-                                       Annotation a = decaM.getAnnotationX().getBcelAnnotation();
-                                       AnnotationGen ag = new AnnotationGen(a,clazz.getConstantPoolGen(),true);
+                                       AnnotationGen a = decaM.getAnnotationX().getBcelAnnotation();
+                                       AnnotationGen ag = new AnnotationGen(a,clazz.getConstantPool(),true);
                                        annotationsToAdd.add(ag);
                                        
                                        mg.addAnnotation(decaM.getAnnotationX());
@@ -847,7 +837,7 @@ class BcelClassWeaver implements IClassWeaver {
                }
                if (annotationsToAdd!=null) {
                        Method oldMethod = mg.getMethod();
-                               MethodGen myGen = new MethodGen(oldMethod,clazz.getClassName(),clazz.getConstantPoolGen(),false);// dont use tags, they won't get repaired like for woven methods.
+                               MethodGen myGen = new MethodGen(oldMethod,clazz.getClassName(),clazz.getConstantPool(),false);// dont use tags, they won't get repaired like for woven methods.
                        for (Iterator iter = annotationsToAdd.iterator(); iter.hasNext();) {
                                                AnnotationGen a = (AnnotationGen) iter.next();
                                                myGen.addAnnotation(a);                                         
@@ -1084,9 +1074,9 @@ class BcelClassWeaver implements IClassWeaver {
              return isChanged;
        }
        
-       private boolean dontAddTwice(DeclareAnnotation decaF, Annotation [] dontAddMeTwice){
+       private boolean dontAddTwice(DeclareAnnotation decaF, AnnotationX[] dontAddMeTwice){
                for (int i = 0; i < dontAddMeTwice.length; i++){
-                       Annotation ann = dontAddMeTwice[i];
+                       AnnotationX ann = dontAddMeTwice[i];
                        if (ann != null && decaF.getAnnotationX().getTypeName().equals(ann.getTypeName())){
                                //dontAddMeTwice[i] = null; // incase it really has been added twice!
                                return true;
@@ -1128,18 +1118,18 @@ class BcelClassWeaver implements IClassWeaver {
                
         List decaFs = getMatchingSubset(allDecafs,clazz.getType());
                if (decaFs.isEmpty()) return false; // nothing more to do
-               Field[] fields = clazz.getFieldGens();
+               List fields = clazz.getFieldGens();
                if (fields!=null) {
                  Set unusedDecafs = new HashSet();
                  unusedDecafs.addAll(decaFs);
-          for (int fieldCounter = 0;fieldCounter<fields.length;fieldCounter++) {
-            BcelField aBcelField = new BcelField(clazz.getBcelObjectType(),fields[fieldCounter]);
+          for (int fieldCounter = 0;fieldCounter<fields.size();fieldCounter++) {
+            BcelField aBcelField = (BcelField)fields.get(fieldCounter);//new BcelField(clazz.getBcelObjectType(),fields[fieldCounter]);
                        if (!aBcelField.getName().startsWith(NameMangler.PREFIX)) {                             
             // Single first pass
             List worthRetrying = new ArrayList();
             boolean modificationOccured = false;
             
-            Annotation [] dontAddMeTwice = fields[fieldCounter].getAnnotations();
+            AnnotationX[] dontAddMeTwice = aBcelField.getAnnotations();
             
             // go through all the declare @field statements
             for (Iterator iter = decaFs.iterator(); iter.hasNext();) {
@@ -1157,22 +1147,22 @@ class BcelClassWeaver implements IClassWeaver {
                                                if(decaF.getAnnotationX().isRuntimeVisible()){ // isAnnotationWithRuntimeRetention(clazz.getJavaClass(world))){
                                                //if(decaF.getAnnotationTypeX().isAnnotationWithRuntimeRetention(world)){                                               
                                                        // it should be runtime visible, so put it on the Field
-                                                       Annotation a = decaF.getAnnotationX().getBcelAnnotation();
-                                                       AnnotationGen ag = new AnnotationGen(a,clazz.getConstantPoolGen(),true);
-                                                       FieldGen myGen = new FieldGen(fields[fieldCounter],clazz.getConstantPoolGen());
-                                                       myGen.addAnnotation(ag);
-                                                       Field newField = myGen.getField();
+//                                                     Annotation a = decaF.getAnnotationX().getBcelAnnotation();
+//                                                     AnnotationGen ag = new AnnotationGen(a,clazz.getConstantPoolGen(),true);
+//                                                     FieldGen myGen = new FieldGen(fields[fieldCounter],clazz.getConstantPoolGen());
+//                                                     myGen.addAnnotation(ag);
+//                                                     Field newField = myGen.getField();
                                                        
                                                        aBcelField.addAnnotation(decaF.getAnnotationX());
-                                                       clazz.replaceField(fields[fieldCounter],newField);
-                                                       fields[fieldCounter]=newField;
+//                                                     clazz.replaceField(fields[fieldCounter],newField);
+//                                                     fields[fieldCounter]=newField;
                                                        
                                                } else{
                                                        aBcelField.addAnnotation(decaF.getAnnotationX());
                                                }
                                        }
                                        
-                                       AsmRelationshipProvider.getDefault().addDeclareAnnotationRelationship(decaF.getSourceLocation(),clazz.getName(),fields[fieldCounter]);
+                                       AsmRelationshipProvider.getDefault().addDeclareAnnotationRelationship(decaF.getSourceLocation(),clazz.getName(),aBcelField.getName());
                                        reportFieldAnnotationWeavingMessage(clazz, fields, fieldCounter, decaF);                
                                        isChanged = true;
                                        modificationOccured = true;
@@ -1200,7 +1190,7 @@ class BcelClassWeaver implements IClassWeaver {
                                                continue; // skip this one...
                                        }
                                        aBcelField.addAnnotation(decaF.getAnnotationX());
-                                       AsmRelationshipProvider.getDefault().addDeclareAnnotationRelationship(decaF.getSourceLocation(),clazz.getName(),fields[fieldCounter]);
+                                       AsmRelationshipProvider.getDefault().addDeclareAnnotationRelationship(decaF.getSourceLocation(),clazz.getName(),aBcelField.getName());
                                        isChanged = true;
                                        modificationOccured = true;
                                        forRemoval.add(decaF);
@@ -1268,13 +1258,13 @@ class BcelClassWeaver implements IClassWeaver {
        }
        
        // TAG: WeavingMessage
-       private void reportFieldAnnotationWeavingMessage(LazyClassGen clazz, Field[] fields, int fieldCounter, DeclareAnnotation decaF) {
+       private void reportFieldAnnotationWeavingMessage(LazyClassGen clazz, List fields, int fieldCounter, DeclareAnnotation decaF) {
                if (!getWorld().getMessageHandler().isIgnoring(IMessage.WEAVEINFO)){
-                 Field theField = fields[fieldCounter];
+                 BcelField theField = (BcelField)fields.get(fieldCounter);
                  world.getMessageHandler().handleMessage(
                          WeaveMessage.constructWeavingMessage(WeaveMessage.WEAVEMESSAGE_ANNOTATES,
                              new String[]{
-                                                 theField.toString() + "' of type '" + clazz.getName(),
+                                                 theField.getFieldAsIs().toString() + "' of type '" + clazz.getName(),
                                                  clazz.getFileName(),
                                                  decaF.getAnnotationString(),
                                                  "field",
@@ -1387,7 +1377,7 @@ class BcelClassWeaver implements IClassWeaver {
        }
 
        private boolean isThisCall(InstructionHandle ih) {
-               INVOKESPECIAL inst = (INVOKESPECIAL) ih.getInstruction();
+               InvokeInstruction inst = (InvokeInstruction) ih.getInstruction();
                return inst.getClassName(cpg).equals(clazz.getName());
        }
 
@@ -1518,7 +1508,7 @@ class BcelClassWeaver implements IClassWeaver {
                                InstructionHandle walker = body.getStart();
                                List rets = new ArrayList();
                                while (walker!=null) { 
-                                       if (walker.getInstruction() instanceof ReturnInstruction) {
+                                       if (walker.getInstruction().isReturnInstruction()) {
                                                rets.add(walker);
                                        }
                                        walker = walker.getNext();
@@ -1547,7 +1537,7 @@ class BcelClassWeaver implements IClassWeaver {
                                                                        // ignore
                                                                } else if (targeter instanceof LineNumberTag) {
                                                                        // ignore
-                                                               } else if (targeter instanceof GOTO || targeter instanceof GOTO_W) {
+                                                               } else if (targeter instanceof InstructionBranch && ((InstructionBranch)targeter).isGoto()) {
                                                                        // move it...
                                                                        targeter.updateTarget(element, monitorExitBlockStart);  
                                                                } else if (targeter instanceof BranchInstruction) {
@@ -1610,8 +1600,8 @@ class BcelClassWeaver implements IClassWeaver {
                        parttwo.append(InstructionFactory.MONITORENTER);
                
                        String fieldname = synchronizedMethod.getEnclosingClass().allocateField("class$");
-                       Field f = new FieldGen(Modifier.STATIC | Modifier.PRIVATE,
-                                   Type.getType(Class.class),fieldname,synchronizedMethod.getEnclosingClass().getConstantPoolGen()).getField();
+                       FieldGen f = new FieldGen(Modifier.STATIC | Modifier.PRIVATE,
+                                   Type.getType(Class.class),fieldname,synchronizedMethod.getEnclosingClass().getConstantPool());
                        synchronizedMethod.getEnclosingClass().addField(f, null);
                        
 //                     10:  invokestatic    #44; //Method java/lang/Class.forName:(Ljava/lang/String;)Ljava/lang/Class;
@@ -1697,7 +1687,7 @@ class BcelClassWeaver implements IClassWeaver {
                        InstructionHandle walker = body.getStart();
                        List rets = new ArrayList();
                        while (walker!=null) { //!walker.equals(body.getEnd())) {
-                               if (walker.getInstruction() instanceof ReturnInstruction) {
+                               if (walker.getInstruction().isReturnInstruction()) {
                                        rets.add(walker);
                                }
                                walker = walker.getNext();
@@ -1805,7 +1795,7 @@ class BcelClassWeaver implements IClassWeaver {
                        InstructionHandle walker = body.getStart();
                        List rets = new ArrayList();
                        while (walker!=null) { //!walker.equals(body.getEnd())) {
-                               if (walker.getInstruction() instanceof ReturnInstruction) {
+                               if (walker.getInstruction().isReturnInstruction()) {
                                        rets.add(walker);
                                }
                                walker = walker.getNext();
@@ -1835,10 +1825,10 @@ class BcelClassWeaver implements IClassWeaver {
                                                                // ignore
                                                        } else if (targeter instanceof LineNumberTag) {
                                                                // ignore
-                                                       } else if (targeter instanceof GOTO || targeter instanceof GOTO_W) {
+                                                       } else if (targeter instanceof InstructionBranch && ((InstructionBranch)targeter).isGoto()) {
                                                                // move it...
                                                                targeter.updateTarget(element, monitorExitBlockStart);
-                                                       } else if (targeter instanceof BranchInstruction) {
+                                                       } else if (targeter instanceof InstructionBranch) {
                                                                // move it
                                                                targeter.updateTarget(element, monitorExitBlockStart);
                                                        } else {
@@ -1897,8 +1887,8 @@ class BcelClassWeaver implements IClassWeaver {
                InstructionList sourceList = donor.getBody();
 
                Map srcToDest  = new HashMap();
-               ConstantPoolGen donorCpg = donor.getEnclosingClass().getConstantPoolGen();
-               ConstantPoolGen recipientCpg = recipient.getEnclosingClass().getConstantPoolGen();
+               ConstantPool donorCpg = donor.getEnclosingClass().getConstantPool();
+               ConstantPool recipientCpg = recipient.getEnclosingClass().getConstantPool();
                
                boolean isAcrossClass = donorCpg != recipientCpg;
                
@@ -1910,11 +1900,11 @@ class BcelClassWeaver implements IClassWeaver {
                {
                        Instruction fresh = Utility.copyInstruction(src.getInstruction());
                        InstructionHandle dest;
-                       if (fresh instanceof CPInstruction) {
+                       if (fresh.isConstantPoolInstruction()) {
                                // need to reset index to go to new constant pool.  This is totally
                                // a computation leak... we're testing this LOTS of times.  Sigh.
                                if (isAcrossClass) {
-                                       CPInstruction cpi = (CPInstruction) fresh;
+                                       InstructionCP cpi = (InstructionCP) fresh;
                                        cpi.setIndex(
                                                recipientCpg.addConstant(
                                                        donorCpg.getConstant(cpi.getIndex()),
@@ -1923,19 +1913,20 @@ class BcelClassWeaver implements IClassWeaver {
                        }
                        if (src.getInstruction() == Range.RANGEINSTRUCTION) {
                                dest = ret.append(Range.RANGEINSTRUCTION);
-                       } else if (fresh instanceof ReturnInstruction) {
+                       } else if (fresh.isReturnInstruction()) {
                                if (keepReturns) {
                                        dest = ret.append(fresh);
                                } else {
                                        dest = 
                                                ret.append(InstructionFactory.createBranchInstruction(Constants.GOTO, end));
                                }
-                       } else if (fresh instanceof BranchInstruction) {
-                               dest = ret.append((BranchInstruction) fresh);
+                       } else if (fresh instanceof InstructionBranch) {
+                               dest = ret.append((InstructionBranch) fresh);
                        } else if (
-                               fresh instanceof LocalVariableInstruction || fresh instanceof RET) {
-                               IndexedInstruction indexed = (IndexedInstruction) fresh;
-                               int oldIndex = indexed.getIndex();
+                               fresh.isLocalVariableInstruction() || fresh instanceof RET) {
+                               
+//                             IndexedInstruction indexed = (IndexedInstruction) fresh;
+                               int oldIndex = fresh.getIndex();
                                int freshIndex;
                                if (!frameEnv.hasKey(oldIndex)) {
                                        freshIndex = recipient.allocateLocal(2);
@@ -1943,7 +1934,7 @@ class BcelClassWeaver implements IClassWeaver {
                                } else {
                                        freshIndex = frameEnv.get(oldIndex);
                                }
-                               indexed.setIndex(freshIndex);
+                               fresh.setIndex(freshIndex);
                                dest = ret.append(fresh);
                        } else {
                                dest = ret.append(fresh);
@@ -1960,8 +1951,8 @@ class BcelClassWeaver implements IClassWeaver {
                        Instruction inst = dest.getInstruction();
                        
                        // retarget branches
-                       if (inst instanceof BranchInstruction) {
-                               BranchInstruction branch = (BranchInstruction) inst;
+                       if (inst instanceof InstructionBranch) {
+                               InstructionBranch branch = (InstructionBranch) inst;
                                InstructionHandle oldTarget = branch.getTarget();
                                InstructionHandle newTarget =
                                        (InstructionHandle) srcToDest.get(oldTarget);
@@ -1970,8 +1961,8 @@ class BcelClassWeaver implements IClassWeaver {
                                        // this was a return instruction we previously replaced
                                } else {
                                        branch.setTarget(newTarget);
-                                       if (branch instanceof Select) {
-                                               Select select = (Select) branch;
+                                       if (branch instanceof InstructionSelect) {
+                                               InstructionSelect select = (InstructionSelect) branch;
                                                InstructionHandle[] oldTargets = select.getTargets();
                                                for (int k = oldTargets.length - 1; k >= 0; k--) {
                                                        select.setTarget(
@@ -2054,7 +2045,7 @@ class BcelClassWeaver implements IClassWeaver {
                                InstructionHandle dest;
                                if (src.getInstruction() == Range.RANGEINSTRUCTION) {
                                        dest = newList.append(Range.RANGEINSTRUCTION);
-                               } else if (fresh instanceof ReturnInstruction) {
+                               } else if (fresh.isReturnInstruction()) {
                                        if (keepReturns) {
                                                newList.append(InstructionFactory.createLoad(monitorVarType,monitorVarSlot));
                                                newList.append(InstructionConstants.MONITOREXIT);
@@ -2063,12 +2054,12 @@ class BcelClassWeaver implements IClassWeaver {
                                                dest = 
                                                        newList.append(InstructionFactory.createBranchInstruction(Constants.GOTO, end));
                                        }
-                               } else if (fresh instanceof BranchInstruction) {
-                                       dest = newList.append((BranchInstruction) fresh);
+                               } else if (fresh instanceof InstructionBranch) {
+                                       dest = newList.append((InstructionBranch) fresh);
                                } else if (
-                                       fresh instanceof LocalVariableInstruction || fresh instanceof RET) {
-                                       IndexedInstruction indexed = (IndexedInstruction) fresh;
-                                       int oldIndex = indexed.getIndex();
+                                       fresh.isLocalVariableInstruction() || fresh instanceof RET) {
+                                       //IndexedInstruction indexed = (IndexedInstruction) fresh;
+                                       int oldIndex = fresh.getIndex();
                                        int freshIndex;
 //                                     if (!frameEnv.hasKey(oldIndex)) {
 //                                             freshIndex = recipient.allocateLocal(2);
@@ -2076,7 +2067,7 @@ class BcelClassWeaver implements IClassWeaver {
 //                                     } else {
                                                freshIndex = oldIndex;//frameEnv.get(oldIndex);
 //                                     }
-                                       indexed.setIndex(freshIndex);
+                                       fresh.setIndex(freshIndex);
                                        dest = newList.append(fresh);
                                } else {
                                        dest = newList.append(fresh);
@@ -2093,8 +2084,8 @@ class BcelClassWeaver implements IClassWeaver {
                                Instruction inst = dest.getInstruction();
                                
                                // retarget branches
-                               if (inst instanceof BranchInstruction) {
-                                       BranchInstruction branch = (BranchInstruction) inst;
+                               if (inst instanceof InstructionBranch) {
+                                       InstructionBranch branch = (InstructionBranch) inst;
                                        InstructionHandle oldTarget = branch.getTarget();
                                        InstructionHandle newTarget =
                                                (InstructionHandle) srcToDest.get(oldTarget);
@@ -2103,8 +2094,8 @@ class BcelClassWeaver implements IClassWeaver {
                                                // this was a return instruction we previously replaced
                                        } else {
                                                branch.setTarget(newTarget);
-                                               if (branch instanceof Select) {
-                                                       Select select = (Select) branch;
+                                               if (branch instanceof InstructionSelect) {
+                                                       InstructionSelect select = (InstructionSelect) branch;
                                                        InstructionHandle[] oldTargets = select.getTargets();
                                                        for (int k = oldTargets.length - 1; k >= 0; k--) {
                                                                select.setTarget(
@@ -2276,11 +2267,11 @@ class BcelClassWeaver implements IClassWeaver {
                        if (start == null) return null;
                        
                        Instruction inst = start.getInstruction();
-                       if (inst instanceof INVOKESPECIAL
-                               && ((INVOKESPECIAL) inst).getName(cpg).equals("<init>")) {
+                       if (inst.opcode==Constants.INVOKESPECIAL
+                               && ((InvokeInstruction) inst).getName(cpg).equals("<init>")) {
                                depth--;
                                if (depth == 0) return start;
-                       } else if (inst instanceof NEW) {
+                       } else if (inst.opcode==Constants.NEW) {
                                depth++;
                        } 
                        start = start.getNext();
@@ -2460,7 +2451,7 @@ class BcelClassWeaver implements IClassWeaver {
                ) {
                        FieldInstruction fi = (FieldInstruction) i;
                                                
-                       if (fi instanceof PUTFIELD || fi instanceof PUTSTATIC) {
+                       if (fi.opcode==Constants.PUTFIELD || fi.opcode==Constants.PUTSTATIC) {
                                // check for sets of constant fields.  We first check the previous 
                                // instruction.  If the previous instruction is a LD_WHATEVER (push
                                // constant on the stack) then we must resolve the field to determine
@@ -2489,12 +2480,12 @@ class BcelClassWeaver implements IClassWeaver {
                        }
                } else if (i instanceof InvokeInstruction) {
                        InvokeInstruction ii = (InvokeInstruction) i;
-                       if (ii.getMethodName(clazz.getConstantPoolGen()).equals("<init>")) {
+                       if (ii.getMethodName(clazz.getConstantPool()).equals("<init>")) {
                                if (canMatch(Shadow.ConstructorCall))
                                        match(
                                                        BcelShadow.makeConstructorCall(world, mg, ih, enclosingShadow),
                                                        shadowAccumulator);
-                       } else if (ii instanceof INVOKESPECIAL) {
+                       } else if (ii.opcode==Constants.INVOKESPECIAL) {
                                String onTypeName = ii.getClassName(cpg);
                                if (onTypeName.equals(mg.getEnclosingClass().getName())) {
                                        // we are private
@@ -2505,26 +2496,25 @@ class BcelClassWeaver implements IClassWeaver {
                        } else {
                                        matchInvokeInstruction(mg, ih, ii, enclosingShadow, shadowAccumulator);
                        }
-               } else if (world.isJoinpointArrayConstructionEnabled() && 
-                                  (i instanceof NEWARRAY || i instanceof ANEWARRAY || i instanceof MULTIANEWARRAY)) {
+               } else if (world.isJoinpointArrayConstructionEnabled() && i.isArrayCreationInstruction()) {
                        if (canMatch(Shadow.ConstructorCall)) {
                                boolean debug = false;
                                if (debug) System.err.println("Found new array instruction: "+i);
-                               if (i instanceof ANEWARRAY) {
-                                       ANEWARRAY arrayInstruction = (ANEWARRAY)i;
-                                       ObjectType arrayType = arrayInstruction.getLoadClassType(clazz.getConstantPoolGen());
+                               if (i.opcode==Constants.ANEWARRAY) {
+//                                     ANEWARRAY arrayInstruction = (ANEWARRAY)i;
+                                       ObjectType arrayType = i.getLoadClassType(clazz.getConstantPool());
                                        if (debug) System.err.println("Array type is "+arrayType);
                                        BcelShadow ctorCallShadow = BcelShadow.makeArrayConstructorCall(world,mg,ih,enclosingShadow);
                                        match(ctorCallShadow,shadowAccumulator);
-                               } else if (i instanceof NEWARRAY) {
-                                       NEWARRAY arrayInstruction = (NEWARRAY)i;
-                                       Type arrayType = arrayInstruction.getType();
+                               } else if (i.opcode==Constants.NEWARRAY) {
+//                                     NEWARRAY arrayInstruction = (NEWARRAY)i;
+                                       Type arrayType = i.getType();
                                        if (debug) System.err.println("Array type is "+arrayType);
                                        BcelShadow ctorCallShadow = BcelShadow.makeArrayConstructorCall(world,mg,ih,enclosingShadow);
                                        match(ctorCallShadow,shadowAccumulator);
                                } else if (i instanceof MULTIANEWARRAY) {
                                        MULTIANEWARRAY arrayInstruction = (MULTIANEWARRAY)i;
-                                       ObjectType arrayType = arrayInstruction.getLoadClassType(clazz.getConstantPoolGen());
+                                       ObjectType arrayType = arrayInstruction.getLoadClassType(clazz.getConstantPool());
                                        if (debug) System.err.println("Array type is "+arrayType);
                                        BcelShadow ctorCallShadow = BcelShadow.makeArrayConstructorCall(world,mg,ih,enclosingShadow);
                                        match(ctorCallShadow,shadowAccumulator);
@@ -2539,9 +2529,9 @@ class BcelClassWeaver implements IClassWeaver {
 //             } else if (i instanceof AASTORE) {
 //                     // ... magic required
                } else if ( world.isJoinpointSynchronizationEnabled() &&
-                                  ((i instanceof MONITORENTER) || (i instanceof MONITOREXIT))) {
+                                  ((i.getOpcode()==Constants.MONITORENTER) || (i.getOpcode()==Constants.MONITOREXIT))) {
                        // if (canMatch(Shadow.Monitoring)) {
-                         if (i instanceof MONITORENTER) {
+                         if (i.getOpcode()==Constants.MONITORENTER) {
                                  BcelShadow monitorEntryShadow = BcelShadow.makeMonitorEnter(world,mg,ih,enclosingShadow);
                                  match(monitorEntryShadow,shadowAccumulator);
                          } else {
@@ -2582,8 +2572,8 @@ class BcelClassWeaver implements IClassWeaver {
                // 'putstatic ajc$initFailureCause'.  If it is then we are 
                // in the handler we created in AspectClinit.generatePostSyntheticCode()
                InstructionHandle twoInstructionsAway = ih.getNext().getNext();
-               if (twoInstructionsAway.getInstruction() instanceof PUTSTATIC) {
-                       String name = ((PUTSTATIC)twoInstructionsAway.getInstruction()).getFieldName(cpg);
+               if (twoInstructionsAway.getInstruction().opcode==Constants.PUTSTATIC) {
+                       String name = ((FieldInstruction)twoInstructionsAway.getInstruction()).getFieldName(cpg);
                        if (name.equals(NameMangler.INITFAILURECAUSE_FIELD_NAME)) return true;
                }
                return false;
index b2a7e6b0d5369ce6f296bbae067e26ca492d2c66..8e01e76b95dcd56330f80d2013055ec0185b4373 100644 (file)
@@ -20,10 +20,12 @@ import java.util.List;
 
 import org.aspectj.apache.bcel.classfile.Attribute;
 import org.aspectj.apache.bcel.classfile.Field;
+import org.aspectj.apache.bcel.classfile.ConstantPool;
 import org.aspectj.apache.bcel.classfile.GenericSignatureParser;
 import org.aspectj.apache.bcel.classfile.Signature;
 import org.aspectj.apache.bcel.classfile.Synthetic;
-import org.aspectj.apache.bcel.classfile.annotation.Annotation;
+import org.aspectj.apache.bcel.classfile.annotation.AnnotationGen;
+import org.aspectj.apache.bcel.generic.FieldGen;
 import org.aspectj.weaver.AjAttribute;
 import org.aspectj.weaver.AnnotationX;
 import org.aspectj.weaver.BCException;
@@ -31,8 +33,10 @@ import org.aspectj.weaver.ResolvedMemberImpl;
 import org.aspectj.weaver.ResolvedType;
 import org.aspectj.weaver.UnresolvedType;
 import org.aspectj.weaver.World;
+import org.aspectj.weaver.AjAttribute.WeaverVersionInfo;
 import org.aspectj.weaver.bcel.BcelGenericSignatureToTypeXConverter.GenericSignatureFormatException;
 
+
 final class BcelField extends ResolvedMemberImpl {
 
        private static int AccSynthetic = 0x1000;
@@ -45,6 +49,8 @@ final class BcelField extends ResolvedMemberImpl {
        private BcelObjectType bcelObjectType;
        private UnresolvedType genericFieldType = null;
        private boolean unpackedGenericSignature = false;
+       private boolean annotationsAdded = false;
+       
 
        BcelField(BcelObjectType declaringType, Field field) {
                super(
@@ -59,20 +65,41 @@ final class BcelField extends ResolvedMemberImpl {
                unpackAttributes(world);
                checkedExceptions = UnresolvedType.NONE;
        }
+       
+       /**
+        * Constructs an instance that wrappers a Field object, but where we do not (yet) have
+        * a BcelObjectType - usually because the containing type (and this field) are being
+        * constructed at runtime (so there is no .class file to retrieve).  
+        */
+       BcelField(String declaringTypeName, Field field,World world) {
+               super(FIELD,UnresolvedType.forName(declaringTypeName),field.getAccessFlags(),field.getName(),field.getSignature());
+               this.field = field;
+               this.world = world;
+               this.bcelObjectType = null;
+               unpackAttributes(world);
+               checkedExceptions = UnresolvedType.NONE;
+       }
 
        // ----
        
        private void unpackAttributes(World world) {
                Attribute[] attrs = field.getAttributes();
-        List as = BcelAttributes.readAjAttributes(getDeclaringType().getClassName(),attrs, getSourceContext(world),world,bcelObjectType.getWeaverVersionAttribute());
-        as.addAll(AtAjAttributes.readAj5FieldAttributes(field, this, world.resolve(getDeclaringType()), getSourceContext(world), world.getMessageHandler()));
-
-               for (Iterator iter = as.iterator(); iter.hasNext();) {
-                       AjAttribute a = (AjAttribute) iter.next();
-                       if (a instanceof AjAttribute.AjSynthetic) {
-                               isAjSynthetic = true;
-                       } else {
-                               throw new BCException("weird field attribute " + a);
+               if (attrs!=null && attrs.length>0) {
+               List as = BcelAttributes.readAjAttributes(
+                                               getDeclaringType().getClassName(),
+                                               attrs, 
+                                               getSourceContext(world),
+                                               world,
+                                               (bcelObjectType!=null?bcelObjectType.getWeaverVersionAttribute():WeaverVersionInfo.CURRENT));
+               as.addAll(AtAjAttributes.readAj5FieldAttributes(field, this, world.resolve(getDeclaringType()), getSourceContext(world), world.getMessageHandler()));
+       
+                       for (Iterator iter = as.iterator(); iter.hasNext();) {
+                               AjAttribute a = (AjAttribute) iter.next();
+                               if (a instanceof AjAttribute.AjSynthetic) {
+                                       isAjSynthetic = true;
+                               } else {
+                                       throw new BCException("weird field attribute " + a);
+                               }
                        }
                }
                isAjSynthetic = false;
@@ -122,7 +149,7 @@ final class BcelField extends ResolvedMemberImpl {
     
        private void ensureAnnotationTypesRetrieved() {
                if (annotationTypes == null) {
-               Annotation annos[] = field.getAnnotations();
+               AnnotationGen annos[] = field.getAnnotations();
                if (annos==null || annos.length==0) {
                        annotationTypes = Collections.EMPTY_SET;
                        annotations     = AnnotationX.NONE;
@@ -130,7 +157,7 @@ final class BcelField extends ResolvedMemberImpl {
                        annotationTypes = new HashSet();
                        annotations = new AnnotationX[annos.length];
                        for (int i = 0; i < annos.length; i++) {
-                                       Annotation annotation = annos[i];
+                                       AnnotationGen annotation = annos[i];
                                        annotationTypes.add(world.resolve(UnresolvedType.forSignature(annotation.getTypeSignature())));
                                        annotations[i] = new AnnotationX(annotation,world);
                                }
@@ -152,11 +179,13 @@ final class BcelField extends ResolvedMemberImpl {
                }
                // Add it to the set of annotation types
                annotationTypes.add(UnresolvedType.forName(annotation.getTypeName()).resolve(world));
+               annotationsAdded=true;
                // FIXME asc this call here suggests we are managing the annotations at
                // too many levels, here in BcelField we keep a set and in the lower 'field'
                // object we keep a set - we should think about reducing this to one
                // level??
-               field.addAnnotation(annotation.getBcelAnnotation());
+               //field.addAnnotation(annotation.getBcelAnnotation());
+               // FIXME CUSTARD
        }
        
        /**
@@ -168,6 +197,29 @@ final class BcelField extends ResolvedMemberImpl {
                return genericFieldType;
        }
        
+       public Field getFieldAsIs() { return field; }
+       
+       // FIXME asc badly performing code ftw !
+       public Field getField(ConstantPool cpg) { 
+               if (!annotationsAdded) return field;
+               FieldGen fg = new FieldGen(field,cpg);
+               AnnotationGen[] alreadyHas = fg.getAnnotations();
+               if (annotations!=null) {
+                       for (int i = 0; i < annotations.length; i++) {
+                               AnnotationX array_element = annotations[i];
+                               boolean alreadyHasIt = false;
+                               for (int j = 0; j < alreadyHas.length; j++) {
+                                       AnnotationGen gen = alreadyHas[j];
+                                       if (gen.getTypeName().equals(array_element.getTypeName())) alreadyHasIt = true;
+                               }
+                               if (!alreadyHasIt) fg.addAnnotation(new AnnotationGen(array_element.getBcelAnnotation(),cpg,true));     
+                       }
+        }
+           field = fg.getField();
+           annotationsAdded = false; // we are now correct again
+        return field;
+       }
+       
        private void unpackGenericSignature() {
                if (unpackedGenericSignature) { return; }
                if (!world.isInJava5Mode()) {
index 13839f41a83d8963cccbccabbddd02500cc46cc6..bea01fba57902cdfdc545fc6d9b1063688d9307b 100644 (file)
@@ -30,13 +30,14 @@ import org.aspectj.apache.bcel.classfile.LocalVariableTable;
 import org.aspectj.apache.bcel.classfile.Method;
 import org.aspectj.apache.bcel.classfile.Signature;
 import org.aspectj.apache.bcel.classfile.Signature.TypeVariableSignature;
-import org.aspectj.apache.bcel.classfile.annotation.Annotation;
+import org.aspectj.apache.bcel.classfile.annotation.AnnotationGen;
 import org.aspectj.bridge.ISourceLocation;
 import org.aspectj.bridge.SourceLocation;
 import org.aspectj.weaver.AjAttribute;
 import org.aspectj.weaver.AnnotationX;
 import org.aspectj.weaver.BCException;
 import org.aspectj.weaver.ISourceContext;
+import org.aspectj.weaver.Member;
 import org.aspectj.weaver.ResolvedMemberImpl;
 import org.aspectj.weaver.ResolvedPointcutDefinition;
 import org.aspectj.weaver.ResolvedType;
@@ -45,31 +46,62 @@ import org.aspectj.weaver.TypeVariable;
 import org.aspectj.weaver.UnresolvedType;
 import org.aspectj.weaver.World;
 import org.aspectj.weaver.bcel.BcelGenericSignatureToTypeXConverter.GenericSignatureFormatException;
+import java.util.*;
 
 public final class BcelMethod extends ResolvedMemberImpl {
 
        private Method method;
-       private boolean isAjSynthetic;
-       private boolean isSynthetic;
-       private boolean knowIfSynthetic = false;
-       private ShadowMunger associatedShadowMunger;
-       private ResolvedPointcutDefinition preResolvedPointcut;  // used when ajc has pre-resolved the pointcut of some @Advice
-       
-//    private ResolvedType[] annotationTypes = null;
-    private AnnotationX[] annotations = null;
-       
-       private AjAttribute.EffectiveSignatureAttribute effectiveSignature;
-       private AjAttribute.MethodDeclarationLineNumberAttribute declarationLineNumber;
-       private World world;
+//     private AjAttribute.MethodDeclarationLineNumberAttribute declarationLineNumber;
+//     private World world;
        private BcelObjectType bcelObjectType;
+
+       public Member slimline() {
+               if (!bcelObjectType.getWorld().isXnoInline()) return this;
+               ResolvedMemberImpl mi = new ResolvedMemberImpl(kind,declaringType,modifiers,returnType,name,parameterTypes);
+               mi.setParameterNames(getParameterNames());
+               return mi;
+       }
+
+//    private AnnotationX[] annotations = null;
+//     private UnresolvedType genericReturnType = null;
+//     private UnresolvedType[] genericParameterTypes = null;
        
-       private boolean parameterNamesInitialized = false;
+       private Map metaData = null;
+       // keys into the meta data
+       private static final String MAPKEY_EFFECTIVE_SIGNATURE     ="effectiveSignature";
+       private static final String MAPKEY_PRERESOLVED_POINTCUT    ="preresolvedPointcut";
+       private static final String MAPKEY_ASSOCIATED_SHADOWMUNGER ="associatedShadowmunger";
+       private static final String MAPKEY_GENERIC_RETURN_TYPE     ="genericReturnType";
+       private static final String MAPKEY_GENERIC_PARAM_TYPES     ="genericParameterTypes";
+       private static final String MAPKEY_ANNOTATIONS             ="annotations";
+       private static final String MAPKEY_MD_LINE_NUMBER_ATTRIBUTE="mdLineNumberAttribute";
 
-        private boolean canBeParameterized = false;
-        // genericized version of return and parameter types
-        private boolean unpackedGenericSignature = false;
-        private UnresolvedType genericReturnType = null;
-        private UnresolvedType[] genericParameterTypes = null;
+//     private AjAttribute.EffectiveSignatureAttribute effectiveSignature;
+//     private ShadowMunger associatedShadowMunger;
+//     private ResolvedPointcutDefinition preResolvedPointcut;  // used when ajc has pre-resolved the pointcut of some @Advice 
+
+       private int bitflags;
+       private static final int KNOW_IF_SYNTHETIC           = 0x0001;
+       private static final int PARAMETER_NAMES_INITIALIZED = 0x0002;
+       private static final int CAN_BE_PARAMETERIZED        = 0x0004;
+       private static final int UNPACKED_GENERIC_SIGNATURE  = 0x0008;
+       private static final int HAS_EFFECTIVE_SIGNATURE     = 0x0010;
+       private static final int HAS_PRERESOLVED_POINTCUT    = 0x0020;
+       private static final int IS_AJ_SYNTHETIC             = 0x0040;
+       private static final int IS_SYNTHETIC                = 0x0080;
+       private static final int IS_SYNTHETIC_INVERSE        = 0x7f7f; // all bits but IS_SYNTHETIC (and topmost bit)
+       private static final int HAS_ASSOCIATED_SHADOWMUNGER = 0x0100;
+       private static final int HAS_GENERIC_RETPARAM_TYPES  = 0x0200;
+       private static final int HAS_ANNOTATIONS             = 0x0400;
+       private static final int HAVE_DETERMINED_ANNOTATIONS = 0x0800;
+       private static final int HAS_MD_LINE_NUMBER_ATTRIBUTE= 0x1000;
+       
+//     private boolean isAjSynthetic;
+//     private boolean isSynthetic;
+//     private boolean knowIfSynthetic = false;
+//     private boolean parameterNamesInitialized = false;
+//  private boolean canBeParameterized = false; 
+//     private boolean unpackedGenericSignature = false;
 
        BcelMethod(BcelObjectType declaringType, Method method) {
                super(
@@ -83,10 +115,10 @@ public final class BcelMethod extends ResolvedMemberImpl {
                        method.getSignature());
                this.method = method;
                this.sourceContext = declaringType.getResolvedTypeX().getSourceContext();
-               this.world = declaringType.getResolvedTypeX().getWorld();
+               //this.world = declaringType.getResolvedTypeX().getWorld();
                this.bcelObjectType = declaringType;
                unpackJavaAttributes();
-               unpackAjAttributes(world);
+               unpackAjAttributes(bcelObjectType.getWorld());
        }
 
        // ----
@@ -113,8 +145,10 @@ public final class BcelMethod extends ResolvedMemberImpl {
     }
        
        public void determineParameterNames() {
-               if (parameterNamesInitialized) return;
-               parameterNamesInitialized=true;
+               if ((bitflags&PARAMETER_NAMES_INITIALIZED)!=0) return;
+               bitflags|=PARAMETER_NAMES_INITIALIZED;
+//             if (parameterNamesInitialized) return;
+//             parameterNamesInitialized=true;
                LocalVariableTable varTable = method.getLocalVariableTable();
                int len = getArity();
                if (varTable == null) {
@@ -137,10 +171,10 @@ public final class BcelMethod extends ResolvedMemberImpl {
        }
 
        private void unpackAjAttributes(World world) {
-               associatedShadowMunger = null;
+//             associatedShadowMunger = null;
         List as = BcelAttributes.readAjAttributes(getDeclaringType().getClassName(),method.getAttributes(), getSourceContext(world),world,bcelObjectType.getWeaverVersionAttribute());
                processAttributes(world, as);
-               as = AtAjAttributes.readAj5MethodAttributes(method, this, world.resolve(getDeclaringType()), preResolvedPointcut,getSourceContext(world), world.getMessageHandler());
+               as = AtAjAttributes.readAj5MethodAttributes(method, this, world.resolve(getDeclaringType()), getPreResolvedPointcutDefinition(),getSourceContext(world), world.getMessageHandler());
                processAttributes(world,as);
        }
 
@@ -148,28 +182,42 @@ public final class BcelMethod extends ResolvedMemberImpl {
                for (Iterator iter = as.iterator(); iter.hasNext();) {
                        AjAttribute a = (AjAttribute) iter.next();
                        if (a instanceof AjAttribute.MethodDeclarationLineNumberAttribute) {
-                               declarationLineNumber = (AjAttribute.MethodDeclarationLineNumberAttribute)a;
+                               addMetaData(MAPKEY_MD_LINE_NUMBER_ATTRIBUTE,a);
+                               bitflags|=HAS_MD_LINE_NUMBER_ATTRIBUTE;
+//                             declarationLineNumber = (AjAttribute.MethodDeclarationLineNumberAttribute)a;
                        } else if (a instanceof AjAttribute.AdviceAttribute) {
-                               associatedShadowMunger = ((AjAttribute.AdviceAttribute)a).reify(this, world);
+                               bitflags|=HAS_ASSOCIATED_SHADOWMUNGER;
+                               addMetaData(MAPKEY_ASSOCIATED_SHADOWMUNGER,((AjAttribute.AdviceAttribute)a).reify(this, world));
+//                             associatedShadowMunger = ((AjAttribute.AdviceAttribute)a).reify(this, world);
                                // return;
                        } else if (a instanceof AjAttribute.AjSynthetic) {
-                               isAjSynthetic = true;
+                               bitflags|=IS_AJ_SYNTHETIC;
+//                             isAjSynthetic = true;
                        } else if (a instanceof AjAttribute.EffectiveSignatureAttribute) {
-                               //System.out.println("found effective: " + this);
-                               effectiveSignature = (AjAttribute.EffectiveSignatureAttribute)a;
+                               // System.out.println("found effective: " + this);
+                               bitflags|=HAS_EFFECTIVE_SIGNATURE;
+                               addMetaData(MAPKEY_EFFECTIVE_SIGNATURE,a);
+//                             effectiveSignature = (AjAttribute.EffectiveSignatureAttribute)a;
                        } else if (a instanceof AjAttribute.PointcutDeclarationAttribute) {
                                // this is an @AspectJ annotated advice method, with pointcut pre-resolved by ajc
-                               preResolvedPointcut = ((AjAttribute.PointcutDeclarationAttribute)a).reify();
+                               bitflags|=HAS_PRERESOLVED_POINTCUT;
+                               addMetaData(MAPKEY_PRERESOLVED_POINTCUT,((AjAttribute.PointcutDeclarationAttribute)a).reify());
+//                             preResolvedPointcut = ((AjAttribute.PointcutDeclarationAttribute)a).reify();
                        } else {
                                throw new BCException("weird method attribute " + a);
                        }
                }
        }
        
+       private void addMetaData(String k,Object v) {
+               if (metaData==null) { metaData = new HashMap();}
+               metaData.put(k,v);
+       }
+       
        // 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(getDeclaringType().getClassName(),method.getAttributes(), getSourceContext(world),world,bcelObjectType.getWeaverVersionAttribute());
+               List l = BcelAttributes.readAjAttributes(getDeclaringType().getClassName(),method.getAttributes(), getSourceContext(bcelObjectType.getWorld()),bcelObjectType.getWorld(),bcelObjectType.getWeaverVersionAttribute());
                for (Iterator iter = l.iterator(); iter.hasNext();) {
                        AjAttribute element = (AjAttribute) iter.next();                
                        if (element.getNameString().equals(name)) results.add(element);
@@ -193,37 +241,56 @@ public final class BcelMethod extends ResolvedMemberImpl {
        }
 
        public boolean isAjSynthetic() {
-               return isAjSynthetic; // || getName().startsWith(NameMangler.PREFIX);
+               return (bitflags&IS_AJ_SYNTHETIC)!=0;//isAjSynthetic; // || getName().startsWith(NameMangler.PREFIX);
        }
        
        //FIXME ??? needs an isSynthetic method
        
        public ShadowMunger getAssociatedShadowMunger() {
-               return associatedShadowMunger;
+               if ((bitflags&HAS_ASSOCIATED_SHADOWMUNGER)==0) return null;
+               return (ShadowMunger)metaData.get(MAPKEY_ASSOCIATED_SHADOWMUNGER);
+//             return associatedShadowMunger;
        }
        
        public AjAttribute.EffectiveSignatureAttribute getEffectiveSignature() {
-               return effectiveSignature;
+               if ((bitflags&HAS_EFFECTIVE_SIGNATURE)==0) return null;
+               return (AjAttribute.EffectiveSignatureAttribute)metaData.get(MAPKEY_EFFECTIVE_SIGNATURE);//effectiveSignature;
+       }
+
+       public ResolvedPointcutDefinition getPreResolvedPointcutDefinition() {
+               if ((bitflags&HAS_PRERESOLVED_POINTCUT)==0) return null;
+               return (ResolvedPointcutDefinition)metaData.get(MAPKEY_PRERESOLVED_POINTCUT);//effectiveSignature;
        }
        
        public boolean hasDeclarationLineNumberInfo() {
-               return declarationLineNumber != null;
+               return ((bitflags&HAS_MD_LINE_NUMBER_ATTRIBUTE)!=0);
+//             return declarationLineNumber != null;
        }
        
        public int getDeclarationLineNumber() {
-               if (declarationLineNumber != null) {
-                       return declarationLineNumber.getLineNumber();
-               } else {
-                       return -1;
+               if ((bitflags&HAS_MD_LINE_NUMBER_ATTRIBUTE)!=0) {
+                       AjAttribute.MethodDeclarationLineNumberAttribute mdlna = (AjAttribute.MethodDeclarationLineNumberAttribute)metaData.get(MAPKEY_MD_LINE_NUMBER_ATTRIBUTE);
+                       return mdlna.getLineNumber();
                }
+               return -1;
+//             if (declarationLineNumber != null) {
+//                     return declarationLineNumber.getLineNumber();
+//             } else {
+//                     return -1;
+//             }
        }
 
     public int getDeclarationOffset() {
-        if (declarationLineNumber != null) {
-            return declarationLineNumber.getOffset();
-        } else {
-            return -1;
-        }
+       if ((bitflags&HAS_MD_LINE_NUMBER_ATTRIBUTE)!=0) {
+                       AjAttribute.MethodDeclarationLineNumberAttribute mdlna = (AjAttribute.MethodDeclarationLineNumberAttribute)metaData.get(MAPKEY_MD_LINE_NUMBER_ATTRIBUTE);
+                       return mdlna.getOffset();
+               }
+               return -1;
+//        if (declarationLineNumber != null) {
+//            return declarationLineNumber.getOffset();
+//        } else {
+//            return -1;
+//        }
     }
 
     public ISourceLocation getSourceLocation() {
@@ -238,7 +305,7 @@ public final class BcelMethod extends ResolvedMemberImpl {
     }
        
        public Kind getKind() {
-               if (associatedShadowMunger != null) {
+               if ((bitflags&HAS_ASSOCIATED_SHADOWMUNGER)!=0) {
                        return ADVICE;
                } else {
                        return super.getKind();
@@ -256,7 +323,12 @@ public final class BcelMethod extends ResolvedMemberImpl {
        
        public AnnotationX[] getAnnotations() {
                ensureAnnotationTypesRetrieved();
-               return annotations;
+               if ((bitflags&HAS_ANNOTATIONS)!=0) {
+                       return (AnnotationX[])metaData.get(MAPKEY_ANNOTATIONS);
+               } else {
+                       return AnnotationX.NONE;
+               }
+//             return annotations;
        }
        
         public ResolvedType[] getAnnotationTypes() {
@@ -268,32 +340,51 @@ public final class BcelMethod extends ResolvedMemberImpl {
         
         public void addAnnotation(AnnotationX annotation) {
            ensureAnnotationTypesRetrieved();   
-               // Add it to the set of annotations
-               int len = annotations.length;
-               AnnotationX[] ret = new AnnotationX[len+1];
-               System.arraycopy(annotations, 0, ret, 0, len);
-               ret[len] = annotation;
-               annotations = ret;
+           if ((bitflags&HAS_ANNOTATIONS)==0) {
+                       AnnotationX[] ret = new AnnotationX[1];
+                       ret[0]=annotation;
+                       addMetaData(MAPKEY_ANNOTATIONS,ret);
+           } else {
+                       // Add it to the set of annotations
+               AnnotationX[] annotations = (AnnotationX[])metaData.get(MAPKEY_ANNOTATIONS);
+                       int len = annotations.length;
+                       AnnotationX[] ret = new AnnotationX[len+1];
+                       System.arraycopy(annotations, 0, ret, 0, len);
+                       ret[len] = annotation;
+                       addMetaData(MAPKEY_ANNOTATIONS,ret);
+//                     annotations = ret;
+           }
+           bitflags|=HAS_ANNOTATIONS;
                
                // Add it to the set of annotation types
-               annotationTypes.add(UnresolvedType.forName(annotation.getTypeName()).resolve(world));
+           if (annotationTypes==Collections.EMPTY_SET) annotationTypes = new HashSet();
+               annotationTypes.add(UnresolvedType.forName(annotation.getTypeName()).resolve(bcelObjectType.getWorld()));
                // FIXME asc looks like we are managing two 'bunches' of annotations, one
                // here and one in the real 'method' - should we reduce it to one layer?
-               method.addAnnotation(annotation.getBcelAnnotation());
+//             method.addAnnotation(annotation.getBcelAnnotation());
+               // FIXME CUSTARD
         }
         
         private void ensureAnnotationTypesRetrieved() {
                if (method == null) return; // must be ok, we have evicted it
-               if (annotationTypes == null || method.getAnnotations().length!=annotations.length) { // sometimes the list changes underneath us!
-               Annotation annos[] = method.getAnnotations();
-               annotationTypes = new HashSet();
-               annotations = new AnnotationX[annos.length];
-               for (int i = 0; i < annos.length; i++) {
-                               Annotation annotation = annos[i];
-                               annotationTypes.add(world.resolve(UnresolvedType.forSignature(annotation.getTypeSignature())));
-                               annotations[i] = new AnnotationX(annotation,world);
-                       }
+               if ((bitflags&HAVE_DETERMINED_ANNOTATIONS)!=0) return;
+               bitflags|=HAVE_DETERMINED_ANNOTATIONS;
+//             if (annotationTypes == null) {// || method.getAnnotations().length!=annotations.length) { // sometimes the list changes underneath us!
+               AnnotationGen annos[] = method.getAnnotations();
+               if (annos.length!=0) {
+                       annotationTypes = new HashSet();
+                       AnnotationX[] annotations = new AnnotationX[annos.length];
+                       for (int i = 0; i < annos.length; i++) {
+                                       AnnotationGen annotation = annos[i];
+                                       annotationTypes.add(bcelObjectType.getWorld().resolve(UnresolvedType.forSignature(annotation.getTypeSignature())));
+                                       annotations[i] = new AnnotationX(annotation,bcelObjectType.getWorld());
+                               }
+                       addMetaData(MAPKEY_ANNOTATIONS,annotations);
+                       bitflags|=HAS_ANNOTATIONS;
+               } else {
+                       annotationTypes=Collections.EMPTY_SET;
                }
+//             }
        }
         
 
@@ -304,29 +395,36 @@ public final class BcelMethod extends ResolvedMemberImpl {
          */
         public boolean canBeParameterized() {
                 unpackGenericSignature();
-               return canBeParameterized;
+               return (bitflags&CAN_BE_PARAMETERIZED)!=0;//canBeParameterized;
        }
         
         
         public UnresolvedType[] getGenericParameterTypes() {
                 unpackGenericSignature();
-                return genericParameterTypes;
+                if ((bitflags&HAS_GENERIC_RETPARAM_TYPES)==0) return getParameterTypes();
+                return (UnresolvedType[])metaData.get(MAPKEY_GENERIC_PARAM_TYPES);
+//              return genericParameterTypes;
         }
         
         public UnresolvedType getGenericReturnType() {
                 unpackGenericSignature();
-                return genericReturnType;
+                if ((bitflags&HAS_GENERIC_RETPARAM_TYPES)==0) return getReturnType();
+                return (UnresolvedType)metaData.get(MAPKEY_GENERIC_RETURN_TYPE);
+//              return genericReturnType;
         }
         
         /** For testing only */
         public Method getMethod() { return method; }
         
         private void unpackGenericSignature() {
-                if (unpackedGenericSignature) return;
-                unpackedGenericSignature = true;
-                if (!world.isInJava5Mode()) { 
-                        this.genericReturnType = getReturnType();
-                        this.genericParameterTypes = getParameterTypes();
+               if ((bitflags&UNPACKED_GENERIC_SIGNATURE)!=0) return;
+               bitflags|=UNPACKED_GENERIC_SIGNATURE;
+//              if (unpackedGenericSignature) return;
+//              unpackedGenericSignature = true;
+                if (!bcelObjectType.getWorld().isInJava5Mode()) { 
+                        
+//                      this.genericReturnType = getReturnType();
+//                      this.genericParameterTypes = getParameterTypes();
                         return;
                 }
                 String gSig = method.getGenericSignature();
@@ -334,7 +432,8 @@ public final class BcelMethod extends ResolvedMemberImpl {
                         Signature.MethodTypeSignature mSig = new GenericSignatureParser().parseAsMethodSignature(gSig);//method.getGenericSignature());
                         if (mSig.formalTypeParameters.length > 0) {
                                // generic method declaration
-                               canBeParameterized = true;
+                               bitflags|=CAN_BE_PARAMETERIZED;
+//                             canBeParameterized = true;
                         }
                         
                        typeVariables = new TypeVariable[mSig.formalTypeParameters.length];
@@ -344,7 +443,7 @@ public final class BcelMethod extends ResolvedMemberImpl {
                                        typeVariables[i] = BcelGenericSignatureToTypeXConverter.formalTypeParameter2TypeVariable(
                                                        methodFtp, 
                                                        mSig.formalTypeParameters,
-                                                       world);
+                                                       bcelObjectType.getWorld());
                                } catch (GenericSignatureFormatException e) {
                                        // this is a development bug, so fail fast with good info
                                        throw new IllegalStateException(
@@ -361,10 +460,13 @@ public final class BcelMethod extends ResolvedMemberImpl {
                         System.arraycopy(mSig.formalTypeParameters,0,formals,0,mSig.formalTypeParameters.length);
                         System.arraycopy(parentFormals,0,formals,mSig.formalTypeParameters.length,parentFormals.length);
                         Signature.TypeSignature returnTypeSignature = mSig.returnType;
+                        bitflags|=HAS_GENERIC_RETPARAM_TYPES;
+                        UnresolvedType genericReturnType = null;
+                        UnresolvedType[] genericParameterTypes = null;
                         try {
                                genericReturnType = BcelGenericSignatureToTypeXConverter.typeSignature2TypeX(
                                                 returnTypeSignature, formals,
-                                                world);
+                                                bcelObjectType.getWorld());
                        } catch (GenericSignatureFormatException e) {
 //                              development bug, fail fast with good info
                                throw new IllegalStateException(
@@ -378,7 +480,7 @@ public final class BcelMethod extends ResolvedMemberImpl {
                                try {
                                        genericParameterTypes[i] = 
                                                BcelGenericSignatureToTypeXConverter.typeSignature2TypeX(
-                                                               paramTypeSigs[i],formals,world);
+                                                               paramTypeSigs[i],formals,bcelObjectType.getWorld());
                                } catch (GenericSignatureFormatException e) {
 //                                      development bug, fail fast with good info
                                        throw new IllegalStateException(
@@ -387,13 +489,18 @@ public final class BcelMethod extends ResolvedMemberImpl {
                                                        + e.getMessage());
                                }
                                if (paramTypeSigs[i] instanceof TypeVariableSignature) {
-                                       canBeParameterized = true;
+                                       bitflags|=CAN_BE_PARAMETERIZED;
+//                                     canBeParameterized = true;
                                }
                         }
-                } else {
-                        genericReturnType = getReturnType();
-                        genericParameterTypes = getParameterTypes();
-                }
+                        addMetaData(MAPKEY_GENERIC_PARAM_TYPES, genericParameterTypes);
+                        addMetaData(MAPKEY_GENERIC_RETURN_TYPE, genericReturnType);
+                        bitflags|=HAS_GENERIC_RETPARAM_TYPES;
+                } 
+//              else {
+//                      genericReturnType = getReturnType();
+//                      genericParameterTypes = getParameterTypes();
+//              }
         }
         
         public void evictWeavingState() {
@@ -408,27 +515,38 @@ public final class BcelMethod extends ResolvedMemberImpl {
         }
 
        public boolean isSynthetic() {
-               if (!knowIfSynthetic) workOutIfSynthetic();
-               return isSynthetic;
+               if ((bitflags&KNOW_IF_SYNTHETIC)==0) {
+                       workOutIfSynthetic();
+               }
+               return (bitflags&IS_SYNTHETIC)!=0;//isSynthetic;
        }
 
        // Pre Java5 synthetic is an attribute 'Synthetic', post Java5 it is a modifier (4096 or 0x1000)
        private void workOutIfSynthetic() {
-               knowIfSynthetic=true;
+               if ((bitflags&KNOW_IF_SYNTHETIC)!=0) return;
+               bitflags|=KNOW_IF_SYNTHETIC;
+//             knowIfSynthetic=true;
                JavaClass jc = bcelObjectType.getJavaClass();
-               isSynthetic=false;
+           bitflags&=IS_SYNTHETIC_INVERSE; // unset the bit
+//             isSynthetic=false;
                if (jc==null) return; // what the hell has gone wrong?
                if (jc.getMajor()<49/*Java5*/) {
                        // synthetic is an attribute
                        String[] synthetics =  getAttributeNames(false);
                        if (synthetics!=null) {
                                for (int i = 0; i < synthetics.length; i++) {
-                                       if (synthetics[i].equals("Synthetic")) {isSynthetic=true;break;}
+                                       if (synthetics[i].equals("Synthetic")) {
+                                               bitflags|=IS_SYNTHETIC;
+//                                             isSynthetic=true;
+                                               break;}
                                }
                        }
                } else {
                        // synthetic is a modifier (4096)
-                       isSynthetic = (modifiers&4096)!=0;
+                       if ((modifiers&4096)!=0) {
+                               bitflags|=IS_SYNTHETIC;
+                       }
+//                     isSynthetic = (modifiers&4096)!=0;
                }
        }
 
index 6943339679ca1895042d91c7bfc6340a47a6c601..ee8da45f5eaba1bda08fa6968081a3fa55800ba2 100644 (file)
@@ -22,14 +22,15 @@ import java.util.Iterator;
 import java.util.List;
 
 import org.aspectj.apache.bcel.classfile.Attribute;
+import org.aspectj.apache.bcel.classfile.AttributeUtils;
 import org.aspectj.apache.bcel.classfile.Field;
 import org.aspectj.apache.bcel.classfile.JavaClass;
 import org.aspectj.apache.bcel.classfile.Method;
 import org.aspectj.apache.bcel.classfile.Signature;
-import org.aspectj.apache.bcel.classfile.annotation.Annotation;
-import org.aspectj.apache.bcel.classfile.annotation.ArrayElementValue;
-import org.aspectj.apache.bcel.classfile.annotation.ElementNameValuePair;
-import org.aspectj.apache.bcel.classfile.annotation.ElementValue;
+import org.aspectj.apache.bcel.classfile.annotation.AnnotationGen;
+import org.aspectj.apache.bcel.classfile.annotation.ArrayElementValueGen;
+import org.aspectj.apache.bcel.classfile.annotation.ElementNameValuePairGen;
+import org.aspectj.apache.bcel.classfile.annotation.ElementValueGen;
 import org.aspectj.bridge.IMessageHandler;
 import org.aspectj.weaver.AbstractReferenceTypeDelegate;
 import org.aspectj.weaver.AjAttribute;
@@ -37,6 +38,7 @@ import org.aspectj.weaver.AjcMemberMaker;
 import org.aspectj.weaver.AnnotationTargetKind;
 import org.aspectj.weaver.AnnotationX;
 import org.aspectj.weaver.BCException;
+import org.aspectj.weaver.ISourceContext;
 import org.aspectj.weaver.ReferenceType;
 import org.aspectj.weaver.ResolvedMember;
 import org.aspectj.weaver.ResolvedPointcutDefinition;
@@ -132,19 +134,27 @@ public class BcelObjectType extends AbstractReferenceTypeDelegate {
         // @AJ pc refs annotation in class hierarchy
         resolvedTypeX.setDelegate(this);
 
-        if (resolvedTypeX.getSourceContext()==SourceContextImpl.UNKNOWN_SOURCE_CONTEXT) {
-           setSourceContext(new SourceContextImpl(this));
+        ISourceContext sourceContext = resolvedTypeX.getSourceContext();
+        if (sourceContext==SourceContextImpl.UNKNOWN_SOURCE_CONTEXT) {
+           sourceContext = new SourceContextImpl(this);
+           setSourceContext(sourceContext);
         }
         
         // this should only ever be java.lang.Object which is 
         // the only class in Java-1.4 with no superclasses
         isObject = (javaClass.getSuperclassNameIndex() == 0);
         ensureAspectJAttributesUnpacked();
+//        if (sourceContext instanceof SourceContextImpl) {
+//             ((SourceContextImpl)sourceContext).setSourceFileName(javaClass.getSourceFileName());
+//        }
         setSourcefilename(javaClass.getSourceFileName());
+        
     }
     
     // repeat initialization
     public void setJavaClass(JavaClass newclass) {
+//     if (this.getResolvedTypeX().isAspect())
+//     new RuntimeException("bcot: "+this.hashCode()+" Set javaclass for aspect").printStackTrace();
        this.javaClass = newclass;
        resetState();
        initializeFromJavaclass();
@@ -191,6 +201,10 @@ public class BcelObjectType extends AbstractReferenceTypeDelegate {
         ResolvedType res =     getResolvedTypeX().getWorld().resolve(UnresolvedType.forSignature(superclassSignature));
        return res;
     }
+    
+    public World getWorld() {
+       return getResolvedTypeX().getWorld();
+    }
         
     /**
      * Retrieves the declared interfaces - this allows for the generic signature on a type.  If specified
@@ -356,6 +370,8 @@ public class BcelObjectType extends AbstractReferenceTypeDelegate {
                                if (getResolvedTypeX().getSourceContext() instanceof SourceContextImpl) {
                                        AjAttribute.SourceContextAttribute sca = (AjAttribute.SourceContextAttribute)a;
                                        ((SourceContextImpl)getResolvedTypeX().getSourceContext()).configureFromAttribute(sca.getSourceFileName(),sca.getLineBreaks());
+                                       
+                                       setSourcefilename(sca.getSourceFileName());
                                }
                        } else if (a instanceof AjAttribute.WeaverVersionInfo) {
                                wvInfo = (AjAttribute.WeaverVersionInfo)a; // Set the weaver version used to build this type
@@ -466,7 +482,7 @@ public class BcelObjectType extends AbstractReferenceTypeDelegate {
     public LazyClassGen getLazyClassGen() {
        LazyClassGen ret = lazyClassGen;
        if (ret == null) {
-               //System.err.println("creating lazy class gen for: " + this);
+//             System.err.println("creating lazy class gen for: " + this);
                ret = new LazyClassGen(this);
                //ret.print(System.err);
                //System.err.println("made LCG from : " + this.getJavaClass().getSuperclassName );
@@ -566,8 +582,8 @@ public class BcelObjectType extends AbstractReferenceTypeDelegate {
                                        if (ax.getTypeName().equals(UnresolvedType.AT_RETENTION.getName())) {
                                List values = ax.getBcelAnnotation().getValues();
                                for (Iterator it = values.iterator(); it.hasNext();) {
-                               ElementNameValuePair element = (ElementNameValuePair) it.next();
-                               ElementValue v = element.getValue();
+                               ElementNameValuePairGen element = (ElementNameValuePairGen) it.next();
+                               ElementValueGen v = element.getValue();
                                retentionPolicy = v.stringifyValue();
                                return retentionPolicy;
                            }
@@ -595,12 +611,12 @@ public class BcelObjectType extends AbstractReferenceTypeDelegate {
                annotationTargetKinds = null; // null means we have no idea or the @Target annotation hasn't been used
                List targetKinds = new ArrayList();
                if (isAnnotation()) {
-               Annotation[] annotationsOnThisType = javaClass.getAnnotations();
+               AnnotationGen[] annotationsOnThisType = javaClass.getAnnotations();
                for (int i = 0; i < annotationsOnThisType.length; i++) {
-                   Annotation a = annotationsOnThisType[i];
+                   AnnotationGen a = annotationsOnThisType[i];
                    if (a.getTypeName().equals(UnresolvedType.AT_TARGET.getName())) {
-                       ArrayElementValue arrayValue = (ArrayElementValue)((ElementNameValuePair)a.getValues().get(0)).getValue();
-                       ElementValue[] evs = arrayValue.getElementValuesArray();
+                       ArrayElementValueGen arrayValue = (ArrayElementValueGen)((ElementNameValuePairGen)a.getValues().get(0)).getValue();
+                       ElementValueGen[] evs = arrayValue.getElementValuesArray();
                        if (evs!=null) {
                                for (int j = 0; j < evs.length; j++) {
                                                        String targetKind = evs[j].stringifyValue();
@@ -628,7 +644,7 @@ public class BcelObjectType extends AbstractReferenceTypeDelegate {
        
        private void ensureAnnotationsUnpacked() {
                if (annotationTypes == null) {
-               Annotation annos[] = javaClass.getAnnotations();
+               AnnotationGen annos[] = javaClass.getAnnotations();
                if (annos==null || annos.length==0) {
                        annotationTypes = ResolvedType.NONE;
                        annotations     = AnnotationX.NONE;
@@ -637,7 +653,7 @@ public class BcelObjectType extends AbstractReferenceTypeDelegate {
                        annotationTypes = new ResolvedType[annos.length];
                        annotations     = new AnnotationX[annos.length];
                        for (int i = 0; i < annos.length; i++) {
-                                       Annotation annotation = annos[i];
+                                       AnnotationGen annotation = annos[i];
                                        annotationTypes[i] = w.resolve(UnresolvedType.forSignature(annotation.getTypeSignature()));
                                        annotations[i]     = new AnnotationX(annotation,w);
                                }
@@ -749,11 +765,8 @@ public class BcelObjectType extends AbstractReferenceTypeDelegate {
        private void ensureGenericInfoProcessed() { 
                if ((bitflag & DISCOVERED_DECLARED_SIGNATURE)!=0) return;
                bitflag |= DISCOVERED_DECLARED_SIGNATURE;
-               Attribute[] as = javaClass.getAttributes();
-               for (int i = 0; i < as.length && declaredSignature==null; i++) {
-                       Attribute attribute = as[i];
-                       if (attribute instanceof Signature) declaredSignature = ((Signature)attribute).getSignature();
-               }
+               Signature sigAttr = AttributeUtils.getSignatureAttribute(javaClass.getAttributes());
+               declaredSignature = (sigAttr==null?null:sigAttr.getSignature());
                if (declaredSignature!=null) isGenericType= (declaredSignature.charAt(0)=='<');
        }
        
@@ -770,6 +783,7 @@ public class BcelObjectType extends AbstractReferenceTypeDelegate {
        
        public void evictWeavingState() {
                // Can't chuck all this away 
+//             if (getResolvedTypeX().isAspect()) System.err.println("Eviction of "+getResolvedTypeX().getName());
                if (getResolvedTypeX().getWorld().couldIncrementalCompileFollow()) return;
                
                if (javaClass != null) {
@@ -791,12 +805,16 @@ public class BcelObjectType extends AbstractReferenceTypeDelegate {
                                weaverState.setReweavable(false);
                                weaverState.setUnwovenClassFileData(null);
                        }
-               for (int i = methods.length - 1; i >= 0; i--) methods[i].evictWeavingState();
+                       
+               for (int i = methods.length - 1; i >= 0; i--) { methods[i].evictWeavingState();}
                for (int i = fields.length - 1;  i >= 0; i--)  fields[i].evictWeavingState();
+//                     if (getResolvedTypeX().isAspect()) System.err.println("nulling jc for "+getResolvedTypeX().getName());
                        javaClass = null;
 //                     setSourceContext(SourceContextImpl.UNKNOWN_SOURCE_CONTEXT); // bit naughty
 //                 interfaces=null; // force reinit - may get us the right instances!
 //                 superClass=null;
+                       // if this is a class, make sure aspects are re-evicted if necessary
+//                     if (!getResolvedTypeX().isAspect()) getWorld().ensureAspectsEvicted();
                }
        }
        
index a3aa3926d6d007a8afc34174f1d6e7bd80594e5f..83aac4585a106deec7ca4a415bfa7d4b478af066 100644 (file)
 package org.aspectj.weaver.bcel;
 
 import org.aspectj.apache.bcel.Constants;
-import org.aspectj.apache.bcel.generic.ATHROW;
-import org.aspectj.apache.bcel.generic.BranchInstruction;
+import org.aspectj.apache.bcel.generic.InstructionBranch;
 import org.aspectj.apache.bcel.generic.InstructionConstants;
 import org.aspectj.apache.bcel.generic.InstructionFactory;
 import org.aspectj.apache.bcel.generic.InstructionHandle;
 import org.aspectj.apache.bcel.generic.InstructionList;
-import org.aspectj.apache.bcel.generic.NOP;
 import org.aspectj.apache.bcel.generic.ObjectType;
-import org.aspectj.apache.bcel.generic.POP;
-import org.aspectj.apache.bcel.generic.PUSH;
 import org.aspectj.apache.bcel.generic.ReferenceType;
 import org.aspectj.apache.bcel.generic.Type;
 import org.aspectj.weaver.AjAttribute;
@@ -170,11 +166,11 @@ public class BcelPerClauseAspectAdder extends BcelTypeMunger {
 
         //FIXME Alex percflowX is not using this one but AJ code style does generate it so..
         ResolvedMember failureFieldInfo = AjcMemberMaker.initFailureCauseField(aspectType);
-        classGen.addField(makeFieldGen(classGen, failureFieldInfo).getField(), null);
+        classGen.addField(makeFieldGen(classGen, failureFieldInfo), null);
 
         if (kind == PerClause.SINGLETON) {
             ResolvedMember perSingletonFieldInfo = AjcMemberMaker.perSingletonField(aspectType);
-            classGen.addField(makeFieldGen(classGen, perSingletonFieldInfo).getField(), null);
+            classGen.addField(makeFieldGen(classGen, perSingletonFieldInfo), null);
 // pr144602 - don't need to do this, PerObjectInterface munger will do it
 //        } else if (kind == PerClause.PEROBJECT) {
 //           ResolvedMember perObjectFieldInfo = AjcMemberMaker.perObjectField(aspectType, aspectType);
@@ -183,10 +179,10 @@ public class BcelPerClauseAspectAdder extends BcelTypeMunger {
 //            // it should be done here.
         } else if (kind == PerClause.PERCFLOW) {
             ResolvedMember perCflowFieldInfo = AjcMemberMaker.perCflowField(aspectType);
-            classGen.addField(makeFieldGen(classGen, perCflowFieldInfo).getField(), null);
+            classGen.addField(makeFieldGen(classGen, perCflowFieldInfo), null);
         } else if (kind == PerClause.PERTYPEWITHIN) {
             ResolvedMember perTypeWithinForField = AjcMemberMaker.perTypeWithinWithinTypeField(aspectType, aspectType);
-            classGen.addField(makeFieldGen(classGen, perTypeWithinForField).getField(), null);
+            classGen.addField(makeFieldGen(classGen, perTypeWithinForField), null);
 //        } else {
 //            throw new Error("Should not happen - no such kind " + kind.toString());
         }
@@ -200,11 +196,11 @@ public class BcelPerClauseAspectAdder extends BcelTypeMunger {
 
         InstructionList il = method.getBody();
         il.append(Utility.createGet(factory, AjcMemberMaker.perSingletonField(aspectType)));
-        BranchInstruction ifNotNull = InstructionFactory.createBranchInstruction(Constants.IFNONNULL, null);
+        InstructionBranch ifNotNull = InstructionFactory.createBranchInstruction(Constants.IFNONNULL, null);
         il.append(ifNotNull);
         il.append(factory.createNew(AjcMemberMaker.NO_ASPECT_BOUND_EXCEPTION.getName()));
         il.append(InstructionConstants.DUP);
-        il.append(new PUSH(classGen.getConstantPoolGen(), aspectType.getName()));
+        il.append(InstructionFactory.PUSH(classGen.getConstantPool(), aspectType.getName()));
         il.append(Utility.createGet(factory, AjcMemberMaker.initFailureCauseField(aspectType)));
         il.append(factory.createInvoke(AjcMemberMaker.NO_ASPECT_BOUND_EXCEPTION.getName(), "<init>", Type.VOID, new Type[] { Type.STRING, new ObjectType("java.lang.Throwable") }, Constants.INVOKESPECIAL));
         il.append(InstructionConstants.ATHROW);
@@ -221,11 +217,11 @@ public class BcelPerClauseAspectAdder extends BcelTypeMunger {
 
         InstructionList il = method.getBody();
         il.append(Utility.createGet(factory, AjcMemberMaker.perSingletonField(aspectType)));
-        BranchInstruction ifNull = InstructionFactory.createBranchInstruction(Constants.IFNULL, null);
+        InstructionBranch ifNull = (InstructionBranch)InstructionFactory.createBranchInstruction(Constants.IFNULL, null);
         il.append(ifNull);
-        il.append(new PUSH(classGen.getConstantPoolGen(), true));
+        il.append(InstructionFactory.PUSH(classGen.getConstantPool(), true));
         il.append(InstructionFactory.createReturn(Type.INT));
-        InstructionHandle ifElse = il.append(new PUSH(classGen.getConstantPoolGen(), false));
+        InstructionHandle ifElse = il.append(InstructionFactory.PUSH(classGen.getConstantPool(), false));
         il.append(InstructionFactory.createReturn(Type.INT));
         ifNull.setTarget(ifElse);
     }
@@ -248,7 +244,7 @@ public class BcelPerClauseAspectAdder extends BcelTypeMunger {
         LazyMethodGen clinit = classGen.getStaticInitializer();
         il = new InstructionList();
         InstructionHandle tryStart = il.append(factory.createInvoke(aspectType.getName(), NameMangler.AJC_POST_CLINIT_NAME, Type.VOID, Type.NO_ARGS, Constants.INVOKESTATIC));
-        BranchInstruction tryEnd = InstructionFactory.createBranchInstruction(Constants.GOTO, null);
+        InstructionBranch tryEnd = InstructionFactory.createBranchInstruction(Constants.GOTO, null);
         il.append(tryEnd);
         InstructionHandle handler = il.append(InstructionConstants.ASTORE_0);
         il.append(InstructionConstants.ALOAD_0);
@@ -258,10 +254,10 @@ public class BcelPerClauseAspectAdder extends BcelTypeMunger {
 
         // replace the original "return" with a "nop"
         //TODO AV - a bit odd, looks like Bcel alters bytecode and has a IMPDEP1 in its representation
-        if (clinit.getBody().getEnd().getInstruction().getOpcode() == Constants.IMPDEP1) {
-            clinit.getBody().getEnd().getPrev().setInstruction(new NOP());
+        if (clinit.getBody().getEnd().getInstruction().opcode == Constants.IMPDEP1) {
+            clinit.getBody().getEnd().getPrev().setInstruction(InstructionConstants.NOP);
         }
-        clinit.getBody().getEnd().setInstruction(new NOP());
+        clinit.getBody().getEnd().setInstruction(InstructionConstants.NOP);
         clinit.getBody().append(il);
 
         clinit.addExceptionHandler(
@@ -279,22 +275,22 @@ public class BcelPerClauseAspectAdder extends BcelTypeMunger {
         InstructionList il = method.getBody();
         il.append(InstructionConstants.ALOAD_0);
         il.append(factory.createInstanceOf(interfaceType));
-        BranchInstruction ifEq = InstructionFactory.createBranchInstruction(Constants.IFEQ, null);
+        InstructionBranch ifEq = InstructionFactory.createBranchInstruction(Constants.IFEQ, null);
         il.append(ifEq);
         il.append(InstructionConstants.ALOAD_0);
         il.append(factory.createCheckCast(interfaceType));
         il.append(Utility.createInvoke(factory, Constants.INVOKEINTERFACE, AjcMemberMaker.perObjectInterfaceGet(aspectType)));
         il.append(InstructionConstants.DUP);
-        BranchInstruction ifNull = InstructionFactory.createBranchInstruction(Constants.IFNULL, null);
+        InstructionBranch ifNull = InstructionFactory.createBranchInstruction(Constants.IFNULL, null);
         il.append(ifNull);
         il.append(InstructionFactory.createReturn(BcelWorld.makeBcelType(aspectType)));
-        InstructionHandle ifNullElse = il.append(new POP());
+        InstructionHandle ifNullElse = il.append(InstructionConstants.POP);
         ifNull.setTarget(ifNullElse);
         InstructionHandle ifEqElse = il.append(factory.createNew(AjcMemberMaker.NO_ASPECT_BOUND_EXCEPTION.getName()));
         ifEq.setTarget(ifEqElse);
         il.append(InstructionConstants.DUP);
         il.append(factory.createInvoke(AjcMemberMaker.NO_ASPECT_BOUND_EXCEPTION.getName(), "<init>", Type.VOID, Type.NO_ARGS, Constants.INVOKESPECIAL));
-        il.append(new ATHROW());
+        il.append(InstructionConstants.ATHROW);
     }
 
     private void generatePerObjectHasAspectMethod(LazyClassGen classGen) {
@@ -307,12 +303,12 @@ public class BcelPerClauseAspectAdder extends BcelTypeMunger {
         InstructionList il = method.getBody();
         il.append(InstructionConstants.ALOAD_0);
         il.append(factory.createInstanceOf(interfaceType));
-        BranchInstruction ifEq = InstructionFactory.createBranchInstruction(Constants.IFEQ, null);
+        InstructionBranch ifEq = InstructionFactory.createBranchInstruction(Constants.IFEQ, null);
         il.append(ifEq);
         il.append(InstructionConstants.ALOAD_0);
         il.append(factory.createCheckCast(interfaceType));
         il.append(Utility.createInvoke(factory, Constants.INVOKEINTERFACE, AjcMemberMaker.perObjectInterfaceGet(aspectType)));
-        BranchInstruction ifNull = InstructionFactory.createBranchInstruction(Constants.IFNULL, null);
+        InstructionBranch ifNull = InstructionFactory.createBranchInstruction(Constants.IFNULL, null);
         il.append(ifNull);
         il.append(InstructionConstants.ICONST_1);
         il.append(InstructionFactory.createReturn(Type.INT));
@@ -332,12 +328,12 @@ public class BcelPerClauseAspectAdder extends BcelTypeMunger {
         InstructionList il = method.getBody();
         il.append(InstructionConstants.ALOAD_0);
         il.append(factory.createInstanceOf(interfaceType));
-        BranchInstruction ifEq = InstructionFactory.createBranchInstruction(Constants.IFEQ, null);
+        InstructionBranch ifEq = InstructionFactory.createBranchInstruction(Constants.IFEQ, null);
         il.append(ifEq);
         il.append(InstructionConstants.ALOAD_0);
         il.append(factory.createCheckCast(interfaceType));
         il.append(Utility.createInvoke(factory, Constants.INVOKEINTERFACE, AjcMemberMaker.perObjectInterfaceGet(aspectType)));
-        BranchInstruction ifNonNull = InstructionFactory.createBranchInstruction(Constants.IFNONNULL, null);
+        InstructionBranch ifNonNull = InstructionFactory.createBranchInstruction(Constants.IFNONNULL, null);
         il.append(ifNonNull);
         il.append(InstructionConstants.ALOAD_0);
         il.append(factory.createCheckCast(interfaceType));
@@ -449,11 +445,11 @@ public class BcelPerClauseAspectAdder extends BcelTypeMunger {
         ));
         il.append(InstructionConstants.ASTORE_1);
         il.append(InstructionConstants.ALOAD_1);
-        BranchInstruction ifNonNull = InstructionFactory.createBranchInstruction(Constants.IFNONNULL, null);
+        InstructionBranch ifNonNull = InstructionFactory.createBranchInstruction(Constants.IFNONNULL, null);
         il.append(ifNonNull);
         il.append(factory.createNew(AjcMemberMaker.NO_ASPECT_BOUND_EXCEPTION.getName()));
         il.append(InstructionConstants.DUP);
-        il.append(new PUSH(classGen.getConstantPoolGen(), aspectType.getName()));
+        il.append(InstructionFactory.PUSH(classGen.getConstantPool(), aspectType.getName()));
         il.append(InstructionConstants.ACONST_NULL);
         il.append(factory.createInvoke(AjcMemberMaker.NO_ASPECT_BOUND_EXCEPTION.getName(), "<init>", Type.VOID, new Type[] { Type.STRING, new ObjectType("java.lang.Throwable") }, Constants.INVOKESPECIAL));
         il.append(InstructionConstants.ATHROW);
@@ -500,7 +496,7 @@ public class BcelPerClauseAspectAdder extends BcelTypeMunger {
                 Constants.INVOKESTATIC,
                 AjcMemberMaker.perTypeWithinGetInstance(aspectType)
         ));
-        BranchInstruction ifNull = InstructionFactory.createBranchInstruction(Constants.IFNULL, null);
+        InstructionBranch ifNull = InstructionFactory.createBranchInstruction(Constants.IFNULL, null);
         il.append(ifNull);
         il.append(InstructionConstants.ICONST_1);
         il.append(InstructionConstants.IRETURN);
@@ -525,7 +521,7 @@ public class BcelPerClauseAspectAdder extends BcelTypeMunger {
 
         InstructionList il = method.getBody();
         InstructionHandle tryStart = il.append(InstructionConstants.ALOAD_0);
-        il.append(new PUSH(factory.getConstantPool(), NameMangler.perTypeWithinLocalAspectOf(aspectType)));
+        il.append(InstructionFactory.PUSH(factory.getConstantPool(), NameMangler.perTypeWithinLocalAspectOf(aspectType)));
         il.append(InstructionConstants.ACONST_NULL);//Class[] for "getDeclaredMethod"
         il.append(factory.createInvoke(
                 "java/lang/Class",
@@ -590,7 +586,7 @@ public class BcelPerClauseAspectAdder extends BcelTypeMunger {
         methodGen.addAttribute(
                 BcelAttributes.bcelAttribute(
                         new AjAttribute.AjSynthetic(),
-                        methodGen.getEnclosingClass().getConstantPoolGen()
+                        methodGen.getEnclosingClass().getConstantPool()
                 )
         );
     }
index edc49f78bc12611153a3aacacd029f315a855900..13335e9e60306e60955c079bbd06f0ffc2b68bd1 100644 (file)
@@ -24,37 +24,23 @@ import java.util.Map;
 
 import org.aspectj.apache.bcel.Constants;
 import org.aspectj.apache.bcel.classfile.Field;
-import org.aspectj.apache.bcel.generic.ACONST_NULL;
-import org.aspectj.apache.bcel.generic.ALOAD;
-import org.aspectj.apache.bcel.generic.ANEWARRAY;
 import org.aspectj.apache.bcel.generic.ArrayType;
-import org.aspectj.apache.bcel.generic.BranchInstruction;
-import org.aspectj.apache.bcel.generic.ConstantPoolGen;
-import org.aspectj.apache.bcel.generic.DUP;
-import org.aspectj.apache.bcel.generic.DUP_X1;
-import org.aspectj.apache.bcel.generic.DUP_X2;
+import org.aspectj.apache.bcel.classfile.ConstantPool;
 import org.aspectj.apache.bcel.generic.FieldInstruction;
 import org.aspectj.apache.bcel.generic.INVOKEINTERFACE;
-import org.aspectj.apache.bcel.generic.INVOKESPECIAL;
-import org.aspectj.apache.bcel.generic.INVOKESTATIC;
 import org.aspectj.apache.bcel.generic.Instruction;
+import org.aspectj.apache.bcel.generic.InstructionBranch;
 import org.aspectj.apache.bcel.generic.InstructionConstants;
 import org.aspectj.apache.bcel.generic.InstructionFactory;
 import org.aspectj.apache.bcel.generic.InstructionHandle;
+import org.aspectj.apache.bcel.generic.InstructionLV;
 import org.aspectj.apache.bcel.generic.InstructionList;
 import org.aspectj.apache.bcel.generic.InstructionTargeter;
 import org.aspectj.apache.bcel.generic.InvokeInstruction;
 import org.aspectj.apache.bcel.generic.LineNumberTag;
-import org.aspectj.apache.bcel.generic.LoadInstruction;
 import org.aspectj.apache.bcel.generic.LocalVariableTag;
 import org.aspectj.apache.bcel.generic.MULTIANEWARRAY;
-import org.aspectj.apache.bcel.generic.NEW;
 import org.aspectj.apache.bcel.generic.ObjectType;
-import org.aspectj.apache.bcel.generic.PUSH;
-import org.aspectj.apache.bcel.generic.RETURN;
-import org.aspectj.apache.bcel.generic.ReturnInstruction;
-import org.aspectj.apache.bcel.generic.SWAP;
-import org.aspectj.apache.bcel.generic.StoreInstruction;
 import org.aspectj.apache.bcel.generic.TargetLostException;
 import org.aspectj.apache.bcel.generic.Type;
 import org.aspectj.bridge.ISourceLocation;
@@ -195,20 +181,19 @@ public class BcelShadow extends Shadow {
 
 
        private void deleteNewAndDup() {
-               final ConstantPoolGen cpg = getEnclosingClass().getConstantPoolGen();
+               final ConstantPool cpg = getEnclosingClass().getConstantPool();
                int depth = 1;
                InstructionHandle ih = range.getStart();
 
-               // Go back from where we are looking for 'NEW' that takes us to a stack depth of 0.   INVOKESPECIAL <init> 
                while (true) {
                        Instruction inst = ih.getInstruction();
-                       if (inst instanceof INVOKESPECIAL
-                               && ((INVOKESPECIAL) inst).getName(cpg).equals("<init>")) {
+                       if (inst.opcode==Constants.INVOKESPECIAL
+                               && ((InvokeInstruction) inst).getName(cpg).equals("<init>")) {
                                depth++;
-                       } else if (inst instanceof NEW) {
+                       } else if (inst.opcode==Constants.NEW) {
                                depth--;
                                if (depth == 0) break;
-                       } else if (inst instanceof DUP_X2) {
+                       } else if (inst.opcode==Constants.DUP_X2) {
                                // This code seen in the wild (by Brad):
 //                             40:  new     #12; //class java/lang/StringBuffer
 //                             STACK: STRINGBUFFER
@@ -243,7 +228,6 @@ public class BcelShadow extends Shadow {
                                // bytecode sequence has only been seen once in the wild.
                                ih.setInstruction(InstructionConstants.DUP);
                        }
-                       
                        ih = ih.getPrev();
                }
                // now IH points to the NEW.  We're followed by the DUP, and that is followed
@@ -251,17 +235,15 @@ public class BcelShadow extends Shadow {
                InstructionHandle newHandle = ih;
                InstructionHandle endHandle = newHandle.getNext();
                InstructionHandle nextHandle;
-               //
-               
-               if (endHandle.getInstruction() instanceof DUP) {
+               if (endHandle.getInstruction().opcode==Constants.DUP) {
                        nextHandle = endHandle.getNext();                       
                        retargetFrom(newHandle, nextHandle);
                        retargetFrom(endHandle, nextHandle);
-               } else if (endHandle.getInstruction() instanceof DUP_X1) {
+               } else if (endHandle.getInstruction().opcode==Constants.DUP_X1) {
                        InstructionHandle dupHandle = endHandle;
                        endHandle = endHandle.getNext();
                        nextHandle = endHandle.getNext();
-                       if (endHandle.getInstruction() instanceof SWAP) {}
+                       if (endHandle.getInstruction().opcode==Constants.SWAP) {}
                        else {
                                // XXX see next XXX comment
                                throw new RuntimeException("Unhandled kind of new " + endHandle);
@@ -532,7 +514,7 @@ public class BcelShadow extends Shadow {
         if (clinitStart.getInstruction() instanceof InvokeInstruction) {
                InvokeInstruction ii = (InvokeInstruction)clinitStart.getInstruction();
                        if (ii
-                               .getName(enclosingMethod.getEnclosingClass().getConstantPoolGen())
+                               .getName(enclosingMethod.getEnclosingClass().getConstantPool())
                                .equals(NameMangler.AJC_PRE_CLINIT_NAME)) {
                                clinitStart = clinitStart.getNext();
                        }
@@ -543,7 +525,7 @@ public class BcelShadow extends Shadow {
         //XXX should move the end before the postClinit, but the return is then tricky...
 //        if (clinitEnd.getInstruction() instanceof InvokeInstruction) {
 //             InvokeInstruction ii = (InvokeInstruction)clinitEnd.getInstruction();
-//             if (ii.getName(enclosingMethod.getEnclosingClass().getConstantPoolGen()).equals(NameMangler.AJC_POST_CLINIT_NAME)) {
+//             if (ii.getName(enclosingMethod.getEnclosingClass().getConstantPool()).equals(NameMangler.AJC_POST_CLINIT_NAME)) {
 //                     clinitEnd = clinitEnd.getPrev();
 //             }
 //        }
@@ -602,10 +584,10 @@ public class BcelShadow extends Shadow {
        }
        
        private static String findHandlerParamName(InstructionHandle startOfHandler) {          
-               if (startOfHandler.getInstruction() instanceof StoreInstruction &&
+               if (startOfHandler.getInstruction().isStoreInstruction() &&
                        startOfHandler.getNext() != null)
                {
-                       int slot = ((StoreInstruction)startOfHandler.getInstruction()).getIndex();
+                       int slot = startOfHandler.getInstruction().getIndex();
                        //System.out.println("got store: " + startOfHandler.getInstruction() + ", " + index);
                        InstructionTargeter[] targeters = startOfHandler.getNext().getTargeters();
                        if (targeters!=null) {
@@ -1022,7 +1004,7 @@ public class BcelShadow extends Shadow {
                if (sources != null) {
                        for (int i = sources.length - 1; i >= 0; i--) {
                                InstructionTargeter source = sources[i];
-                               if (source instanceof BranchInstruction) {
+                               if (source instanceof InstructionBranch) {
                                        source.updateTarget(from, to);
                                }
                        }
@@ -1257,12 +1239,12 @@ public class BcelShadow extends Shadow {
                if (hasThis()) {
                        ((BcelVar)getThisVar()).appendLoad(il, fact);
                } else {
-                       il.append(new ACONST_NULL());
+                       il.append(InstructionConstants.ACONST_NULL);
                }
                if (hasTarget()) {
                        ((BcelVar)getTargetVar()).appendLoad(il, fact);
                } else {
-                       il.append(new ACONST_NULL());
+                       il.append(InstructionConstants.ACONST_NULL);
                }
                
                switch(getArgCount()) {
@@ -1435,34 +1417,32 @@ public class BcelShadow extends Shadow {
                // Lets go back through the code from the start of the shadow
             InstructionHandle searchPtr = range.getStart().getPrev();
             while (Range.isRangeHandle(searchPtr) || 
-                  searchPtr.getInstruction() instanceof StoreInstruction) { // ignore this instruction - it doesnt give us the info we want
+                  searchPtr.getInstruction().isStoreInstruction()) { // ignore this instruction - it doesnt give us the info we want
                searchPtr = searchPtr.getPrev();  
             }
             
             // A load instruction may tell us the real type of what the clone() call is on
-            if (searchPtr.getInstruction() instanceof LoadInstruction) {
-               LoadInstruction li = (LoadInstruction)searchPtr.getInstruction();
-               li.getIndex();
-               LocalVariableTag lvt = LazyMethodGen.getLocalVariableTag(searchPtr,li.getIndex());
+            if (searchPtr.getInstruction().isLoadInstruction()) { 
+               LocalVariableTag lvt = LazyMethodGen.getLocalVariableTag(searchPtr,searchPtr.getInstruction().getIndex());
                if (lvt!=null)  return UnresolvedType.forSignature(lvt.getType());
             }
             // A field access instruction may tell us the real type of what the clone() call is on
             if (searchPtr.getInstruction() instanceof FieldInstruction) {
                FieldInstruction si = (FieldInstruction)searchPtr.getInstruction();
-               Type t = si.getFieldType(getEnclosingClass().getConstantPoolGen());
+               Type t = si.getFieldType(getEnclosingClass().getConstantPool());
                return BcelWorld.fromBcel(t);
             } 
             // A new array instruction obviously tells us it is an array type !
-            if (searchPtr.getInstruction() instanceof ANEWARRAY) {
+            if (searchPtr.getInstruction().opcode==Constants.ANEWARRAY) {
                //ANEWARRAY ana = (ANEWARRAY)searchPoint.getInstruction();
-               //Type t = ana.getType(getEnclosingClass().getConstantPoolGen());
+//             Type t = ana.getType(getEnclosingClass().getConstantPool());
                // Just use a standard java.lang.object array - that will work fine
                return BcelWorld.fromBcel(new ArrayType(Type.OBJECT,1));
             }
             // A multi new array instruction obviously tells us it is an array type !
             if (searchPtr.getInstruction() instanceof MULTIANEWARRAY) {
                MULTIANEWARRAY ana = (MULTIANEWARRAY)searchPtr.getInstruction();
-                // Type t = ana.getType(getEnclosingClass().getConstantPoolGen());
+                // Type t = ana.getType(getEnclosingClass().getConstantPool());
                // t = new ArrayType(t,ana.getDimensions());
                // Just use a standard java.lang.object array - that will work fine
                return BcelWorld.fromBcel(new ArrayType(Type.OBJECT,ana.getDimensions()));
@@ -1825,7 +1805,7 @@ public class BcelShadow extends Shadow {
        private List findReturnInstructions() {
                List returns = new ArrayList();
         for (InstructionHandle ih = range.getStart(); ih != range.getEnd(); ih = ih.getNext()) {
-            if (ih.getInstruction() instanceof ReturnInstruction) {
+            if (ih.getInstruction().isReturnInstruction()) {
                 returns.add(ih);
             }
         }
@@ -1859,7 +1839,7 @@ public class BcelShadow extends Shadow {
                int i=returns.size()-1;
                while (newReturnInstruction == null && i>=0) {
                        InstructionHandle ih = (InstructionHandle)returns.get(i);
-                       if (!(ih.getInstruction() instanceof RETURN)) {
+                       if (ih.getInstruction().opcode!=Constants.RETURN) {
                                newReturnInstruction = Utility.copyInstruction(ih.getInstruction());
                        }
                        i--;
@@ -1982,7 +1962,7 @@ public class BcelShadow extends Shadow {
                InstructionList ih = new InstructionList(InstructionConstants.NOP);
                handler.append(exceptionVar.createLoad(fact));
                handler.append(fact.createInstanceOf(eiieBcelType));
-               BranchInstruction bi = 
+               InstructionBranch bi = 
                 InstructionFactory.createBranchInstruction(Constants.IFEQ,ih.getStart());
                handler.append(bi);
                handler.append(exceptionVar.createLoad(fact));
@@ -2103,7 +2083,7 @@ public class BcelShadow extends Shadow {
                String aspectname = munger.getConcreteAspect().getName();
                
                String ptwField = NameMangler.perTypeWithinFieldForTarget(munger.getConcreteAspect());
-               entrySuccessInstructions.append(new PUSH(fact.getConstantPool(),t.getName()));
+               entrySuccessInstructions.append(InstructionFactory.PUSH(fact.getConstantPool(),t.getName()));
                
                entrySuccessInstructions.append(fact.createInvoke(aspectname,"ajc$createAspectInstance",new ObjectType(aspectname),
                                new Type[]{new ObjectType("java.lang.String")},Constants.INVOKESTATIC));
@@ -2313,7 +2293,7 @@ public class BcelShadow extends Shadow {
             boolean canSeeProceedPassedToOther = false;
             InstructionHandle curr = adviceMethod.getBody().getStart();
             InstructionHandle end = adviceMethod.getBody().getEnd();
-            ConstantPoolGen cpg = adviceMethod.getEnclosingClass().getConstantPoolGen();
+            ConstantPool cpg = adviceMethod.getEnclosingClass().getConstantPool();
             while (curr != end) {
                 InstructionHandle next = curr.getNext();
                 Instruction inst = curr.getInstruction();
@@ -2526,12 +2506,12 @@ public class BcelShadow extends Shadow {
 
             InstructionHandle curr = localAdviceMethod.getBody().getStart();
             InstructionHandle end = localAdviceMethod.getBody().getEnd();
-            ConstantPoolGen cpg = localAdviceMethod.getEnclosingClass().getConstantPoolGen();
+            ConstantPool cpg = localAdviceMethod.getEnclosingClass().getConstantPool();
             while (curr != end) {
                 InstructionHandle next = curr.getNext();
                 Instruction inst = curr.getInstruction();
-                if ((inst instanceof INVOKESTATIC)
-                    && proceedName.equals(((INVOKESTATIC) inst).getMethodName(cpg))) {
+                if ((inst.opcode==Constants.INVOKESTATIC)
+                    && proceedName.equals(((InvokeInstruction) inst).getMethodName(cpg))) {
 
                     localAdviceMethod.getBody().append(
                         curr,
@@ -2551,7 +2531,7 @@ public class BcelShadow extends Shadow {
             // [TODO document @AJ code rule: don't manipulate 2 jps proceed at the same time.. in an advice body]
             InstructionHandle curr = localAdviceMethod.getBody().getStart();
             InstructionHandle end = localAdviceMethod.getBody().getEnd();
-            ConstantPoolGen cpg = localAdviceMethod.getEnclosingClass().getConstantPoolGen();
+            ConstantPool cpg = localAdviceMethod.getEnclosingClass().getConstantPool();
             while (curr != end) {
                 InstructionHandle next = curr.getNext();
                 Instruction inst = curr.getInstruction();
@@ -2741,7 +2721,7 @@ public class BcelShadow extends Shadow {
                     indexIntoObjectArrayForArguments=1;
                } else {
                        // use local variable 0 (which is 'this' for a non-static method)
-                       ret.append(new ALOAD(0));
+                       ret.append(InstructionFactory.createALOAD(0));
                        indexIntoCallbackMethodForArguments++;
                }
             }
@@ -2779,7 +2759,7 @@ public class BcelShadow extends Shadow {
                 Type stateType = callbackMethod.getArgumentTypes()[i];
                 BcelWorld.fromBcel(stateType).resolve(world);
                 if ("Lorg/aspectj/lang/JoinPoint;".equals(stateType.getSignature())) {
-                    ret.append(new ALOAD(localJp));// from localAdvice signature
+                    ret.append(new InstructionLV(Constants.ALOAD,localJp));// from localAdvice signature
                 } else {
                     ret.append(InstructionFactory.createLoad(objectArrayType, localProceedArgArray));
                     ret.append(Utility.createConstant(fact, i-indexIntoCallbackMethodForArguments +indexIntoObjectArrayForArguments));
@@ -2802,7 +2782,7 @@ public class BcelShadow extends Shadow {
                 /*ResolvedType stateTypeX =*/ 
                 BcelWorld.fromBcel(stateType).resolve(world);
                 if ("Lorg/aspectj/lang/JoinPoint;".equals(stateType.getSignature())) {
-                    ret.append(new ALOAD(localJp));// from localAdvice signature
+                    ret.append(InstructionFactory.createALOAD(localJp));// from localAdvice signature
 //                } else if ("Lorg/aspectj/lang/ProceedingJoinPoint;".equals(stateType.getSignature())) {
 //                    //FIXME ALEX?
 //                        ret.append(new ALOAD(localJp));// from localAdvice signature
@@ -3183,7 +3163,7 @@ public class BcelShadow extends Shadow {
                stateIndex++;
         }
         il.append(fact.createNew(new ObjectType(constructor.getDeclaringType().getName())));
-        il.append(new DUP());
+        il.append(InstructionConstants.DUP);
         arrayVar.appendLoad(il, fact);
         il.append(Utility.createInvoke(fact, world, constructor));
         if (getKind() == PreInitialization) {
@@ -3234,7 +3214,7 @@ public class BcelShadow extends Shadow {
                                                             Modifier.PUBLIC,
                                                             new String[] {},
                                                             getWorld());
-        InstructionFactory fact = new InstructionFactory(closureClass.getConstantPoolGen());
+        InstructionFactory fact = new InstructionFactory(closureClass.getConstantPool());
                                        
         // constructor
         LazyMethodGen constructor = new LazyMethodGen(Modifier.PUBLIC, 
@@ -3381,7 +3361,7 @@ public class BcelShadow extends Shadow {
                InvokeInstruction superCallInstruction = 
                        (InvokeInstruction) superCallHandle.getInstruction();
                return superCallInstruction.getArgumentTypes(
-                       getEnclosingClass().getConstantPoolGen());
+                       getEnclosingClass().getConstantPool());
        }
 
 
index 0a392cc26874e1f9b915db19816c126a8c099806..dad598b1ee3425031ae1512dac117cb690ebffc4 100644 (file)
@@ -20,17 +20,16 @@ import java.util.List;
 import java.util.Set;
 
 import org.aspectj.apache.bcel.Constants;
-import org.aspectj.apache.bcel.classfile.annotation.Annotation;
-import org.aspectj.apache.bcel.generic.BranchInstruction;
-import org.aspectj.apache.bcel.generic.ConstantPoolGen;
 import org.aspectj.apache.bcel.generic.FieldGen;
-import org.aspectj.apache.bcel.generic.INVOKESPECIAL;
+import org.aspectj.apache.bcel.generic.InstructionBranch;
+import org.aspectj.apache.bcel.classfile.ConstantPool;
+import org.aspectj.apache.bcel.classfile.annotation.AnnotationGen;
 import org.aspectj.apache.bcel.generic.InstructionConstants;
 import org.aspectj.apache.bcel.generic.InstructionFactory;
 import org.aspectj.apache.bcel.generic.InstructionHandle;
 import org.aspectj.apache.bcel.generic.InstructionList;
+import org.aspectj.apache.bcel.generic.InvokeInstruction;
 import org.aspectj.apache.bcel.generic.Type;
-import org.aspectj.apache.bcel.generic.annotation.AnnotationGen;
 import org.aspectj.asm.AsmManager;
 import org.aspectj.bridge.IMessage;
 import org.aspectj.bridge.ISourceLocation;
@@ -66,6 +65,7 @@ import org.aspectj.weaver.World;
 import org.aspectj.weaver.patterns.DeclareAnnotation;
 import org.aspectj.weaver.patterns.Pointcut;
 
+
 //XXX addLazyMethodGen is probably bad everywhere
 public class BcelTypeMunger extends ConcreteTypeMunger {
 
@@ -409,9 +409,9 @@ public class BcelTypeMunger extends ConcreteTypeMunger {
                        InstructionList insList = aMethod.getBody();
                        InstructionHandle handle = insList.getStart();
                        while (handle!= null) {
-                               if (handle.getInstruction() instanceof INVOKESPECIAL) {
-                                       ConstantPoolGen cpg = newParentTarget.getConstantPoolGen();
-                                       INVOKESPECIAL invokeSpecial = (INVOKESPECIAL)handle.getInstruction();
+                               if (handle.getInstruction().opcode==Constants.INVOKESPECIAL) {
+                                       ConstantPool cpg = newParentTarget.getConstantPool();
+                                       InvokeInstruction invokeSpecial = (InvokeInstruction)handle.getInstruction();
                                        if (invokeSpecial.getClassName(cpg).equals(currentParent) && invokeSpecial.getMethodName(cpg).equals("<init>")) {
                                                // System.err.println("Transforming super call '<init>"+sp.getSignature(cpg)+"'");
                      
@@ -455,7 +455,7 @@ public class BcelTypeMunger extends ConcreteTypeMunger {
        /**
      * Creates a nice signature for the ctor, something like "(int,Integer,String)"
         */
-       private String createReadableCtorSig(ResolvedType newParent, ConstantPoolGen cpg, INVOKESPECIAL invokeSpecial) {
+       private String createReadableCtorSig(ResolvedType newParent, ConstantPool cpg, InvokeInstruction invokeSpecial) {
         StringBuffer sb = new StringBuffer();
                Type[] ctorArgs = invokeSpecial.getArgumentTypes(cpg);
                  sb.append(newParent.getClassName());
@@ -637,7 +637,7 @@ public class BcelTypeMunger extends ConcreteTypeMunger {
                        member.getModifiers(),
                        BcelWorld.makeBcelType(member.getReturnType()),
                        member.getName(),
-                       gen.getConstantPoolGen());
+                       gen.getConstantPool());
        }
 
 
@@ -654,7 +654,7 @@ public class BcelTypeMunger extends ConcreteTypeMunger {
                        FieldGen fg = makeFieldGen(gen, 
                                AjcMemberMaker.perObjectField(gen.getType(), aspectType));
 
-               gen.addField(fg.getField(),getSourceLocation());
+               gen.addField(fg,getSourceLocation());
                
                
                Type fieldType = BcelWorld.makeBcelType(aspectType);
@@ -712,7 +712,7 @@ public class BcelTypeMunger extends ConcreteTypeMunger {
                        // Add (to the target type) the field that will hold the aspect instance
                        // e.g ajc$com_blah_SecurityAspect$ptwAspectInstance
                        FieldGen fg = makeFieldGen(gen, AjcMemberMaker.perTypeWithinField(gen.getType(), aspectType));
-                   gen.addField(fg.getField(),getSourceLocation());
+                   gen.addField(fg,getSourceLocation());
                        
                    // Add an accessor for this new field, the ajc$<aspectname>$localAspectOf() method
                    // e.g. "public com_blah_SecurityAspect ajc$com_blah_SecurityAspect$localAspectOf()"
@@ -806,9 +806,9 @@ public class BcelTypeMunger extends ConcreteTypeMunger {
                                if (annotationsOnRealMember!=null) {
                                        for (int i = 0; i < annotationsOnRealMember.length; i++) {
                                                AnnotationX annotationX = annotationsOnRealMember[i];
-                                               Annotation a = annotationX.getBcelAnnotation();
-                                               AnnotationGen ag = new AnnotationGen(a,weaver.getLazyClassGen().getConstantPoolGen(),true);
-                                               newMethod.addAnnotation(new AnnotationX(ag.getAnnotation(),weaver.getWorld()));
+                                               AnnotationGen a = annotationX.getBcelAnnotation();
+                                               AnnotationGen ag = new AnnotationGen(a,weaver.getLazyClassGen().getConstantPool(),true);
+                                               newMethod.addAnnotation(new AnnotationX(ag,weaver.getWorld()));
                                        }
                                }
                                // the below loop fixes the very special (and very stupid)
@@ -901,9 +901,9 @@ public class BcelTypeMunger extends ConcreteTypeMunger {
                                        if (annotationsOnRealMember!=null) {
                                                for (int i = 0; i < annotationsOnRealMember.length; i++) {
                                                        AnnotationX annotationX = annotationsOnRealMember[i];
-                                                       Annotation a = annotationX.getBcelAnnotation();
-                                                       AnnotationGen ag = new AnnotationGen(a,weaver.getLazyClassGen().getConstantPoolGen(),true);
-                                                       mg.addAnnotation(new AnnotationX(ag.getAnnotation(),weaver.getWorld()));
+                                                       AnnotationGen a = annotationX.getBcelAnnotation();
+                                                       AnnotationGen ag = new AnnotationGen(a,weaver.getLazyClassGen().getConstantPool(),true);
+                                                       mg.addAnnotation(new AnnotationX(ag,weaver.getWorld()));
                                                }
                                        }
                          }
@@ -1128,9 +1128,9 @@ public class BcelTypeMunger extends ConcreteTypeMunger {
                 if (annotationsOnRealMember!=null) {
                     for (int i = 0; i < annotationsOnRealMember.length; i++) {
                         AnnotationX annotationX = annotationsOnRealMember[i];
-                        Annotation a = annotationX.getBcelAnnotation();
-                        AnnotationGen ag = new AnnotationGen(a,weaver.getLazyClassGen().getConstantPoolGen(),true);
-                        mg.addAnnotation(new AnnotationX(ag.getAnnotation(),weaver.getWorld()));
+                        AnnotationGen a = annotationX.getBcelAnnotation();
+                        AnnotationGen ag = new AnnotationGen(a,weaver.getLazyClassGen().getConstantPool(),true);
+                        mg.addAnnotation(new AnnotationX(ag,weaver.getWorld()));
                     }
                 }
             }
@@ -1141,7 +1141,7 @@ public class BcelTypeMunger extends ConcreteTypeMunger {
             // getfield
             body.append(InstructionConstants.ALOAD_0);
             body.append(Utility.createGet(fact, munger.getDelegate(weaver.getLazyClassGen().getType())));
-            BranchInstruction ifNonNull = InstructionFactory.createBranchInstruction(Constants.IFNONNULL, null);
+            InstructionBranch ifNonNull = InstructionFactory.createBranchInstruction(Constants.IFNONNULL, null);
             body.append(ifNonNull);
             
             // Create and store a new instance
@@ -1196,7 +1196,7 @@ public class BcelTypeMunger extends ConcreteTypeMunger {
                 aspectType);
         weaver.getLazyClassGen().addField(makeFieldGen(
                 weaver.getLazyClassGen(),
-                host).getField(), null);
+                host), null);
         return true;
     }
 
@@ -1336,9 +1336,9 @@ public class BcelTypeMunger extends ConcreteTypeMunger {
                        if (annotationsOnRealMember!=null) {
                                for (int i = 0; i < annotationsOnRealMember.length; i++) {
                                        AnnotationX annotationX = annotationsOnRealMember[i];
-                                       Annotation a = annotationX.getBcelAnnotation();
-                                       AnnotationGen ag = new AnnotationGen(a,weaver.getLazyClassGen().getConstantPoolGen(),true);
-                                       mg.addAnnotation(new AnnotationX(ag.getAnnotation(),weaver.getWorld()));
+                                       AnnotationGen a = annotationX.getBcelAnnotation();
+                                       AnnotationGen ag = new AnnotationGen(a,weaver.getLazyClassGen().getConstantPool(),true);
+                                       mg.addAnnotation(new AnnotationX(ag,weaver.getWorld()));
                                }
                        }
                        // the below loop fixes the very special (and very stupid)
@@ -1527,13 +1527,13 @@ public class BcelTypeMunger extends ConcreteTypeMunger {
                                if (annotationsOnRealMember!=null) {
                                        for (int i = 0; i < annotationsOnRealMember.length; i++) {
                                                AnnotationX annotationX = annotationsOnRealMember[i];
-                                               Annotation a = annotationX.getBcelAnnotation();
-                                               AnnotationGen ag = new AnnotationGen(a,weaver.getLazyClassGen().getConstantPoolGen(),true);     
+                                               AnnotationGen a = annotationX.getBcelAnnotation();
+                                               AnnotationGen ag = new AnnotationGen(a,weaver.getLazyClassGen().getConstantPool(),true);        
                                                fg.addAnnotation(ag);
                                        }
                                }
                                
-                               gen.addField(fg.getField(),getSourceLocation());
+                               gen.addField(fg,getSourceLocation());
                        
                        }
                return true;
@@ -1551,13 +1551,13 @@ public class BcelTypeMunger extends ConcreteTypeMunger {
                                if (annotationsOnRealMember!=null) {
                                        for (int i = 0; i < annotationsOnRealMember.length; i++) {
                                                AnnotationX annotationX = annotationsOnRealMember[i];
-                                               Annotation a = annotationX.getBcelAnnotation();
-                                               AnnotationGen ag = new AnnotationGen(a,weaver.getLazyClassGen().getConstantPoolGen(),true);     
+                                               AnnotationGen a = annotationX.getBcelAnnotation();
+                                               AnnotationGen ag = new AnnotationGen(a,weaver.getLazyClassGen().getConstantPool(),true);        
                                                fg.addAnnotation(ag);
                                        }
                                }
                                
-                       gen.addField(fg.getField(),getSourceLocation());
+                       gen.addField(fg,getSourceLocation());
                //this uses a shadow munger to add init method to constructors
                //weaver.getShadowMungers().add(makeInitCallShadowMunger(initMethod));
                
index 72626eacdacba783f3b178dca4b1e6d358943ff9..1596b0da61773dc506147916b00f3e231256bae9 100644 (file)
@@ -192,6 +192,8 @@ public class BcelWeaver implements IWeaver {
                                  wsi.getUnwovenClassFileData(wovenJavaClass.getBytes()));
                                world.storeClass(unwovenJavaClass);
                                classType.setJavaClass(unwovenJavaClass);
+                               if (world.isRunMinimalMemory() && world.isXnoInline())
+                                       classType.evictWeavingState();  // CUSTARD      
 //                             classType.setJavaClass(Utility.makeJavaClass(classType.getJavaClass().getFileName(), wsi.getUnwovenClassFileData(classType.getJavaClass().getBytes())));
                        }
                        
index a5ac53aef35178b8c574e228bb9abb4e3d67a211..3678c7cbf367888ce9d806e57600f4f8add6c687 100644 (file)
@@ -24,27 +24,20 @@ import java.util.List;
 import java.util.Properties;
 import java.util.StringTokenizer;
 
+import org.aspectj.apache.bcel.Constants;
 import org.aspectj.apache.bcel.classfile.Attribute;
 import org.aspectj.apache.bcel.classfile.ClassParser;
 import org.aspectj.apache.bcel.classfile.JavaClass;
+import org.aspectj.apache.bcel.classfile.ConstantPool;
 import org.aspectj.apache.bcel.classfile.Method;
-import org.aspectj.apache.bcel.classfile.annotation.Annotation;
-import org.aspectj.apache.bcel.generic.ANEWARRAY;
-import org.aspectj.apache.bcel.generic.ConstantPoolGen;
+import org.aspectj.apache.bcel.classfile.annotation.AnnotationGen;
 import org.aspectj.apache.bcel.generic.FieldInstruction;
-import org.aspectj.apache.bcel.generic.GETSTATIC;
 import org.aspectj.apache.bcel.generic.INVOKEINTERFACE;
-import org.aspectj.apache.bcel.generic.INVOKESPECIAL;
-import org.aspectj.apache.bcel.generic.INVOKESTATIC;
 import org.aspectj.apache.bcel.generic.Instruction;
 import org.aspectj.apache.bcel.generic.InstructionHandle;
 import org.aspectj.apache.bcel.generic.InvokeInstruction;
-import org.aspectj.apache.bcel.generic.MONITORENTER;
-import org.aspectj.apache.bcel.generic.MONITOREXIT;
 import org.aspectj.apache.bcel.generic.MULTIANEWARRAY;
-import org.aspectj.apache.bcel.generic.NEWARRAY;
 import org.aspectj.apache.bcel.generic.ObjectType;
-import org.aspectj.apache.bcel.generic.PUTSTATIC;
 import org.aspectj.apache.bcel.generic.Type;
 import org.aspectj.apache.bcel.util.ClassLoaderRepository;
 import org.aspectj.apache.bcel.util.ClassPath;
@@ -112,8 +105,7 @@ public class BcelWorld extends World implements Repository {
        }
        
 
-    
-               
+       
        private static List getPathEntries(String s) {
                List ret = new ArrayList();
                StringTokenizer tok = new StringTokenizer(s, File.pathSeparator);
@@ -143,7 +135,7 @@ public class BcelWorld extends World implements Repository {
         // TODO Alex do we need to call org.aspectj.apache.bcel.Repository.setRepository(delegate);
         // if so, how can that be safe in J2EE ?? (static stuff in Bcel)
        }
-
+       
     /**
      * Build a World from a ClassLoader, for LTW support
      *
@@ -433,11 +425,11 @@ public class BcelWorld extends World implements Repository {
        }
 
     public static Member makeFieldJoinPointSignature(LazyClassGen cg, FieldInstruction fi) {
-       ConstantPoolGen cpg = cg.getConstantPoolGen();
+       ConstantPool cpg = cg.getConstantPool();
         return            
                  MemberImpl.field(
                                fi.getClassName(cpg),
-                               (fi instanceof GETSTATIC || fi instanceof PUTSTATIC)
+                               (fi.opcode==Constants.GETSTATIC || fi.opcode==Constants.PUTSTATIC)
                                ? Modifier.STATIC: 0, 
                                fi.getName(cpg),
                                fi.getSignature(cpg));
@@ -490,23 +482,23 @@ public class BcelWorld extends World implements Repository {
     }
        
        public Member makeJoinPointSignatureForMonitorEnter(LazyClassGen cg,InstructionHandle h) {
-               MONITORENTER i = (MONITORENTER)h.getInstruction();
+               Instruction i = h.getInstruction();
                return MemberImpl.monitorEnter();
        }
 
        public Member makeJoinPointSignatureForMonitorExit(LazyClassGen cg,InstructionHandle h) {
-               MONITOREXIT i = (MONITOREXIT)h.getInstruction();
+               Instruction i = h.getInstruction();
                return MemberImpl.monitorExit();
        }
        
        public Member makeJoinPointSignatureForArrayConstruction(LazyClassGen cg, InstructionHandle handle) {
                Instruction i = handle.getInstruction();
-               ConstantPoolGen cpg = cg.getConstantPoolGen();
+               ConstantPool cpg = cg.getConstantPool();
                Member retval = null;
 
-               if (i instanceof ANEWARRAY) {
-                       ANEWARRAY arrayInstruction = (ANEWARRAY)i;
-                       Type ot = arrayInstruction.getType(cpg);
+               if (i.opcode==Constants.ANEWARRAY) {
+//                     ANEWARRAY arrayInstruction = (ANEWARRAY)i;
+                       Type ot = i.getType(cpg);
                        UnresolvedType ut = fromBcel(ot);
                        ut = UnresolvedType.makeArray(ut,1);
                        retval = MemberImpl.method(ut, Modifier.PUBLIC, ResolvedType.VOID, "<init>", new ResolvedType[]{ResolvedType.INT});
@@ -526,9 +518,9 @@ public class BcelWorld extends World implements Repository {
                        for (int ii=0;ii<dimensions;ii++) parms[ii] = ResolvedType.INT;
                        retval = MemberImpl.method(ut, Modifier.PUBLIC, ResolvedType.VOID, "<init>", parms);
                        
-               } else if (i instanceof NEWARRAY) {
-                       NEWARRAY arrayInstruction = (NEWARRAY)i;
-                       Type ot = arrayInstruction.getType();
+               } else if (i.opcode==Constants.NEWARRAY) {
+//                     NEWARRAY arrayInstruction = (NEWARRAY)i;
+                       Type ot = i.getType();
                        UnresolvedType ut = fromBcel(ot);
                        retval = MemberImpl.method(ut, Modifier.PUBLIC, ResolvedType.VOID, "<init>", new ResolvedType[]{ResolvedType.INT});
                } else {
@@ -538,7 +530,7 @@ public class BcelWorld extends World implements Repository {
        }
 
     public Member makeJoinPointSignatureForMethodInvocation(LazyClassGen cg, InvokeInstruction ii) {
-       ConstantPoolGen cpg = cg.getConstantPoolGen();
+       ConstantPool cpg = cg.getConstantPool();
        String name = ii.getName(cpg);
         String declaring = ii.getClassName(cpg);
         UnresolvedType declaringType = null;
@@ -548,16 +540,16 @@ public class BcelWorld extends World implements Repository {
         int modifier = 
             (ii instanceof INVOKEINTERFACE)
             ? Modifier.INTERFACE
-            : (ii instanceof INVOKESTATIC)
+            : (ii.opcode==Constants.INVOKESTATIC)
               ? Modifier.STATIC
-              : (ii instanceof INVOKESPECIAL && ! name.equals("<init>"))
+              : (ii.opcode==Constants.INVOKESPECIAL && ! name.equals("<init>"))
                 ? Modifier.PRIVATE
                 : 0;
 
         // in Java 1.4 and after, static method call of super class within subclass method appears
         // as declared by the subclass in the bytecode - but they are not
         // see #104212
-        if (ii instanceof INVOKESTATIC) {
+        if (ii.opcode==Constants.INVOKESTATIC) {
             ResolvedType appearsDeclaredBy = resolve(declaring);
             // look for the method there
             for (Iterator iterator = appearsDeclaredBy.getMethods(); iterator.hasNext();) {
@@ -678,7 +670,8 @@ public class BcelWorld extends World implements Repository {
        }
 
        public void clear() {
-               throw new RuntimeException("Not implemented");
+               delegate.clear();
+//             throw new RuntimeException("Not implemented");
        }
 
     // @Override
@@ -718,13 +711,13 @@ public class BcelWorld extends World implements Repository {
             if (!jc.isClass()) {
                 return false;
             }
-            Annotation anns[] = jc.getAnnotations();
+            AnnotationGen anns[] = jc.getAnnotations();
             if (anns.length == 0) {
                 return false;
             }
             boolean couldBeAtAspectJStyle = false;
             for (int i = 0; i < anns.length; i++) {
-                Annotation ann = anns[i];
+                AnnotationGen ann = anns[i];
                 if ("Lorg/aspectj/lang/annotation/Aspect;".equals(ann.getTypeSignature())) {
                     couldBeAtAspectJStyle = true;
                 }
index 6f6743f4716beeed95d73f52e9e3bd8b9dd4b561..ad4728423e3b9cdb05098dc69ad8f07ea729e971 100644 (file)
@@ -39,20 +39,17 @@ import org.aspectj.apache.bcel.classfile.Method;
 import org.aspectj.apache.bcel.classfile.Signature;
 import org.aspectj.apache.bcel.classfile.Synthetic;
 import org.aspectj.apache.bcel.classfile.Unknown;
-import org.aspectj.apache.bcel.classfile.annotation.Annotation;
 import org.aspectj.apache.bcel.generic.BasicType;
 import org.aspectj.apache.bcel.generic.ClassGen;
-import org.aspectj.apache.bcel.generic.ConstantPoolGen;
+import org.aspectj.apache.bcel.classfile.ConstantPool;
+import org.aspectj.apache.bcel.classfile.annotation.AnnotationGen;
 import org.aspectj.apache.bcel.generic.FieldGen;
 import org.aspectj.apache.bcel.generic.InstructionConstants;
 import org.aspectj.apache.bcel.generic.InstructionFactory;
 import org.aspectj.apache.bcel.generic.InstructionHandle;
 import org.aspectj.apache.bcel.generic.InstructionList;
 import org.aspectj.apache.bcel.generic.ObjectType;
-import org.aspectj.apache.bcel.generic.PUSH;
-import org.aspectj.apache.bcel.generic.RETURN;
 import org.aspectj.apache.bcel.generic.Type;
-import org.aspectj.apache.bcel.generic.annotation.AnnotationGen;
 import org.aspectj.bridge.IMessage;
 import org.aspectj.bridge.ISourceLocation;
 import org.aspectj.bridge.SourceLocation;
@@ -72,6 +69,7 @@ import org.aspectj.weaver.World;
 import org.aspectj.weaver.AjAttribute.WeaverVersionInfo;
 
 
+
 /**
  * Lazy lazy lazy.
  * We don't unpack the underlying class unless necessary.  Things
@@ -91,10 +89,11 @@ public final class LazyClassGen {
        
        private BcelObjectType myType; // XXX is not set for types we create
        private ClassGen myGen;
-       private ConstantPoolGen constantPoolGen;
+       private ConstantPool constantPoolGen;
        private World world;
     private String packageName = null;
 
+    private List /*BcelField*/ fields          = new ArrayList();
     private List /*LazyMethodGen*/ methodGens  = new ArrayList();
     private List /*LazyClassGen*/  classGens   = new ArrayList();
     private List /*AnnotationGen*/ annotations = new ArrayList();
@@ -155,7 +154,7 @@ public final class LazyClassGen {
                byte[] bytes = Utility.stringToUTF(data);
                int length = bytes.length;
 
-               return new Unknown(nameIndex, length, bytes, constantPoolGen.getConstantPool());                
+               return new Unknown(nameIndex, length, bytes, constantPoolGen);          
        }       
 
 //     private LazyClassGen() {}
@@ -290,9 +289,9 @@ public final class LazyClassGen {
                        // Do we need to calculate an SUID and add it?
                        if (!hasSerialVersionUIDField && world.isAddSerialVerUID()) {
                        calculatedSerialVersionUID = myGen.getSUID();
-                       Field fg = new FieldGen(
+                       FieldGen fg = new FieldGen(
                                        Constants.ACC_PRIVATE|Constants.ACC_FINAL|Constants.ACC_STATIC,
-                                       BasicType.LONG,"serialVersionUID",getConstantPoolGen()).getField();
+                                       BasicType.LONG,"serialVersionUID",getConstantPool());
                        addField(fg);
                        hasSerialVersionUIDField=true;
                        serialVersionUIDRequiresInitialization=true;
@@ -303,11 +302,15 @@ public final class LazyClassGen {
                }
                }
 
-        Method[] methods = myGen.getMethods();
-        for (int i = 0; i < methods.length; i++) {
-            addMethodGen(new LazyMethodGen(methods[i], this));
-        }
-        
+               ResolvedMember[] methods = myType.getDeclaredMethods();
+               for (int i=0; i<methods.length; i++) {
+                       addMethodGen(new LazyMethodGen((BcelMethod)methods[i],this));
+               }
+               
+               ResolvedMember[] fields = myType.getDeclaredFields();
+               for (int i=0; i<fields.length; i++) {
+                       this.fields.add((BcelField)fields[i]);
+               }
     }
 
        public static boolean hasSerialVersionUIDField (ResolvedType type) {
@@ -331,9 +334,10 @@ public final class LazyClassGen {
        // ---- 
 
     public String getInternalClassName() {
-        return getConstantPoolGen().getConstantPool().getConstantString(
-            myGen.getClassNameIndex(),
-            Constants.CONSTANT_Class);
+        return getConstantPool().getConstantString_CONSTANTClass(myGen.getClassNameIndex());
+        //getConstantPool().getConstantString(
+        //    myGen.getClassNameIndex(),
+        //    Constants.CONSTANT_Class);
 
     }
 
@@ -382,7 +386,7 @@ public final class LazyClassGen {
                methodGens.add(gen);
                if (highestLineNumber < gen.highestLineNumber) highestLineNumber = gen.highestLineNumber;
        }
-
+       
        public void addMethodGen(LazyMethodGen gen, ISourceLocation sourceLocation) {
                addMethodGen(gen);
                if (!gen.getMethod().isPrivate()) { 
@@ -391,7 +395,7 @@ public final class LazyClassGen {
        }
        
 
-       public void errorOnAddedField (Field field, ISourceLocation sourceLocation) {
+       public void errorOnAddedField (FieldGen field, ISourceLocation sourceLocation) {
                if (isSerializable && !hasSerialVersionUIDField) {
                        getWorld().getLint().serialVersionUIDBroken.signal(
                                new String[] {
@@ -436,20 +440,20 @@ public final class LazyClassGen {
         return methodGens; //???Collections.unmodifiableList(methodGens);
     }
     
-    // FIXME asc Should be collection returned here
-    public Field[] getFieldGens() {
-      return myGen.getFields();
+    public List/*BcelField*/ getFieldGens() {
+      return fields;
+    //  return myGen.getFields();
     }
     
-    public Field getField(String name) {
-       Field[] allFields = myGen.getFields();
-       if (allFields==null) return null;
-       for (int i = 0; i < allFields.length; i++) {
-                       Field field = allFields[i];
-                       if (field.getName().equals(name)) return field;
-               }
-       return null;
-    }
+//    public Field getField(String name) {
+//     Field[] allFields = myGen.getFields();
+//     if (allFields==null) return null;
+//     for (int i = 0; i < allFields.length; i++) {
+//                     Field field = allFields[i];
+//                     if (field.getName().equals(name)) return field;
+//             }
+//     return null;
+//    }
     
     // FIXME asc How do the ones on the underlying class surface if this just returns new ones added?
     // FIXME asc ...although no one calls this right now !
@@ -458,7 +462,7 @@ public final class LazyClassGen {
     }
 
     private void writeBack(BcelWorld world) {
-        if (getConstantPoolGen().getSize() > Short.MAX_VALUE) {
+        if (getConstantPool().getSize() > Short.MAX_VALUE) {
             reportClassTooBigProblem();
                return;
         }
@@ -468,7 +472,7 @@ public final class LazyClassGen {
                                AnnotationGen element = (AnnotationGen) iter.next();
                                myGen.addAnnotation(element);
                        }
-//         Attribute[] annAttributes  = org.aspectj.apache.bcel.classfile.Utility.getAnnotationAttributes(getConstantPoolGen(),annotations);
+//         Attribute[] annAttributes  = org.aspectj.apache.bcel.classfile.Utility.getAnnotationAttributes(getConstantPool(),annotations);
 //        for (int i = 0; i < annAttributes.length; i++) {
 //                     Attribute attribute = annAttributes[i];
 //                     System.err.println("Adding attribute for "+attribute);
@@ -484,12 +488,12 @@ public final class LazyClassGen {
                        if (attribute.getName().equals("org.aspectj.weaver.WeaverVersion")) hasVersionAttribute=true;
                }        
         if (!hasVersionAttribute)
-               myGen.addAttribute(BcelAttributes.bcelAttribute(new AjAttribute.WeaverVersionInfo(),getConstantPoolGen()));
+               myGen.addAttribute(BcelAttributes.bcelAttribute(new AjAttribute.WeaverVersionInfo(),getConstantPool()));
 
         if (myType != null && myType.getWeaverState() != null) {
                        myGen.addAttribute(BcelAttributes.bcelAttribute(
                                new AjAttribute.WeaverState(myType.getWeaverState()), 
-                               getConstantPoolGen()));
+                               getConstantPool()));
        }
 
         //FIXME ATAJ needed only for slow Aspects.aspectOf() - keep or remove
@@ -500,17 +504,24 @@ public final class LazyClassGen {
 //        }
 
        addAjcInitializers();
-       
-        int len = methodGens.size();
-        myGen.setMethods(new Method[0]);
-        
+
         calculateSourceDebugExtensionOffsets();
+        
+        int len = methodGens.size();
+        myGen.setMethods(Method.NoMethods);
         for (int i = 0; i < len; i++) {
             LazyMethodGen gen = (LazyMethodGen) methodGens.get(i);
             // we skip empty clinits
             if (isEmptyClinit(gen)) continue;
             myGen.addMethod(gen.getMethod());
         }
+        len = fields.size();
+        myGen.setFields(Field.NoFields);
+        for (int i = 0; i < len; i++) {
+            BcelField gen = (BcelField) fields.get(i);
+            myGen.addField(gen.getField(this.constantPoolGen));
+        }
+        
                if (inlinedFiles.size() != 0) {
                        if (hasSourceDebugExtensionAttribute(myGen)) {
                                world.showMessage(
@@ -608,7 +619,7 @@ public final class LazyClassGen {
        private Signature createSignatureAttribute(String signature) {
                int nameIndex = constantPoolGen.addUtf8("Signature");
                int sigIndex  = constantPoolGen.addUtf8(signature);
-               return new Signature(nameIndex,2,sigIndex,constantPoolGen.getConstantPool());
+               return new Signature(nameIndex,2,sigIndex,constantPoolGen);
        }
 
        /**
@@ -632,7 +643,7 @@ public final class LazyClassGen {
        }
 
        private static boolean hasSourceDebugExtensionAttribute(ClassGen gen) {
-               ConstantPoolGen pool = gen.getConstantPool();
+               ConstantPool pool = gen.getConstantPool();
                Attribute[] attrs = gen.getAttributes();
                for (int i = 0; i < attrs.length; i++) {
                        if ("SourceDebugExtension"
@@ -796,7 +807,7 @@ public final class LazyClassGen {
        //System.err.println("checking clinig: " + gen);
        InstructionHandle start = gen.getBody().getStart();
        while (start != null) {
-               if (Range.isRangeHandle(start) || (start.getInstruction() instanceof RETURN)) {
+               if (Range.isRangeHandle(start) || (start.getInstruction().opcode==Constants.RETURN)) {
                        start = start.getNext();
                } else {
                        return false;
@@ -806,7 +817,7 @@ public final class LazyClassGen {
        return true;
     }
 
-    public ConstantPoolGen getConstantPoolGen() {
+    public ConstantPool getConstantPool() {
         return constantPoolGen;
     }
     
@@ -929,8 +940,9 @@ public final class LazyClassGen {
                } else {
                        jpType = isEnclosingJp?enclosingStaticTjpType:staticTjpType;
                }
-               ret = new FieldGen(modifiers,jpType,"ajc$tjp_" + tjpFields.size(),getConstantPoolGen()).getField();
-       addField(ret);
+               FieldGen fGen  = new FieldGen(modifiers,jpType,"ajc$tjp_" + tjpFields.size(),getConstantPool());
+       addField(fGen);
+       ret = fGen.getField();
        tjpFields.put(shadow, ret);
        return ret;
     }
@@ -943,11 +955,11 @@ public final class LazyClassGen {
 //                Modifier.PRIVATE | Modifier.FINAL | Modifier.STATIC,
 //                classType,
 //                "aj$class",
-//                getConstantPoolGen()).getField();
+//                getConstantPool()).getField();
 //        addField(ajClassField);
 //
 //        InstructionList il = new InstructionList();
-//        il.append(new PUSH(getConstantPoolGen(), getClassName()));
+//        il.append(new PUSH(getConstantPool(), getClassName()));
 //        il.append(fact.createInvoke("java.lang.Class", "forName", classType,
 //                    new Type[] {Type.STRING}, Constants.INVOKESTATIC));
 //        il.append(fact.createFieldAccess(getClassName(), ajClassField.getName(),
@@ -968,7 +980,7 @@ public final class LazyClassGen {
                if (il==null) {
                        il= new InstructionList();
                }
-           il.append(new PUSH(getConstantPoolGen(),calculatedSerialVersionUID));
+           il.append(InstructionFactory.PUSH(getConstantPool(),calculatedSerialVersionUID));
            il.append(getFactory().createFieldAccess(getClassName(), "serialVersionUID", BasicType.LONG, Constants.PUTSTATIC));
        }
        
@@ -984,11 +996,11 @@ public final class LazyClassGen {
        list.append(fact.createNew(factoryType));
        list.append(InstructionFactory.createDup(1));
        
-       list.append(new PUSH(getConstantPoolGen(), getFileName()));
+       list.append(InstructionFactory.PUSH(getConstantPool(), getFileName()));
        
        // load the current Class object
        //XXX check that this works correctly for inners/anonymous
-       list.append(new PUSH(getConstantPoolGen(), getClassName()));
+       list.append(InstructionFactory.PUSH(getConstantPool(), getClassName()));
        //XXX do we need to worry about the fact the theorectically this could throw
        //a ClassNotFoundException
        list.append(fact.createInvoke("java.lang.Class", "forName", classType,
@@ -1030,13 +1042,13 @@ public final class LazyClassGen {
        list.append(InstructionFactory.createLoad(factoryType, 0));
        
        // load the kind
-       list.append(new PUSH(getConstantPoolGen(), shadow.getKind().getName()));
+       list.append(InstructionFactory.PUSH(getConstantPool(), shadow.getKind().getName()));
        
        // create the signature
        list.append(InstructionFactory.createLoad(factoryType, 0));
        
        if (world.isTargettingAspectJRuntime12()) { // TAG:SUPPORTING12: We didn't have optimized factory methods in 1.2
-               list.append(new PUSH(getConstantPoolGen(), sig.getSignatureString(shadow.getWorld())));
+               list.append(InstructionFactory.PUSH(getConstantPool(), sig.getSignatureString(shadow.getWorld())));
                list.append(fact.createInvoke(factoryType.getClassName(), 
                                        sig.getSignatureMakerName(),
                                        new ObjectType(sig.getSignatureType()),
@@ -1045,13 +1057,13 @@ public final class LazyClassGen {
        } else  if (sig.getKind().equals(Member.METHOD)) {
                BcelWorld w = shadow.getWorld();
                // For methods, push the parts of the signature on.
-               list.append(new PUSH(getConstantPoolGen(),makeString(sig.getModifiers(w))));
-               list.append(new PUSH(getConstantPoolGen(),sig.getName()));
-               list.append(new PUSH(getConstantPoolGen(),makeString(sig.getDeclaringType())));
-               list.append(new PUSH(getConstantPoolGen(),makeString(sig.getParameterTypes())));
-               list.append(new PUSH(getConstantPoolGen(),makeString(sig.getParameterNames(w))));
-               list.append(new PUSH(getConstantPoolGen(),makeString(sig.getExceptions(w))));
-               list.append(new PUSH(getConstantPoolGen(),makeString(sig.getReturnType())));
+               list.append(InstructionFactory.PUSH(getConstantPool(),makeString(sig.getModifiers(w))));
+               list.append(InstructionFactory.PUSH(getConstantPool(),sig.getName()));
+               list.append(InstructionFactory.PUSH(getConstantPool(),makeString(sig.getDeclaringType())));
+               list.append(InstructionFactory.PUSH(getConstantPool(),makeString(sig.getParameterTypes())));
+               list.append(InstructionFactory.PUSH(getConstantPool(),makeString(sig.getParameterNames(w))));
+               list.append(InstructionFactory.PUSH(getConstantPool(),makeString(sig.getExceptions(w))));
+               list.append(InstructionFactory.PUSH(getConstantPool(),makeString(sig.getReturnType())));
                // And generate a call to the variant of makeMethodSig() that takes 7 strings
                list.append(fact.createInvoke(factoryType.getClassName(), 
                                sig.getSignatureMakerName(),
@@ -1059,14 +1071,14 @@ public final class LazyClassGen {
                                new Type[] { Type.STRING,Type.STRING,Type.STRING,Type.STRING,Type.STRING,Type.STRING,Type.STRING },
                                Constants.INVOKEVIRTUAL));
            } else if (sig.getKind().equals(Member.MONITORENTER)) {
-               list.append(new PUSH(getConstantPoolGen(),makeString(sig.getDeclaringType())));
+               list.append(InstructionFactory.PUSH(getConstantPool(),makeString(sig.getDeclaringType())));
                list.append(fact.createInvoke(factoryType.getClassName(), 
                                sig.getSignatureMakerName(),
                                new ObjectType(sig.getSignatureType()),
                                new Type[] { Type.STRING},
                                Constants.INVOKEVIRTUAL));
        } else if (sig.getKind().equals(Member.MONITOREXIT)) {
-               list.append(new PUSH(getConstantPoolGen(),makeString(sig.getDeclaringType())));
+               list.append(InstructionFactory.PUSH(getConstantPool(),makeString(sig.getDeclaringType())));
                list.append(fact.createInvoke(factoryType.getClassName(), 
                                sig.getSignatureMakerName(),
                                new ObjectType(sig.getSignatureType()),
@@ -1074,9 +1086,9 @@ public final class LazyClassGen {
                                Constants.INVOKEVIRTUAL));
        } else if (sig.getKind().equals(Member.HANDLER)) {
                BcelWorld w = shadow.getWorld();
-               list.append(new PUSH(getConstantPoolGen(),makeString(sig.getDeclaringType())));
-               list.append(new PUSH(getConstantPoolGen(),makeString(sig.getParameterTypes())));
-               list.append(new PUSH(getConstantPoolGen(),makeString(sig.getParameterNames(w))));
+               list.append(InstructionFactory.PUSH(getConstantPool(),makeString(sig.getDeclaringType())));
+               list.append(InstructionFactory.PUSH(getConstantPool(),makeString(sig.getParameterTypes())));
+               list.append(InstructionFactory.PUSH(getConstantPool(),makeString(sig.getParameterNames(w))));
                list.append(fact.createInvoke(factoryType.getClassName(),
                                sig.getSignatureMakerName(),
                                new ObjectType(sig.getSignatureType()),
@@ -1086,22 +1098,22 @@ public final class LazyClassGen {
                BcelWorld w = shadow.getWorld();
                if (w.isJoinpointArrayConstructionEnabled() && sig.getDeclaringType().isArray()) {
                        // its the magical new jp
-                       list.append(new PUSH(getConstantPoolGen(),makeString(Modifier.PUBLIC)));
-                       list.append(new PUSH(getConstantPoolGen(),makeString(sig.getDeclaringType())));
-                       list.append(new PUSH(getConstantPoolGen(),makeString(sig.getParameterTypes())));
-                       list.append(new PUSH(getConstantPoolGen(),""));//makeString("")));//sig.getParameterNames(w))));
-                       list.append(new PUSH(getConstantPoolGen(),""));//makeString("")));//sig.getExceptions(w))));
+                       list.append(InstructionFactory.PUSH(getConstantPool(),makeString(Modifier.PUBLIC)));
+                       list.append(InstructionFactory.PUSH(getConstantPool(),makeString(sig.getDeclaringType())));
+                       list.append(InstructionFactory.PUSH(getConstantPool(),makeString(sig.getParameterTypes())));
+                       list.append(InstructionFactory.PUSH(getConstantPool(),""));//makeString("")));//sig.getParameterNames(w))));
+                       list.append(InstructionFactory.PUSH(getConstantPool(),""));//makeString("")));//sig.getExceptions(w))));
                        list.append(fact.createInvoke(factoryType.getClassName(),
                                        sig.getSignatureMakerName(),
                                        new ObjectType(sig.getSignatureType()),
                                        new Type[] { Type.STRING, Type.STRING, Type.STRING, Type.STRING, Type.STRING },
                                        Constants.INVOKEVIRTUAL));      
                } else {
-                       list.append(new PUSH(getConstantPoolGen(),makeString(sig.getModifiers(w))));    
-                       list.append(new PUSH(getConstantPoolGen(),makeString(sig.getDeclaringType())));
-                       list.append(new PUSH(getConstantPoolGen(),makeString(sig.getParameterTypes())));
-                       list.append(new PUSH(getConstantPoolGen(),makeString(sig.getParameterNames(w))));
-                       list.append(new PUSH(getConstantPoolGen(),makeString(sig.getExceptions(w))));
+                       list.append(InstructionFactory.PUSH(getConstantPool(),makeString(sig.getModifiers(w))));        
+                       list.append(InstructionFactory.PUSH(getConstantPool(),makeString(sig.getDeclaringType())));
+                       list.append(InstructionFactory.PUSH(getConstantPool(),makeString(sig.getParameterTypes())));
+                       list.append(InstructionFactory.PUSH(getConstantPool(),makeString(sig.getParameterNames(w))));
+                       list.append(InstructionFactory.PUSH(getConstantPool(),makeString(sig.getExceptions(w))));
                        list.append(fact.createInvoke(factoryType.getClassName(),
                                        sig.getSignatureMakerName(),
                                        new ObjectType(sig.getSignatureType()),
@@ -1110,10 +1122,10 @@ public final class LazyClassGen {
                }
        } else if(sig.getKind().equals(Member.FIELD)) {
                BcelWorld w = shadow.getWorld();
-               list.append(new PUSH(getConstantPoolGen(),makeString(sig.getModifiers(w))));
-               list.append(new PUSH(getConstantPoolGen(),sig.getName()));
-               list.append(new PUSH(getConstantPoolGen(),makeString(sig.getDeclaringType())));
-               list.append(new PUSH(getConstantPoolGen(),makeString(sig.getReturnType())));
+               list.append(InstructionFactory.PUSH(getConstantPool(),makeString(sig.getModifiers(w))));
+               list.append(InstructionFactory.PUSH(getConstantPool(),sig.getName()));
+               list.append(InstructionFactory.PUSH(getConstantPool(),makeString(sig.getDeclaringType())));
+               list.append(InstructionFactory.PUSH(getConstantPool(),makeString(sig.getReturnType())));
                list.append(fact.createInvoke(factoryType.getClassName(),
                                sig.getSignatureMakerName(),
                                new ObjectType(sig.getSignatureType()),
@@ -1121,13 +1133,13 @@ public final class LazyClassGen {
                                Constants.INVOKEVIRTUAL));      
        } else if(sig.getKind().equals(Member.ADVICE)) {
                BcelWorld w = shadow.getWorld();
-               list.append(new PUSH(getConstantPoolGen(),makeString(sig.getModifiers(w))));
-               list.append(new PUSH(getConstantPoolGen(),sig.getName()));
-               list.append(new PUSH(getConstantPoolGen(),makeString(sig.getDeclaringType())));
-               list.append(new PUSH(getConstantPoolGen(),makeString(sig.getParameterTypes())));
-               list.append(new PUSH(getConstantPoolGen(),makeString(sig.getParameterNames(w))));
-               list.append(new PUSH(getConstantPoolGen(),makeString(sig.getExceptions(w))));
-               list.append(new PUSH(getConstantPoolGen(),makeString((sig.getReturnType()))));                  
+               list.append(InstructionFactory.PUSH(getConstantPool(),makeString(sig.getModifiers(w))));
+               list.append(InstructionFactory.PUSH(getConstantPool(),sig.getName()));
+               list.append(InstructionFactory.PUSH(getConstantPool(),makeString(sig.getDeclaringType())));
+               list.append(InstructionFactory.PUSH(getConstantPool(),makeString(sig.getParameterTypes())));
+               list.append(InstructionFactory.PUSH(getConstantPool(),makeString(sig.getParameterNames(w))));
+               list.append(InstructionFactory.PUSH(getConstantPool(),makeString(sig.getExceptions(w))));
+               list.append(InstructionFactory.PUSH(getConstantPool(),makeString((sig.getReturnType()))));              
                list.append(fact.createInvoke(factoryType.getClassName(),
                                sig.getSignatureMakerName(),
                                new ObjectType(sig.getSignatureType()),
@@ -1135,15 +1147,15 @@ public final class LazyClassGen {
                                Constants.INVOKEVIRTUAL));      
        } else if(sig.getKind().equals(Member.STATIC_INITIALIZATION)) {
                BcelWorld w = shadow.getWorld();
-               list.append(new PUSH(getConstantPoolGen(),makeString(sig.getModifiers(w))));
-               list.append(new PUSH(getConstantPoolGen(),makeString(sig.getDeclaringType())));
+               list.append(InstructionFactory.PUSH(getConstantPool(),makeString(sig.getModifiers(w))));
+               list.append(InstructionFactory.PUSH(getConstantPool(),makeString(sig.getDeclaringType())));
                list.append(fact.createInvoke(factoryType.getClassName(),
                                sig.getSignatureMakerName(),
                                new ObjectType(sig.getSignatureType()),
                                new Type[] { Type.STRING, Type.STRING },
                                Constants.INVOKEVIRTUAL));
        } else {
-         list.append(new PUSH(getConstantPoolGen(), sig.getSignatureString(shadow.getWorld())));
+         list.append(InstructionFactory.PUSH(getConstantPool(), sig.getSignatureString(shadow.getWorld())));
          list.append(fact.createInvoke(factoryType.getClassName(), 
                                   sig.getSignatureMakerName(),
                                   new ObjectType(sig.getSignatureType()),
@@ -1231,12 +1243,20 @@ public final class LazyClassGen {
                return myGen.getFileName();
        }
 
-       private void addField(Field field) {
-               myGen.addField(field);
+       // for *new* fields
+       private void addField(FieldGen field) {
                makeSyntheticAndTransientIfNeeded(field);
+               BcelField bcelField = null;
+               if (getBcelObjectType() != null) {
+                       bcelField = new BcelField(getBcelObjectType(),field.getField());
+               } else {
+                       bcelField = new BcelField(getName(),field.getField(),world);
+               }
+               fields.add(bcelField);
+//             myGen.addField(field.getField());
        }
        
-       private void makeSyntheticAndTransientIfNeeded(Field field) {
+       private void makeSyntheticAndTransientIfNeeded(FieldGen field) {
                if (field.getName().startsWith(NameMangler.PREFIX) &&
                        !field.getName().startsWith("ajc$interField$")) {
                        // it's an aj added field
@@ -1251,19 +1271,20 @@ public final class LazyClassGen {
                        }
                        if (!hasSyntheticAttribute(field.getAttributes())) {
                  // belt and braces, do the attribute even on Java 5 in addition to the modifier flag
-                         Attribute[] oldAttrs = field.getAttributes();
-                         Attribute[] newAttrs = new Attribute[oldAttrs.length + 1];
-                         System.arraycopy(oldAttrs, 0, newAttrs, 0, oldAttrs.length);
-                         ConstantPoolGen cpg = myGen.getConstantPool();
+//                       Attribute[] oldAttrs = field.getAttributes();
+//                       Attribute[] newAttrs = new Attribute[oldAttrs.length + 1];
+//                       System.arraycopy(oldAttrs, 0, newAttrs, 0, oldAttrs.length);
+                         ConstantPool cpg = myGen.getConstantPool();
                          int index = cpg.addUtf8("Synthetic");
-                         Attribute synthetic  = new Synthetic(index, 0, new byte[0], cpg.getConstantPool());
-                         newAttrs[newAttrs.length - 1] = synthetic;
-                         field.setAttributes(newAttrs);
+                         Attribute synthetic  = new Synthetic(index, 0, new byte[0], cpg);
+                         field.addAttribute(synthetic);
+//                       newAttrs[newAttrs.length - 1] = synthetic;
+//                       field.setAttributes(newAttrs);
                        }
                }
        }
        
-       private boolean hasSyntheticAttribute(Attribute[] attributes) {
+               private boolean hasSyntheticAttribute(Attribute[] attributes) {
                for (int i = 0; i < attributes.length; i++) {
                        if (attributes[i].getName().equals("Synthetic")) {
                                return true;
@@ -1271,13 +1292,8 @@ public final class LazyClassGen {
                }
                return false;
        }
-
-       public void replaceField(Field oldF, Field newF){
-               myGen.removeField(oldF);
-               myGen.addField(newF);
-       }
        
-       public void addField(Field field, ISourceLocation sourceLocation) {
+       public void addField(FieldGen field, ISourceLocation sourceLocation) {
                addField(field);
                if (!(field.isPrivate() 
                        && (field.isStatic() || field.isTransient()))) {
@@ -1341,9 +1357,9 @@ public final class LazyClassGen {
                return false;
        }
        
-       public void addAnnotation(Annotation a) {
+       public void addAnnotation(AnnotationGen a) {
                if (!hasAnnotation(UnresolvedType.forSignature(a.getTypeSignature()))) {
-                 annotations.add(new AnnotationGen(a,getConstantPoolGen(),true));
+                 annotations.add(new AnnotationGen(a,getConstantPool(),true));
                }
        }
        
@@ -1377,9 +1393,9 @@ public final class LazyClassGen {
         */
        public String allocateField(String prefix) {
                int highestAllocated = -1;
-               Field[] fs = getFieldGens();
-               for (int i = 0; i < fs.length; i++) {
-                       Field field = fs[i];
+               List/*BcelField*/ fs = getFieldGens();
+               for (int i = 0; i < fs.size(); i++) {
+                       BcelField field = (BcelField)fs.get(i);
                        if (field.getName().startsWith(prefix)) {
                                try {
                                        int num = Integer.parseInt(field.getName().substring(prefix.length()));
index ddb77ace9246552d566bb5659e0aa2c2462c810e..5859fa7573f5d2e8f9ba18dca1c2c6deec1958b1 100644 (file)
@@ -33,28 +33,24 @@ import org.aspectj.apache.bcel.classfile.Attribute;
 import org.aspectj.apache.bcel.classfile.ConstantPool;
 import org.aspectj.apache.bcel.classfile.Method;
 import org.aspectj.apache.bcel.classfile.Synthetic;
-import org.aspectj.apache.bcel.classfile.annotation.Annotation;
+import org.aspectj.apache.bcel.classfile.annotation.AnnotationGen;
 import org.aspectj.apache.bcel.generic.BranchHandle;
-import org.aspectj.apache.bcel.generic.BranchInstruction;
-import org.aspectj.apache.bcel.generic.CPInstruction;
 import org.aspectj.apache.bcel.generic.ClassGenException;
 import org.aspectj.apache.bcel.generic.CodeExceptionGen;
-import org.aspectj.apache.bcel.generic.ConstantPoolGen;
 import org.aspectj.apache.bcel.generic.Instruction;
+import org.aspectj.apache.bcel.generic.InstructionBranch;
 import org.aspectj.apache.bcel.generic.InstructionHandle;
 import org.aspectj.apache.bcel.generic.InstructionList;
+import org.aspectj.apache.bcel.generic.InstructionSelect;
 import org.aspectj.apache.bcel.generic.InstructionTargeter;
 import org.aspectj.apache.bcel.generic.LineNumberGen;
 import org.aspectj.apache.bcel.generic.LineNumberTag;
 import org.aspectj.apache.bcel.generic.LocalVariableGen;
-import org.aspectj.apache.bcel.generic.LocalVariableInstruction;
 import org.aspectj.apache.bcel.generic.LocalVariableTag;
 import org.aspectj.apache.bcel.generic.MethodGen;
 import org.aspectj.apache.bcel.generic.ObjectType;
-import org.aspectj.apache.bcel.generic.Select;
 import org.aspectj.apache.bcel.generic.Tag;
 import org.aspectj.apache.bcel.generic.Type;
-import org.aspectj.apache.bcel.generic.annotation.AnnotationGen;
 import org.aspectj.bridge.IMessage;
 import org.aspectj.bridge.ISourceLocation;
 import org.aspectj.bridge.MessageUtil;
@@ -226,6 +222,33 @@ public final class LazyMethodGen implements Traceable {
             }
         }
     }
+    public LazyMethodGen(BcelMethod m,LazyClassGen enclosingClass) {
+       savedMethod = m.getMethod();
+       this.enclosingClass = enclosingClass;
+        if (!(m.isAbstract() || m.isNative()) && savedMethod.getCode() == null) {
+               throw new RuntimeException("bad non-abstract method with no code: " + m + " on " + enclosingClass);
+        }
+        if ((m.isAbstract() || m.isNative()) && savedMethod.getCode() != null) {
+               throw new RuntimeException("bad abstract method with code: " + m + " on " + enclosingClass);
+        }
+               //this.memberView = new BcelMethod(enclosingClass.getBcelObjectType(), m);
+        this.memberView = m;
+               this.accessFlags = savedMethod.getAccessFlags();
+               this.name = m.getName();
+
+        // @AJ advice are not inlined by default since requires further analysis
+        // and weaving ordering control
+        // TODO AV - improve - note: no room for improvement as long as aspects are reweavable
+        // since the inlined version with wrappers and an to be done annotation to keep
+        // inline state will be garbaged due to reweavable impl
+        if (memberView != null && isAdviceMethod()) {
+            if (enclosingClass.getType().isAnnotationStyleAspect()) {
+                //TODO we could check for @Around advice as well
+                this.canInline = false;
+            }
+        }
+       
+    }
     
     public boolean hasDeclaredLineNumberInfo() {
        return (memberView != null && memberView.hasDeclarationLineNumberInfo());
@@ -292,7 +315,7 @@ public final class LazyMethodGen implements Traceable {
        
        //System.err.println("initializing: " + getName() + ", " + enclosingClass.getName() + ", " + returnType + ", " + savedMethod);
        
-               MethodGen gen = new MethodGen(savedMethod, enclosingClass.getName(), enclosingClass.getConstantPoolGen(),avoidUseOfBcelGenObjects);
+               MethodGen gen = new MethodGen(savedMethod, enclosingClass.getName(), enclosingClass.getConstantPool(),avoidUseOfBcelGenObjects);
         
                this.returnType = gen.getReturnType();
                this.argumentTypes = gen.getArgumentTypes();
@@ -606,7 +629,7 @@ public final class LazyMethodGen implements Traceable {
         List ranges;
 
         BodyPrinter(PrintStream out) {
-            this.pool = enclosingClass.getConstantPoolGen().getConstantPool();
+            this.pool = enclosingClass.getConstantPool();
             this.body = getBody();
             this.out = out;
         }
@@ -634,7 +657,7 @@ public final class LazyMethodGen implements Traceable {
                             if (r.getStart() == ih) {
                                 insertHandler(r, exnTable);
                             }
-                        } else if (t instanceof BranchInstruction) {
+                        } else if (t instanceof InstructionBranch) {
                             if (pendingLabel == null) {
                                 pendingLabel = "L" + lcounter++;
                             }
@@ -736,14 +759,13 @@ public final class LazyMethodGen implements Traceable {
             printLabel((String) labelMap.get(h), depth);   
            
             Instruction inst = h.getInstruction();
-            if (inst instanceof CPInstruction) {
-                CPInstruction cpinst = (CPInstruction) inst;
-                out.print(Constants.OPCODE_NAMES[cpinst.getOpcode()].toUpperCase());
+            if (inst.isConstantPoolInstruction()) {
+                out.print(Constants.OPCODE_NAMES[inst.opcode].toUpperCase());
                 out.print(" ");
-                out.print(pool.constantToString(pool.getConstant(cpinst.getIndex())));
-            } else if (inst instanceof Select) {
-                Select sinst = (Select) inst;
-                out.println(Constants.OPCODE_NAMES[sinst.getOpcode()].toUpperCase());
+                out.print(pool.constantToString(pool.getConstant(inst.getIndex())));
+            } else if (inst instanceof InstructionSelect) {
+               InstructionSelect sinst = (InstructionSelect) inst;
+                out.println(Constants.OPCODE_NAMES[sinst.opcode].toUpperCase());
                 int[] matches = sinst.getMatchs();
                 InstructionHandle[] targets = sinst.getTargets();
                 InstructionHandle defaultTarget = sinst.getTarget();
@@ -760,15 +782,15 @@ public final class LazyMethodGen implements Traceable {
                 out.print("  ");
                 out.print("default: \t");
                 out.print(labelMap.get(defaultTarget));
-            } else if (inst instanceof BranchInstruction) {
-                BranchInstruction brinst = (BranchInstruction) inst;
+            } else if (inst instanceof InstructionBranch) {
+               InstructionBranch brinst = (InstructionBranch) inst;
                 out.print(Constants.OPCODE_NAMES[brinst.getOpcode()].toUpperCase());
                 out.print(" ");
                 out.print(labelMap.get(brinst.getTarget()));
-            } else if (inst instanceof LocalVariableInstruction) {
-                LocalVariableInstruction lvinst = (LocalVariableInstruction) inst;
+            } else if (inst.isLocalVariableInstruction()) {
+                //LocalVariableInstruction lvinst = (LocalVariableInstruction) inst;
                 out.print(inst.toString(false).toUpperCase());
-                int index = lvinst.getIndex();
+                int index = inst.getIndex();
                 LocalVariableTag tag = getLocalVariableTag(h, index);
                 if (tag != null) {
                     out.print("     // ");
@@ -939,7 +961,7 @@ public final class LazyMethodGen implements Traceable {
                 getName(),
                 getEnclosingClass().getName(),
                 new InstructionList(),
-                getEnclosingClass().getConstantPoolGen());
+                getEnclosingClass().getConstantPool());
         for (int i = 0, len = declaredExceptions.length; i < len; i++) {
             gen.addException(declaredExceptions[i]);
         }
@@ -958,7 +980,7 @@ public final class LazyMethodGen implements Traceable {
         if (memberView!=null && memberView.getAnnotations()!=null && memberView.getAnnotations().length!=0) {
                  AnnotationX[] ans = memberView.getAnnotations();
           for (int i = 0, len = ans.length; i < len; i++) {
-                       Annotation a= ans[i].getBcelAnnotation();
+                       AnnotationGen a= ans[i].getBcelAnnotation();
             gen.addAnnotation(new AnnotationGen(a,gen.getConstantPool(),true));
           }
         }
@@ -968,9 +990,9 @@ public final class LazyMethodGen implements Traceable {
                        gen.setModifiers(gen.getModifiers() | ACC_SYNTHETIC);
                }
                // belt and braces, do the attribute even on Java 5 in addition to the modifier flag
-                       ConstantPoolGen cpg = gen.getConstantPool();
+                       ConstantPool cpg = gen.getConstantPool();
                        int index = cpg.addUtf8("Synthetic");
-                       gen.addAttribute(new Synthetic(index, 0, new byte[0], cpg.getConstantPool()));                  
+                       gen.addAttribute(new Synthetic(index, 0, new byte[0], cpg));                    
         }
         
         if (hasBody()) {
@@ -1037,7 +1059,7 @@ public final class LazyMethodGen implements Traceable {
                 Instruction oldInstruction = oldInstructionHandle.getInstruction();
                 Instruction newInstruction = newInstructionHandle.getInstruction();
     
-                       if (oldInstruction instanceof BranchInstruction) {
+                       if (oldInstruction instanceof InstructionBranch) {
                                handleBranchInstruction(map, oldInstruction, newInstruction);
                        }
                 
@@ -1140,8 +1162,8 @@ public final class LazyMethodGen implements Traceable {
        }
 
        private void handleBranchInstruction(Map map, Instruction oldInstruction, Instruction newInstruction) {
-           BranchInstruction oldBranchInstruction = (BranchInstruction) oldInstruction;
-           BranchInstruction newBranchInstruction = (BranchInstruction) newInstruction;
+               InstructionBranch oldBranchInstruction = (InstructionBranch) oldInstruction;
+               InstructionBranch newBranchInstruction = (InstructionBranch) newInstruction;
            InstructionHandle oldTarget = oldBranchInstruction.getTarget(); // old target
    
 //                             try {
@@ -1154,10 +1176,10 @@ public final class LazyMethodGen implements Traceable {
 //                                     throw e;
 //                             }
    
-                   if (oldBranchInstruction instanceof Select) { 
+                   if (oldBranchInstruction instanceof InstructionSelect) { 
                        // Either LOOKUPSWITCH or TABLESWITCH
-                       InstructionHandle[] oldTargets = ((Select) oldBranchInstruction).getTargets();
-                       InstructionHandle[] newTargets = ((Select) newBranchInstruction).getTargets();
+                       InstructionHandle[] oldTargets = ((InstructionSelect) oldBranchInstruction).getTargets();
+                       InstructionHandle[] newTargets = ((InstructionSelect) newBranchInstruction).getTargets();
    
                        for (int k = oldTargets.length - 1; k >= 0; k--) { 
                            // Update all targets
@@ -1198,8 +1220,8 @@ public final class LazyMethodGen implements Traceable {
             Instruction i = ih.getInstruction();
             Instruction c = Utility.copyInstruction(i);
 
-            if (c instanceof BranchInstruction)
-                map.put(ih, intoList.append((BranchInstruction) c));
+            if (c instanceof InstructionBranch)
+                map.put(ih, intoList.append((InstructionBranch) c));
             else
                 map.put(ih, intoList.append(c));
         }
@@ -1335,7 +1357,7 @@ public final class LazyMethodGen implements Traceable {
                Stack ranges = new Stack();
                for (InstructionHandle ih = il.getStart(); ih != null; ih = ih.getNext()) {
                        body.add(ih);
-                       if (ih.getInstruction() instanceof BranchInstruction) {
+                       if (ih.getInstruction() instanceof InstructionBranch) {
                                body.add(ih.getInstruction());
                        }
                }
@@ -1353,19 +1375,19 @@ public final class LazyMethodGen implements Traceable {
 
        private static void assertGoodHandle(InstructionHandle ih, Set body, Stack ranges, String from) {
                Instruction inst = ih.getInstruction();
-               if ((inst instanceof BranchInstruction) ^ (ih instanceof BranchHandle)) {
+               if ((inst instanceof InstructionBranch) ^ (ih instanceof BranchHandle)) {
                        throw new BCException("bad instruction/handle pair in " + from);
                }
                if (Range.isRangeHandle(ih)) {
                        assertGoodRangeHandle(ih, body, ranges, from);
-               } else if (inst instanceof BranchInstruction) {
-                       assertGoodBranchInstruction((BranchHandle) ih, (BranchInstruction) inst, body, ranges, from);
+               } else if (inst instanceof InstructionBranch) {
+                       assertGoodBranchInstruction((BranchHandle) ih, (InstructionBranch) inst, body, ranges, from);
                }
        }
 
        private static void assertGoodBranchInstruction(
                BranchHandle ih,
-               BranchInstruction inst,
+               InstructionBranch inst,
                Set body,
                Stack ranges,
                String from)
@@ -1376,8 +1398,8 @@ public final class LazyMethodGen implements Traceable {
                InstructionHandle target = ih.getTarget();
                assertInBody(target, body, from);
                assertTargetedBy(target, inst, from);
-               if (inst instanceof Select) {
-                       Select sel = (Select) inst;
+               if (inst instanceof InstructionSelect) {
+                       InstructionSelect sel = (InstructionSelect) inst;
             InstructionHandle[] itargets = sel.getTargets();
             for (int k = itargets.length - 1; k >= 0; k--) { 
                                assertInBody(itargets[k], body, from);
@@ -1443,11 +1465,11 @@ public final class LazyMethodGen implements Traceable {
                        if (r instanceof ExceptionRange) {
                                if (((ExceptionRange)r).getHandler() == target) return;
                        }
-               } else if (targeter instanceof BranchInstruction) {
-                       BranchInstruction bi = (BranchInstruction) targeter;
+               } else if (targeter instanceof InstructionBranch) {
+                       InstructionBranch bi = (InstructionBranch) targeter;
                        if (bi.getTarget() == target) return;
-                       if (targeter instanceof Select) {
-                               Select sel = (Select) targeter;
+                       if (targeter instanceof InstructionSelect) {
+                               InstructionSelect sel = (InstructionSelect) targeter;
                    InstructionHandle[] itargets = sel.getTargets();
                    for (int k = itargets.length - 1; k >= 0; k--) { 
                                        if (itargets[k] == target) return;
@@ -1482,7 +1504,7 @@ public final class LazyMethodGen implements Traceable {
        assertTargets(t, ih, from);
                if (t instanceof Range) {
                        assertGoodRange((Range) t, body, from);
-               } else if (t instanceof BranchInstruction) {
+               } else if (t instanceof InstructionBranch) {
                        assertInBody(t, body, from);
                }
     }
index c7f9bd29c7426fcf406dd117feeebebb0d61b259..c6fd1aa3c76fb8c2285e0d8073ef64eec37fd366 100644 (file)
@@ -15,8 +15,8 @@ package org.aspectj.weaver.bcel;
 
 import java.util.Map;
 
-import org.aspectj.apache.bcel.generic.IMPDEP1;
 import org.aspectj.apache.bcel.generic.Instruction;
+import org.aspectj.apache.bcel.generic.InstructionConstants;
 import org.aspectj.apache.bcel.generic.InstructionHandle;
 import org.aspectj.apache.bcel.generic.InstructionList;
 import org.aspectj.apache.bcel.generic.InstructionTargeter;
@@ -224,7 +224,7 @@ abstract class Range implements InstructionTargeter {
 
     // note that this is STUPIDLY copied by Instruction.copy(), so don't do that.
 
-    public static final Instruction RANGEINSTRUCTION = new IMPDEP1();
+    public static final Instruction RANGEINSTRUCTION = InstructionConstants.IMPDEP1;
     
     // ----
 
index 2415a6f6cf0af5d36cd4979e85c4dc52d0858902..93f0dba4fdcc487b7a3990753e65ab718280b4ef 100644 (file)
 
 package org.aspectj.weaver.bcel;
 
-import org.aspectj.apache.bcel.generic.BranchInstruction;
-import org.aspectj.apache.bcel.generic.IndexedInstruction;
 import org.aspectj.apache.bcel.generic.Instruction;
+import org.aspectj.apache.bcel.generic.InstructionBranch;
 import org.aspectj.apache.bcel.generic.InstructionFactory;
 import org.aspectj.apache.bcel.generic.InstructionHandle;
 import org.aspectj.apache.bcel.generic.InstructionList;
+import org.aspectj.apache.bcel.generic.InstructionSelect;
 import org.aspectj.apache.bcel.generic.InstructionTargeter;
-import org.aspectj.apache.bcel.generic.LocalVariableInstruction;
 import org.aspectj.apache.bcel.generic.LocalVariableTag;
 import org.aspectj.apache.bcel.generic.RET;
-import org.aspectj.apache.bcel.generic.Select;
 import org.aspectj.apache.bcel.generic.TargetLostException;
 import org.aspectj.weaver.BCException;
 import org.aspectj.weaver.IntMap;
@@ -76,17 +74,17 @@ final class ShadowRange extends Range {
 
                        // Now we add it to the new instruction list.
             InstructionHandle freshIh;
-            if (freshI instanceof BranchInstruction) {
+            if (freshI instanceof InstructionBranch) {
                                //If it's a targeting instruction,
                        // update the target(s) to point to the new copy instead of the old copy.
-               BranchInstruction oldBranch = (BranchInstruction) oldI;
-               BranchInstruction freshBranch = (BranchInstruction) freshI;
+               InstructionBranch oldBranch = (InstructionBranch) oldI;
+               InstructionBranch freshBranch = (InstructionBranch) freshI;
                                InstructionHandle oldTarget = oldBranch.getTarget();
                                oldTarget.removeTargeter(oldBranch);
                                oldTarget.addTargeter(freshBranch);
-                               if (freshBranch instanceof Select) {
-                                       Select oldSelect = (Select) oldI;
-                                       Select freshSelect = (Select) freshI;
+                               if (freshBranch instanceof InstructionSelect) {
+                                       InstructionSelect oldSelect = (InstructionSelect) oldI;
+                                       InstructionSelect freshSelect = (InstructionSelect) freshI;
                                        InstructionHandle[] oldTargets = freshSelect.getTargets();
                                        for (int k = oldTargets.length - 1; k >= 0; k--) {
                                                oldTargets[k].removeTargeter(oldSelect);
@@ -161,9 +159,9 @@ final class ShadowRange extends Range {
                        // do compaction/expansion: allocate a new local variable, and modify the remap
                        // to handle it.  XXX We're doing the safe thing and allocating ALL these local variables
                        // as double-wides, in case the location is found to hold a double-wide later.
-            if (freshI instanceof LocalVariableInstruction || freshI instanceof RET) {
-               IndexedInstruction indexedI = (IndexedInstruction) freshI;
-                int oldIndex = indexedI.getIndex();
+            if (freshI.isLocalVariableInstruction() || freshI instanceof RET) {
+//             IndexedInstruction indexedI = (IndexedInstruction) freshI;
+                int oldIndex = freshI.getIndex();
                int freshIndex;
                 if (! remap.hasKey(oldIndex)) {
                     freshIndex = freshMethod.allocateLocal(2);
@@ -171,7 +169,7 @@ final class ShadowRange extends Range {
                 } else {
                     freshIndex = remap.get(oldIndex);
                 }
-                indexedI.setIndex(freshIndex);
+                freshI.setIndex(freshIndex);
             }
 //            System.err.println("JUST COPIED: " + oldIh.getInstruction().toString(freshMethod.getEnclosingClass().getConstantPoolGen().getConstantPool()) 
 //             + " INTO " + freshIh.getInstruction().toString(freshMethod.getEnclosingClass().getConstantPoolGen().getConstantPool()));
index c6e735cf80fa30bf16bbfd1a0fe0e347bcecc798..1f0db781bbc3065cae39f7eb7fc331bef578a7f4 100644 (file)
@@ -27,30 +27,28 @@ import org.aspectj.apache.bcel.Constants;
 import org.aspectj.apache.bcel.classfile.ClassParser;
 import org.aspectj.apache.bcel.classfile.JavaClass;
 import org.aspectj.apache.bcel.classfile.Method;
-import org.aspectj.apache.bcel.classfile.annotation.ArrayElementValue;
-import org.aspectj.apache.bcel.classfile.annotation.ElementNameValuePair;
-import org.aspectj.apache.bcel.classfile.annotation.ElementValue;
-import org.aspectj.apache.bcel.classfile.annotation.SimpleElementValue;
+import org.aspectj.apache.bcel.classfile.annotation.ArrayElementValueGen;
+import org.aspectj.apache.bcel.classfile.annotation.ElementNameValuePairGen;
+import org.aspectj.apache.bcel.classfile.annotation.ElementValueGen;
+import org.aspectj.apache.bcel.classfile.annotation.SimpleElementValueGen;
 import org.aspectj.apache.bcel.generic.ArrayType;
-import org.aspectj.apache.bcel.generic.BIPUSH;
 import org.aspectj.apache.bcel.generic.BasicType;
-import org.aspectj.apache.bcel.generic.BranchInstruction;
-import org.aspectj.apache.bcel.generic.ConstantPushInstruction;
-import org.aspectj.apache.bcel.generic.INSTANCEOF;
 import org.aspectj.apache.bcel.generic.Instruction;
+import org.aspectj.apache.bcel.generic.InstructionBranch;
+import org.aspectj.apache.bcel.generic.InstructionByte;
+import org.aspectj.apache.bcel.generic.InstructionCP;
 import org.aspectj.apache.bcel.generic.InstructionConstants;
 import org.aspectj.apache.bcel.generic.InstructionFactory;
 import org.aspectj.apache.bcel.generic.InstructionHandle;
 import org.aspectj.apache.bcel.generic.InstructionList;
+import org.aspectj.apache.bcel.generic.InstructionSelect;
+import org.aspectj.apache.bcel.generic.InstructionShort;
 import org.aspectj.apache.bcel.generic.InstructionTargeter;
 import org.aspectj.apache.bcel.generic.InvokeInstruction;
-import org.aspectj.apache.bcel.generic.LDC;
 import org.aspectj.apache.bcel.generic.LineNumberTag;
 import org.aspectj.apache.bcel.generic.ObjectType;
 import org.aspectj.apache.bcel.generic.ReferenceType;
-import org.aspectj.apache.bcel.generic.SIPUSH;
-import org.aspectj.apache.bcel.generic.SWITCH;
-import org.aspectj.apache.bcel.generic.Select;
+import org.aspectj.apache.bcel.generic.SwitchBuilder;
 import org.aspectj.apache.bcel.generic.TargetLostException;
 import org.aspectj.apache.bcel.generic.Type;
 import org.aspectj.bridge.ISourceLocation;
@@ -231,7 +229,7 @@ public class Utility {
                        (t instanceof ArrayType)
                        ? fact.getConstantPool().addArrayClass((ArrayType)t)
                        : fact.getConstantPool().addClass((ObjectType)t);
-               return new INSTANCEOF(cpoolEntry);
+               return new InstructionCP(Constants.INSTANCEOF,cpoolEntry);
     }
 
     public static Instruction createInvoke(
@@ -384,8 +382,15 @@ public class Utility {
             Type from = BcelWorld.makeBcelType(fromType);
             Type to = BcelWorld.makeBcelType(toType);
             try {
-                il.append(fact.createCast(from, to));
+               Instruction i = fact.createCast(from, to);
+               if (i!=null) {
+                       il.append(i);
+               } else {
+                       il.append(fact.createCast(from, Type.INT));
+                    il.append(fact.createCast(Type.INT, to));
+               }
             } catch (RuntimeException e) {
+               e.printStackTrace();
                 il.append(fact.createCast(from, Type.INT));
                 il.append(fact.createCast(Type.INT, to));
             }
@@ -513,11 +518,12 @@ public class Utility {
                        case 5: inst =  InstructionConstants.ICONST_5;  break;  
                }
                if (i <= Byte.MAX_VALUE && i >= Byte.MIN_VALUE) {
-               inst =  new BIPUSH((byte)i);
+               inst =  new InstructionByte(Constants.BIPUSH,(byte)i);
                } else if (i <= Short.MAX_VALUE && i >= Short.MIN_VALUE) {
-                       inst =  new SIPUSH((short)i);
+                       inst =  new InstructionShort(Constants.SIPUSH,(short)i);
                } else {
-                       inst =  new LDC(fact.getClassGen().getConstantPool().addInteger(i));
+                     int ii = fact.getClassGen().getConstantPool().addInteger(i);
+                     inst = new InstructionCP(i<=Constants.MAX_BYTE?Constants.LDC:Constants.LDC_W,ii);
                }
                return inst;
        }
@@ -557,7 +563,7 @@ public class Utility {
         */
     public static void replaceInstruction(
         InstructionHandle ih,
-        BranchInstruction branchInstruction,
+        InstructionBranch branchInstruction,
         LazyMethodGen enclosingMethod) 
     {
         
@@ -635,8 +641,8 @@ public class Utility {
         * </pre>
         */
        public static Instruction copyInstruction(Instruction i) {
-               if (i instanceof Select) {
-                       Select freshSelect = (Select)i;
+               if (i instanceof InstructionSelect) {
+                       InstructionSelect freshSelect = (InstructionSelect)i;
                                  
                        // Create a new targets array that looks just like the existing one
                        InstructionHandle[] targets = new InstructionHandle[freshSelect.getTargets().length];
@@ -645,9 +651,8 @@ public class Utility {
                        }
                                  
                        // Create a new select statement with the new targets array
-                       SWITCH switchStatement =
-                               new SWITCH(freshSelect.getMatchs(), targets, freshSelect.getTarget());
-                       return (Select)switchStatement.getInstruction();        
+                               
+                       return new SwitchBuilder(freshSelect.getMatchs(), targets, freshSelect.getTarget()).getInstruction();   
                } else {
                        return i.copy(); // Use clone for shallow copy...
                }
@@ -729,7 +734,8 @@ public class Utility {
        }
 
        public static boolean isConstantPushInstruction(Instruction i) {
-               return (i instanceof ConstantPushInstruction) || (i instanceof LDC);
+               long ii= Constants.instFlags[i.opcode];
+               return ((ii&Constants.PUSH_INST)!=0 && (ii&Constants.CONSTANT_INST)!=0);
        }
        
        /**
@@ -753,11 +759,11 @@ public class Utility {
                 suppressed = true;
             } else { // (2)
                // We know the value is an array value
-               ArrayElementValue array = (ArrayElementValue)((ElementNameValuePair)vals.get(0)).getValue();
-               ElementValue[] values = array.getElementValuesArray();
+               ArrayElementValueGen array = (ArrayElementValueGen)((ElementNameValuePairGen)vals.get(0)).getValue();
+               ElementValueGen[] values = array.getElementValuesArray();
                for (int j = 0; j < values.length; j++) {
                        // We know values in the array are strings
-                                       SimpleElementValue value = (SimpleElementValue)values[j];
+                                       SimpleElementValueGen value = (SimpleElementValueGen)values[j];
                                        if (value.getValueString().equals(lintkey)) {
                                                suppressed = true;
                                        }
@@ -785,11 +791,11 @@ public class Utility {
                suppressedWarnings.addAll(lint.allKinds());
             } else { // (2)
                // We know the value is an array value
-               ArrayElementValue array = (ArrayElementValue)((ElementNameValuePair)vals.get(0)).getValue();
-               ElementValue[] values = array.getElementValuesArray();
+               ArrayElementValueGen array = (ArrayElementValueGen)((ElementNameValuePairGen)vals.get(0)).getValue();
+               ElementValueGen[] values = array.getElementValuesArray();
                for (int j = 0; j < values.length; j++) {
                        // We know values in the array are strings
-                                       SimpleElementValue value = (SimpleElementValue)values[j];
+                                       SimpleElementValueGen value = (SimpleElementValueGen)values[j];
                                        Lint.Kind lintKind = lint.getLintKind(value.getValueString());
                                        if (lintKind != null) suppressedWarnings.add(lintKind);
                                }
@@ -807,12 +813,12 @@ public class Utility {
                InstructionHandle InstrHandle = instrucs.getStart();
                while (InstrHandle != null) {                  
                  Instruction Instr = InstrHandle.getInstruction();
-                 int opCode = Instr.getOpcode();
+                 int opCode = Instr.opcode;
                  // if current instruction is a branch instruction, see if it's a backward branch.
                  // if it is return immediately (can't be trivial)
-                 if (Instr instanceof BranchInstruction) {
-                     BranchInstruction BI = (BranchInstruction) Instr;
-                     if (BI.getIndex() < 0) return false;
+                 if (Instr instanceof InstructionBranch) {
+                       //  InstructionBranch BI = (InstructionBranch) Instr;
+                     if (Instr.getIndex() < 0) return false;
                  } else if (Instr instanceof InvokeInstruction) {
                          // if current instruction is an invocation, indicate that it can't be trivial
                      return false;