Browse Source

adding accessor methods for calls to protected methods from inter-type

declarations just like we have from calls to super methods
tags/V_1_1_b2
jhugunin 21 years ago
parent
commit
a6d1918ba0

+ 8
- 7
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/InterTypeDeclaration.java View 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) {

+ 24
- 10
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/SuperFixerVisitor.java View 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);
}
}

+ 11
- 2
weaver/src/org/aspectj/weaver/NameMangler.java View 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) {

+ 14
- 15
weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java View 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);

+ 1
- 1
weaver/src/org/aspectj/weaver/bcel/BcelWeaver.java View 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);

Loading…
Cancel
Save