瀏覽代碼

better type and visibility checking for pointcut references

tags/V_1_1_b5
jhugunin 21 年之前
父節點
當前提交
12955353e3

+ 5
- 0
weaver/src/org/aspectj/weaver/ResolvedMember.java 查看文件

@@ -161,5 +161,10 @@ public class ResolvedMember extends Member implements IHasPosition {
return Modifier.isAbstract(modifiers);
}

public boolean isVisible(ResolvedTypeX fromType) {
World world = fromType.getWorld();
return ResolvedTypeX.isVisible(getModifiers(), getDeclaringType().resolve(world),
fromType);
}
}

+ 3
- 3
weaver/src/org/aspectj/weaver/ResolvedTypeX.java 查看文件

@@ -885,7 +885,7 @@ public abstract class ResolvedTypeX extends TypeX {
} else {
if (this instanceof BcelObjectType) return false; //XXX ignores separate comp
getWorld().getMessageHandler().handleMessage(
MessageUtil.error("inter-type declaration from " + munger.getAspectType() +
MessageUtil.error("inter-type declaration from " + munger.getAspectType().getName() +
" conflicts with existing member: " + existingMember,
munger.getSourceLocation())
);
@@ -957,11 +957,11 @@ public abstract class ResolvedTypeX extends TypeX {
//System.err.println("conflict at " + m2.getSourceLocation());
getWorld().getMessageHandler().handleMessage(MessageUtil.error(
"intertype declaration from "
+ m1.getAspectType().getClassName()
+ m1.getAspectType().getName()
+ " conflicts with intertype declaration: "
+ m2.getSignature()
+ " from "
+ m2.getAspectType().getClassName(),
+ m2.getAspectType().getName(),
m2.getSourceLocation()));
}

+ 12
- 3
weaver/src/org/aspectj/weaver/patterns/ReferencePointcut.java 查看文件

@@ -142,6 +142,12 @@ public class ReferencePointcut extends Pointcut {
return;
}
// check visibility
if (!pointcutDef.isVisible(scope.getEnclosingType())) {
scope.message(IMessage.ERROR, this, "pointcut declaration " + pointcutDef + " is not accessible");
return;
}
if (Modifier.isAbstract(pointcutDef.getModifiers())) {
if (onType != null) {
scope.message(IMessage.ERROR, this,
@@ -174,7 +180,9 @@ public class ReferencePointcut extends Pointcut {
"bad parameter to pointcut reference");
return;
}
if (!p.matchesSubtypes(parameterTypes[i])) {
if (!p.matchesSubtypes(parameterTypes[i]) &&
!p.getExactType().equals(TypeX.OBJECT))
{
scope.message(IMessage.ERROR, p, "incompatible type, expected " +
parameterTypes[i].getName() + " found " + p);
return;
@@ -220,7 +228,6 @@ public class ReferencePointcut extends Pointcut {
);
return Pointcut.makeMatchesNothing(Pointcut.CONCRETE);
}
//??? error if we don't find
//System.err.println("start: " + searchStart);
ResolvedTypeX[] parameterTypes = searchStart.getWorld().resolve(pointcutDec.getParameterTypes());
@@ -231,7 +238,9 @@ public class ReferencePointcut extends Pointcut {
for (int i=0,len=arguments.size(); i < len; i++) {
TypePattern p = arguments.get(i);
//we are allowed to bind to pointcuts which use subtypes as this is type safe
if (!p.matchesSubtypes(parameterTypes[i])) {
if (!p.matchesSubtypes(parameterTypes[i]) &&
!p.getExactType().equals(TypeX.OBJECT))
{
throw new BCException("illegal change to pointcut declaration: " + this);
}

Loading…
取消
儲存