]> source.dussan.org Git - aspectj.git/commitdiff
fix for failing test case that aspects must be constructed after their
authorjhugunin <jhugunin>
Wed, 22 Jan 2003 01:25:44 +0000 (01:25 +0000)
committerjhugunin <jhugunin>
Wed, 22 Jan 2003 01:25:44 +0000 (01:25 +0000)
clinit has run

14 files changed:
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/AspectClinit.java
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/AspectDeclaration.java
tests/new/options11/aspectlib1.jar
tests/new/options11/aspectlib2.jar
tests/new/options11/injar.jar
weaver/src/org/aspectj/weaver/AjcMemberMaker.java
weaver/src/org/aspectj/weaver/NameMangler.java
weaver/src/org/aspectj/weaver/bcel/BcelCflowStackFieldAdder.java
weaver/src/org/aspectj/weaver/bcel/BcelShadow.java
weaver/src/org/aspectj/weaver/bcel/LazyClassGen.java
weaver/testdata/dummyAspect.jar
weaver/testdata/megatrace.jar
weaver/testdata/megatraceNoweave.jar
weaver/testdata/tracing.jar

index d82e00cf00c68ea0f4309dba4c8cd712a696a6a1..4c929b91cabdcb7854c39909397b52d1b2213dd3 100644 (file)
@@ -21,28 +21,49 @@ import org.eclipse.jdt.internal.compiler.codegen.CodeStream;
 import org.eclipse.jdt.internal.compiler.lookup.ClassScope;
 
 public class AspectClinit extends Clinit {
-       public AspectClinit(Clinit old, CompilationResult compilationResult) {
+       private boolean hasPre, hasPost;
+       
+       public AspectClinit(Clinit old, CompilationResult compilationResult, boolean hasPre, boolean hasPost) {
                super(compilationResult);
                this.needFreeReturn = old.needFreeReturn;
                this.sourceEnd = old.sourceEnd;
                this.sourceStart = old.sourceStart;
                this.declarationSourceEnd = old.declarationSourceEnd;
                this.declarationSourceStart = old.declarationSourceStart;
+               
+               this.hasPre = hasPre;
+               this.hasPost = hasPost;
        }
 
        protected void generateSyntheticCode(
                ClassScope classScope,
                CodeStream codeStream) 
        {
-               if (!classScope.referenceContext.binding.isAbstract()) {
+               if (hasPre) {
                        final EclipseWorld world = EclipseWorld.fromScopeLookupEnvironment(classScope);
 
                        codeStream.invokestatic(world.makeMethodBindingForCall(
-                               AjcMemberMaker.ajcClinitMethod(
+                               AjcMemberMaker.ajcPreClinitMethod(
                                        world.fromBinding(classScope.referenceContext.binding)
                                )));
                }
                super.generateSyntheticCode(classScope, codeStream);
        }
+       
+       protected void generatePostSyntheticCode(
+               ClassScope classScope,
+               CodeStream codeStream)
+       {
+               super.generatePostSyntheticCode(classScope, codeStream);
+               if (hasPost) {
+                       final EclipseWorld world = EclipseWorld.fromScopeLookupEnvironment(classScope);
+
+                       codeStream.invokestatic(world.makeMethodBindingForCall(
+                               AjcMemberMaker.ajcPostClinitMethod(
+                                       world.fromBinding(classScope.referenceContext.binding)
+                               )));
+               }
+               
+       }
 
 }
index 1ce398ea45816f4c7da08f60be081700c38d7d77..2ea980df50363102988ecf2661ea32fa55216edb 100644 (file)
@@ -169,13 +169,13 @@ public class AspectDeclaration extends MemberTypeDeclaration {
                        } else if (perClause.getKind() == PerClause.SINGLETON) {
                                binding.addField(world.makeFieldBinding(AjcMemberMaker.perSingletonField(
                                                typeX)));
-                               methods[0] = new AspectClinit((Clinit)methods[0], compilationResult);
+                               methods[0] = new AspectClinit((Clinit)methods[0], compilationResult, false, true);
                        } else if (perClause.getKind() == PerClause.PERCFLOW) {
                                binding.addField(
                                        world.makeFieldBinding(
                                                AjcMemberMaker.perCflowField(
                                                        typeX)));
-                               methods[0] = new AspectClinit((Clinit)methods[0], compilationResult);
+                               methods[0] = new AspectClinit((Clinit)methods[0], compilationResult, true, false);
                        } else if (perClause.getKind() == PerClause.PEROBJECT) {
 //                             binding.addField(
 //                                     world.makeFieldBinding(
@@ -367,7 +367,7 @@ public class AspectDeclaration extends MemberTypeDeclaration {
                ClassFile classFile) 
        {
                final EclipseWorld world = EclipseWorld.fromScopeLookupEnvironment(this.scope);
-               generateMethod(classFile, world.makeMethodBinding(AjcMemberMaker.ajcClinitMethod(
+               generateMethod(classFile, world.makeMethodBinding(AjcMemberMaker.ajcPreClinitMethod(
                                world.fromBinding(binding))), 
                new BodyGenerator() {
                        public void generate(CodeStream codeStream) {
@@ -549,7 +549,7 @@ public class AspectDeclaration extends MemberTypeDeclaration {
                ClassFile classFile) 
        {
                final EclipseWorld world = EclipseWorld.fromScopeLookupEnvironment(this.scope);
-               generateMethod(classFile, world.makeMethodBinding(AjcMemberMaker.ajcClinitMethod(
+               generateMethod(classFile, world.makeMethodBinding(AjcMemberMaker.ajcPostClinitMethod(
                                world.fromBinding(binding))), 
                new BodyGenerator() {
                        public void generate(CodeStream codeStream) {
index fe2883cb42e9a5d022cca131bd182c06e84c11ac..4028b829cd7bb378241bb0090126ae41e2cb00da 100644 (file)
Binary files a/tests/new/options11/aspectlib1.jar and b/tests/new/options11/aspectlib1.jar differ
index 816803da4017ab18e638c837324ed036bcecee9e..698acc6381b3d26d739a0a0810317cb4f14d8aa5 100644 (file)
Binary files a/tests/new/options11/aspectlib2.jar and b/tests/new/options11/aspectlib2.jar differ
index 93ac53fa740af912f3667b2d594866957a54df50..e19ead4bf6799fce13c4d673b029a9df94ee7553 100644 (file)
Binary files a/tests/new/options11/injar.jar and b/tests/new/options11/injar.jar differ
index 2a63a6e5e88e18a6f0dc51155f746c4e4efd0627..ae29a0d4ccb2ec8f3c4c00b704ae0b1a783800f1 100644 (file)
@@ -40,12 +40,21 @@ public class AjcMemberMaker {
        public static final TypeX NO_ASPECT_BOUND_EXCEPTION =
                TypeX.forName("org.aspectj.lang.NoAspectBoundException");
 
-       public static ResolvedMember ajcClinitMethod(TypeX declaringType) {
+       public static ResolvedMember ajcPreClinitMethod(TypeX declaringType) {
                return new ResolvedMember(
                        Member.METHOD, 
                        declaringType,
                        PRIVATE_STATIC,
-                       NameMangler.AJC_CLINIT_NAME,
+                       NameMangler.AJC_PRE_CLINIT_NAME,
+                       "()V");
+       }
+
+       public static ResolvedMember ajcPostClinitMethod(TypeX declaringType) {
+               return new ResolvedMember(
+                       Member.METHOD, 
+                       declaringType,
+                       PRIVATE_STATIC,
+                       NameMangler.AJC_POST_CLINIT_NAME,
                        "()V");
        }
 
index f3a9e4c286ae6ec79406d3cbb5c55786eac6f700..e510cc3e76e4ab065bc86ec5b49ebe0d808364d3 100644 (file)
@@ -39,7 +39,9 @@ public class NameMangler {
 
        public static final String PEROBJECT_BIND_METHOD = PREFIX + "perObjectBind";
 
-       public static final String AJC_CLINIT_NAME = PREFIX + "clinit";
+       public static final String AJC_PRE_CLINIT_NAME = PREFIX + "preClinit";
+
+       public static final String AJC_POST_CLINIT_NAME = PREFIX + "postClinit";
 
 
 
index 75c515218b8864c86fa5410c4b5977a3306fc77f..405e28cb36e6db2d0027a5681f65ce9d7f390684 100644 (file)
@@ -36,7 +36,7 @@ public class BcelCflowStackFieldAdder extends BcelTypeMunger {
                gen.getConstantPoolGen()).getField();
        gen.addField(f);
 
-               LazyMethodGen clinit = gen.getAjcClinit(); //StaticInitializer();
+               LazyMethodGen clinit = gen.getAjcPreClinit(); //StaticInitializer();
                InstructionList setup = new InstructionList();
                InstructionFactory fact = gen.getFactory();
 
index bd8c76288c7dd7bbbb5f4e8855b923028e6ea22d..26d2d7f1d926bf133481fc7c90fdba9cc2807865 100644 (file)
@@ -309,13 +309,27 @@ public class BcelShadow extends Shadow {
             LazyMethodGen enclosingMethod) 
     {
         InstructionList body = enclosingMethod.getBody();
-        InstructionHandle ih = body.getStart();
-        if (ih.getInstruction() instanceof InvokeInstruction) {
-               InvokeInstruction ii = (InvokeInstruction)ih.getInstruction();
-               if (ii.getName(enclosingMethod.getEnclosingClass().getConstantPoolGen()).equals(NameMangler.AJC_CLINIT_NAME)) {
-                       ih = ih.getNext();
+        // move the start past ajc$preClinit
+        InstructionHandle clinitStart = body.getStart();
+        if (clinitStart.getInstruction() instanceof InvokeInstruction) {
+               InvokeInstruction ii = (InvokeInstruction)clinitStart.getInstruction();
+               if (ii.getName(enclosingMethod.getEnclosingClass().getConstantPoolGen()).equals(NameMangler.AJC_PRE_CLINIT_NAME)) {
+                       clinitStart = clinitStart.getNext();
                }
         }
+        
+        InstructionHandle clinitEnd = body.getEnd();
+        
+        //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)) {
+//                     clinitEnd = clinitEnd.getPrev();
+//             }
+//        }
+        
+        
+        
         BcelShadow s =
             new BcelShadow(
                 world,
@@ -326,8 +340,8 @@ public class BcelShadow extends Shadow {
         ShadowRange r = new ShadowRange(body);
         r.associateWithShadow(s);
         r.associateWithTargets(
-            Range.genStart(body, ih),
-            Range.genEnd(body));
+            Range.genStart(body, clinitStart),
+            Range.genEnd(body, clinitEnd));
         return s;
     }
     
index 0953d1884452d21e373572269e8f77380b91662c..da0a2db8fe823aabcae0dfe3fae5101970dca68d 100644 (file)
@@ -319,15 +319,15 @@ public final class LazyClassGen {
         return clinit;
     }
     
-    public LazyMethodGen getAjcClinit() {
+    public LazyMethodGen getAjcPreClinit() {
         for (Iterator i = methodGens.iterator(); i.hasNext();) {
             LazyMethodGen gen = (LazyMethodGen) i.next();
-                       if (gen.getName().equals(NameMangler.AJC_CLINIT_NAME)) return gen;
+                       if (gen.getName().equals(NameMangler.AJC_PRE_CLINIT_NAME)) return gen;
         }
         LazyMethodGen ajcClinit = new LazyMethodGen(
                Modifier.STATIC,
                Type.VOID,
-               NameMangler.AJC_CLINIT_NAME,
+               NameMangler.AJC_PRE_CLINIT_NAME,
                new Type[0],
                CollectionUtil.NO_STRINGS,
                this);
index 100b7d8f187183d4b8b1f885750ed57005491ae8..54b76f013f5bc1828c839fcb54e97f6f2f1105d2 100644 (file)
Binary files a/weaver/testdata/dummyAspect.jar and b/weaver/testdata/dummyAspect.jar differ
index 927615c58c0b63683fd1b12aa2294c461ae000dc..8c0843c286c0775cc32f230506e0e01b46b42b87 100644 (file)
Binary files a/weaver/testdata/megatrace.jar and b/weaver/testdata/megatrace.jar differ
index 8a62739958f60833c968af3908fdcbdf7990f1a9..dba8efbff861bd7ae49f6b1e677e26061971471a 100644 (file)
Binary files a/weaver/testdata/megatraceNoweave.jar and b/weaver/testdata/megatraceNoweave.jar differ
index 99744a6bc99d9432ef45e864439096a6775f5d1b..18bf1b7597bd5dcaa44302e5bfab23e216cb432d 100644 (file)
Binary files a/weaver/testdata/tracing.jar and b/weaver/testdata/tracing.jar differ