diff options
author | aclement <aclement> | 2004-12-03 16:11:16 +0000 |
---|---|---|
committer | aclement <aclement> | 2004-12-03 16:11:16 +0000 |
commit | 343fd37dfa5fb623c3ed8c5b561d88221dee2ca5 (patch) | |
tree | 1e497708fcc6293d69838b4fba9d26883af2b0a0 /weaver | |
parent | dae0fd4898e22dc648317f77b988d5d308fcaf42 (diff) | |
download | aspectj-343fd37dfa5fb623c3ed8c5b561d88221dee2ca5.tar.gz aspectj-343fd37dfa5fb623c3ed8c5b561d88221dee2ca5.zip |
72766 - varargs policing in signature matching
Diffstat (limited to 'weaver')
-rw-r--r-- | weaver/src/org/aspectj/weaver/Lint.java | 3 | ||||
-rw-r--r-- | weaver/src/org/aspectj/weaver/XlintDefault.properties | 4 | ||||
-rw-r--r-- | weaver/src/org/aspectj/weaver/patterns/SignaturePattern.java | 36 |
3 files changed, 42 insertions, 1 deletions
diff --git a/weaver/src/org/aspectj/weaver/Lint.java b/weaver/src/org/aspectj/weaver/Lint.java index fa5ef51d7..466cf9b5b 100644 --- a/weaver/src/org/aspectj/weaver/Lint.java +++ b/weaver/src/org/aspectj/weaver/Lint.java @@ -65,6 +65,9 @@ public class Lint { public final Kind noJoinpointsForBridgeMethods = new Kind("noJoinpointsForBridgeMethods","pointcut did not match on the method call to a bridge method. Bridge methods are generated by the compiler and have no join points"); + public final Kind cantMatchArrayTypeOnVarargs = + new Kind("cantMatchArrayTypeOnVarargs","an array type as the last parameter in a signature does not match on the varargs declared method: {0}"); + public Lint(World world) { this.world = world; } diff --git a/weaver/src/org/aspectj/weaver/XlintDefault.properties b/weaver/src/org/aspectj/weaver/XlintDefault.properties index 3c54f58b0..a75e8b9fc 100644 --- a/weaver/src/org/aspectj/weaver/XlintDefault.properties +++ b/weaver/src/org/aspectj/weaver/XlintDefault.properties @@ -16,4 +16,6 @@ brokeSerialVersionCompatibility = ignore noInterfaceCtorJoinpoint = warning -noJoinpointsForBridgeMethods = warning
\ No newline at end of file +noJoinpointsForBridgeMethods = warning + +cantMatchArrayTypeOnVarargs = ignore
\ No newline at end of file diff --git a/weaver/src/org/aspectj/weaver/patterns/SignaturePattern.java b/weaver/src/org/aspectj/weaver/patterns/SignaturePattern.java index 905d2a627..d086c8573 100644 --- a/weaver/src/org/aspectj/weaver/patterns/SignaturePattern.java +++ b/weaver/src/org/aspectj/weaver/patterns/SignaturePattern.java @@ -30,6 +30,7 @@ import org.aspectj.lang.reflect.AdviceSignature; import org.aspectj.lang.reflect.ConstructorSignature; import org.aspectj.lang.reflect.FieldSignature; import org.aspectj.lang.reflect.MethodSignature; +import org.aspectj.weaver.Constants; import org.aspectj.weaver.ISourceContext; import org.aspectj.weaver.Member; import org.aspectj.weaver.NameMangler; @@ -164,6 +165,13 @@ public class SignaturePattern extends PatternNode { return false; } + // If we have matched on parameters, let's just check it isn't because the last parameter in the pattern + // is an array type and the method is declared with varargs + if (isNotMatchBecauseOfVarargsIssue(parameterTypes,sig.getModifiers())) { + world.getLint().cantMatchArrayTypeOnVarargs.signal(sig.toString(),getSourceLocation()); + return false; + } + // Check the throws pattern if (!throwsPattern.matches(sig.getExceptions(), world)) return false; @@ -172,6 +180,14 @@ public class SignaturePattern extends PatternNode { if (!parameterTypes.matches(world.resolve(sig.getParameterTypes()), TypePattern.STATIC).alwaysTrue()) { return false; } + + // If we have matched on parameters, let's just check it isn't because the last parameter in the pattern + // is an array type and the method is declared with varargs + if (isNotMatchBecauseOfVarargsIssue(parameterTypes,sig.getModifiers())) { + world.getLint().cantMatchArrayTypeOnVarargs.signal(sig.toString(),getSourceLocation()); + return false; + } + if (!throwsPattern.matches(sig.getExceptions(), world)) return false; return declaringType.matchesStatically(member.getDeclaringType().resolve(world)); //return declaringTypeMatch(member.getDeclaringType(), member, world); @@ -250,6 +266,8 @@ public class SignaturePattern extends PatternNode { if (!parameterTypes.matches(params, TypePattern.STATIC).alwaysTrue()) { return false; } + if (isNotMatchBecauseOfVarargsIssue(parameterTypes,msig.getModifiers())) { return false; } + if (!throwsPattern.matches(exceptionTypes)) return false; return declaringTypeMatch(sig); // XXXAJ5 - Need to make this a covariant aware version for dynamic JP matching to work } else if (kind == Member.CONSTRUCTOR) { @@ -259,6 +277,8 @@ public class SignaturePattern extends PatternNode { if (!parameterTypes.matches(params, TypePattern.STATIC).alwaysTrue()) { return false; } + if (isNotMatchBecauseOfVarargsIssue(parameterTypes,csig.getModifiers())) { return false; } + if (!throwsPattern.matches(exceptionTypes)) return false; return declaringType.matchesStatically(sig.getDeclaringType()); //return declaringTypeMatch(member.getDeclaringType(), member, world); @@ -267,6 +287,7 @@ public class SignaturePattern extends PatternNode { return false; } + public boolean matches(Class declaringClass, java.lang.reflect.Member member) { if (kind == Member.ADVICE) return true; if (kind == Member.POINTCUT) return false; @@ -293,6 +314,7 @@ public class SignaturePattern extends PatternNode { if (!parameterTypes.matches(params, TypePattern.STATIC).alwaysTrue()) { return false; } + if (isNotMatchBecauseOfVarargsIssue(parameterTypes,member.getModifiers())) { return false; } if (!throwsPattern.matches(exceptionTypes)) return false; return declaringTypeMatch(member.getDeclaringClass()); // XXXAJ5 - Need to make this a covariant aware version for dynamic JP matching to work } @@ -304,6 +326,7 @@ public class SignaturePattern extends PatternNode { if (!parameterTypes.matches(params, TypePattern.STATIC).alwaysTrue()) { return false; } + if (isNotMatchBecauseOfVarargsIssue(parameterTypes,member.getModifiers())) { return false; } if (!throwsPattern.matches(exceptionTypes)) return false; return declaringType.matchesStatically(declaringClass); } @@ -495,5 +518,18 @@ public class SignaturePattern extends PatternNode { public ThrowsPattern getThrowsPattern() { return throwsPattern; } + + /** + * return true if last argument in params is an Object[] but the modifiers say this method + * was declared with varargs (Object...). We shouldn't be matching if this is the case. + */ + private boolean isNotMatchBecauseOfVarargsIssue(TypePatternList params,int modifiers) { + if (params.size()>0 && (modifiers & Constants.ACC_VARARGS)!=0 && // XXX Promote this to an isVarargs() on MethodSignature? + params.get(params.size()-1).getExactType().isArray()) { + return true; + } + return false; + } + } |