summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjhugunin <jhugunin>2002-12-17 23:17:35 +0000
committerjhugunin <jhugunin>2002-12-17 23:17:35 +0000
commita6d1918ba0e713546a214901de6eda9376604877 (patch)
tree18ddd98ce46820a291f64b353bcc7ec967211855
parent4f58fd779099e3a59c6c1e177f94b86b6c7b5f47 (diff)
downloadaspectj-a6d1918ba0e713546a214901de6eda9376604877.tar.gz
aspectj-a6d1918ba0e713546a214901de6eda9376604877.zip
adding accessor methods for calls to protected methods from inter-type
declarations just like we have from calls to super methods
-rw-r--r--org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/InterTypeDeclaration.java15
-rw-r--r--org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/SuperFixerVisitor.java34
-rw-r--r--weaver/src/org/aspectj/weaver/NameMangler.java13
-rw-r--r--weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java29
-rw-r--r--weaver/src/org/aspectj/weaver/bcel/BcelWeaver.java2
5 files changed, 58 insertions, 35 deletions
diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/InterTypeDeclaration.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/InterTypeDeclaration.java
index 43ca45e20..a9a73337a 100644
--- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/InterTypeDeclaration.java
+++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/InterTypeDeclaration.java
@@ -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) {
diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/SuperFixerVisitor.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/SuperFixerVisitor.java
index c1747778a..ab564f9f4 100644
--- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/SuperFixerVisitor.java
+++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/SuperFixerVisitor.java
@@ -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);
}
}
diff --git a/weaver/src/org/aspectj/weaver/NameMangler.java b/weaver/src/org/aspectj/weaver/NameMangler.java
index 69a3271fa..3d9bc8c11 100644
--- a/weaver/src/org/aspectj/weaver/NameMangler.java
+++ b/weaver/src/org/aspectj/weaver/NameMangler.java
@@ -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) {
diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java b/weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java
index a14f0e0b3..89e085fba 100644
--- a/weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java
+++ b/weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java
@@ -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);
diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelWeaver.java b/weaver/src/org/aspectj/weaver/bcel/BcelWeaver.java
index 63eb043d5..c0e475cbd 100644
--- a/weaver/src/org/aspectj/weaver/bcel/BcelWeaver.java
+++ b/weaver/src/org/aspectj/weaver/bcel/BcelWeaver.java
@@ -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);