]> source.dussan.org Git - aspectj.git/commitdiff
adding accessor methods for calls to protected methods from inter-type
authorjhugunin <jhugunin>
Tue, 17 Dec 2002 23:17:35 +0000 (23:17 +0000)
committerjhugunin <jhugunin>
Tue, 17 Dec 2002 23:17:35 +0000 (23:17 +0000)
declarations just like we have from calls to super methods

org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/InterTypeDeclaration.java
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/SuperFixerVisitor.java
weaver/src/org/aspectj/weaver/NameMangler.java
weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java
weaver/src/org/aspectj/weaver/bcel/BcelWeaver.java

index 43ca45e20d54164c6eb7ac4f2159caac7c168ac6..a9a73337a808fb3e9d1aa9710a873598356bfe58 100644 (file)
@@ -70,13 +70,14 @@ public abstract class InterTypeDeclaration extends MethodDeclaration {
        public void fixSuperCallsInBody() {
                SuperFixerVisitor v = new SuperFixerVisitor(this, onTypeBinding);
                this.traverse(v, (ClassScope)null);
-               HashSet set = new HashSet();
-               for (Iterator i = v.superMethodsCalled.iterator(); i.hasNext(); ) {
-                       MethodBinding b = (MethodBinding)i.next();
-                       set.add(EclipseWorld.makeResolvedMember(b));
-               }
-               
-               munger.setSuperMethodsCalled(set);
+               munger.setSuperMethodsCalled(v.superMethodsCalled);
+//             HashSet set = new HashSet();
+//             for (Iterator i = v.superMethodsCalled.iterator(); i.hasNext(); ) {
+//                     MethodBinding b = (MethodBinding)i.next();
+//                     set.add(EclipseWorld.makeResolvedMember(b));
+//             }
+//             
+//             munger.setSuperMethodsCalled(set);
        }
 
        protected void resolveOnType(ClassScope classScope) {
index c1747778a514ee983990b2c22e49d77678772cca..ab564f9f4d6d3b55d2eeb914f5c5ee5eff18273d 100644 (file)
@@ -16,6 +16,7 @@ package org.aspectj.ajdt.internal.compiler.ast;
 import java.util.*;
 import java.util.Arrays;
 
+import org.aspectj.ajdt.internal.compiler.lookup.EclipseWorld;
 import org.aspectj.weaver.*;
 import org.aspectj.weaver.ShadowMunger;
 import org.eclipse.jdt.internal.compiler.AbstractSyntaxTreeVisitorAdapter;
@@ -44,15 +45,28 @@ public class SuperFixerVisitor extends AbstractSyntaxTreeVisitorAdapter {
                // an error has already occurred
                if (call.codegenBinding == null) return; 
                
-               if (!call.isSuperAccess() || call.binding.isStatic()) return;
-
-               call.receiver = new ThisReference();
-               
                MethodBinding superBinding = call.codegenBinding;
-               
-               char[] accessName = AstUtil.makeAjcMangledName(
-                       ResolvedTypeMunger.SUPER_DISPATCH_NAME.toCharArray(), targetClass, superBinding.selector
-               );
+               char[] accessName;
+               boolean isSuper;
+               if (call.isSuperAccess() && !call.binding.isStatic()) {
+                       call.receiver = new ThisReference();
+                       accessName =
+                               NameMangler.superDispatchMethod(EclipseWorld.fromBinding(targetClass), 
+                                                       new String(superBinding.selector)).toCharArray();
+               } else if (call.receiver.isThis() && call.binding.isProtected() && !call.binding.isStatic()) {
+                       //XXX this is a hack that violates some binary compatibility rules
+                       if (superBinding.declaringClass.equals(targetClass)) {
+                               accessName =
+                                       NameMangler.protectedDispatchMethod(EclipseWorld.fromBinding(targetClass), 
+                                                               new String(superBinding.selector)).toCharArray();
+                       } else {
+                               accessName =
+                               NameMangler.superDispatchMethod(EclipseWorld.fromBinding(targetClass), 
+                                                       new String(superBinding.selector)).toCharArray();
+                       }
+               } else {
+                       return;
+               }
                
                //??? do we want these to be unique
                MethodBinding superAccessBinding =
@@ -62,7 +76,7 @@ public class SuperFixerVisitor extends AbstractSyntaxTreeVisitorAdapter {
                
                call.codegenBinding = superAccessBinding;
                
-               superMethodsCalled.add(superBinding);
-
+               ResolvedMember targetMember = EclipseWorld.makeResolvedMember(superBinding);
+               superMethodsCalled.add(targetMember);
        }
 }
index 69a3271faefdf525f2cf5d5a4142194f56cfe40f..3d9bc8c11059ba6f5a733b57c0ea1a91da2d4cea 100644 (file)
@@ -231,14 +231,23 @@ public class NameMangler {
        // ----
 
        /**
-        * This static method goes on the declaring aspect of the inter-type method.
+        * This static method goes on the target class of the inter-type method.
         */
-       public static String superDispatcher(TypeX classType, String name) 
+       public static String superDispatchMethod(TypeX classType, String name) 
        {
                return makeName("superDispatch",
                                        classType.getNameAsIdentifier(), name);
        }
 
+       /**
+        * This static method goes on the target class of the inter-type method.
+        */
+       public static String protectedDispatchMethod(TypeX classType, String name) 
+       {
+               return makeName("protectedDispatch",
+                                       classType.getNameAsIdentifier(), name);
+       }
+
        // ----
 
        private static TypeX getOutermostType(TypeX type) {
index a14f0e0b3a48587a21fb9defcc04331a0670ef8f..89e085fba5f7bf3d59e21e78d11af71003638037 100644 (file)
@@ -300,8 +300,12 @@ public class BcelTypeMunger extends ConcreteTypeMunger {
                        for (Iterator iter = neededSuperCalls.iterator(); iter.hasNext(); ) {
                                ResolvedMember superMethod = (ResolvedMember) iter.next();
                                if (weaver.addDispatchTarget(superMethod)) {
-                                       String dispatchName = genSuperDispatchName(onType, superMethod);
-                                       LazyMethodGen dispatcher = makeDispatcher(gen, dispatchName, superMethod, weaver.getWorld());
+                                       //System.err.println("super type: " + superMethod.getDeclaringType() + ", " + gen.getType());
+                                       boolean isSuper = !superMethod.getDeclaringType().equals(gen.getType());
+                                       String dispatchName;
+                                       if (isSuper) dispatchName = NameMangler.superDispatchMethod(onType, superMethod.getName());
+                                       else dispatchName = NameMangler.protectedDispatchMethod(onType, superMethod.getName());
+                                       LazyMethodGen dispatcher = makeDispatcher(gen, dispatchName, superMethod, weaver.getWorld(), isSuper);
 
                                        weaver.addLazyMethodGen(dispatcher);
                                }
@@ -433,7 +437,8 @@ public class BcelTypeMunger extends ConcreteTypeMunger {
                LazyClassGen onGen,
                String dispatchName,
                ResolvedMember superMethod,
-               BcelWorld world) 
+               BcelWorld world,
+               boolean isSuper) 
        {
                Type[] paramTypes = BcelWorld.makeBcelTypes(superMethod.getParameterTypes());
                Type returnType = BcelWorld.makeBcelType(superMethod.getReturnType());
@@ -459,21 +464,15 @@ public class BcelTypeMunger extends ConcreteTypeMunger {
                        body.append(fact.createLoad(paramType, pos));
                        pos+=paramType.getSize();
                }
-               body.append(Utility.createSuperInvoke(fact, world, superMethod));
+               if (isSuper) {
+                       body.append(Utility.createSuperInvoke(fact, world, superMethod));
+               } else {
+                       body.append(Utility.createInvoke(fact, world, superMethod));
+               }
                body.append(fact.createReturn(returnType));
 
                return mg;
-       }
-
-
-       private static String genSuperDispatchName(
-               ResolvedTypeX onType,
-               ResolvedMember superMethod) 
-       {
-               return "ajc$" + ResolvedTypeMunger.SUPER_DISPATCH_NAME + "$" + onType.getNameAsIdentifier() + "$" + superMethod.getName();
-       }
-
-       
+       }       
        
        private boolean mungeNewField(BcelClassWeaver weaver, NewFieldTypeMunger munger) {
                ResolvedMember initMethod = munger.getInitMethod(aspectType);
index 63eb043d557051b424b2681f48c93e7b238846eb..c0e475cbdd0c4e33174965dbc97d04c8a96f8268 100644 (file)
@@ -283,7 +283,7 @@ public class BcelWeaver implements IWeaver {
 
                LazyClassGen clazz = null;
                
-               if (shadowMungers.size() > 0 || typeMungers.size() > 0) {
+               if (shadowMungers.size() > 0 || typeMungers.size() > 0 || classType.isAspect()) {
                        clazz = classType.getLazyClassGen();
                        try {
                                boolean isChanged = BcelClassWeaver.weave(world, clazz, shadowMungers, typeMungers);