From b5f4d09e4f4e45943c6c8b3dc8dca0c05b90f27c Mon Sep 17 00:00:00 2001 From: acolyer Date: Tue, 22 Mar 2005 13:14:44 +0000 Subject: [PATCH] Fix for Bugzilla Bug 88652: an array type as the last parameter in a signature does not match on the varargs declared method --- tests/java5/varargs/Pr88652.aj | 20 +++++++++++++++++++ .../systemtest/ajc150/Ajc150Tests.java | 4 ++++ .../org/aspectj/systemtest/ajc150/ajc150.xml | 7 +++++++ .../weaver/patterns/ExactTypePattern.java | 4 ++++ .../weaver/patterns/SignaturePattern.java | 9 +++++---- .../aspectj/weaver/patterns/TypePattern.java | 4 ++++ .../weaver/patterns/WildTypePattern.java | 4 ++++ 7 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 tests/java5/varargs/Pr88652.aj diff --git a/tests/java5/varargs/Pr88652.aj b/tests/java5/varargs/Pr88652.aj new file mode 100644 index 000000000..bd3141cca --- /dev/null +++ b/tests/java5/varargs/Pr88652.aj @@ -0,0 +1,20 @@ +public aspect Pr88652 { + + pointcut p(): call(Touple.new(..)); + + declare warning: p() : "should match"; + + public static void main(String[] args) { + Touple t = new Touple(new Object()); + Touple t2 = new Touple(new Object(),new Object()); + } +} + + +class Touple { + + public Touple(Object formulaHandle, Object... propositions) { + ; // empty + } + +} \ No newline at end of file diff --git a/tests/src/org/aspectj/systemtest/ajc150/Ajc150Tests.java b/tests/src/org/aspectj/systemtest/ajc150/Ajc150Tests.java index 3d75b53c7..bdcc31a41 100644 --- a/tests/src/org/aspectj/systemtest/ajc150/Ajc150Tests.java +++ b/tests/src/org/aspectj/systemtest/ajc150/Ajc150Tests.java @@ -141,6 +141,10 @@ public class Ajc150Tests extends org.aspectj.testing.XMLBasedAjcTestCase { runTest("invalid cons syntax"); } + public void testVarargsInConsBug() { + runTest("varargs in constructor sig"); + } + // helper methods..... public SyntheticRepository createRepos(File cpentry) { diff --git a/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml b/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml index 84e1de484..67370847d 100644 --- a/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml +++ b/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml @@ -126,6 +126,13 @@ + + + + + + + diff --git a/weaver/src/org/aspectj/weaver/patterns/ExactTypePattern.java b/weaver/src/org/aspectj/weaver/patterns/ExactTypePattern.java index b4e4ea7e3..6776579f3 100644 --- a/weaver/src/org/aspectj/weaver/patterns/ExactTypePattern.java +++ b/weaver/src/org/aspectj/weaver/patterns/ExactTypePattern.java @@ -70,6 +70,10 @@ public class ExactTypePattern extends TypePattern { this.type = type; } + public boolean isArray() { + return type.isArray(); + } + /* (non-Javadoc) * @see org.aspectj.weaver.patterns.TypePattern#couldEverMatchSameTypesAs(org.aspectj.weaver.patterns.TypePattern) */ diff --git a/weaver/src/org/aspectj/weaver/patterns/SignaturePattern.java b/weaver/src/org/aspectj/weaver/patterns/SignaturePattern.java index 126d45e95..633e15748 100644 --- a/weaver/src/org/aspectj/weaver/patterns/SignaturePattern.java +++ b/weaver/src/org/aspectj/weaver/patterns/SignaturePattern.java @@ -573,11 +573,12 @@ public class SignaturePattern extends PatternNode { * 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).isVarArgs) { - return true; + if (params.size()>0 && (modifiers & Constants.ACC_VARARGS)!=0) { + // we have at least one parameter in the pattern list, and the method has a varargs signature + TypePattern lastPattern = params.get(params.size()-1); + if (lastPattern.isArray() && !lastPattern.isVarArgs) return true; } - return false; + return false; } public AnnotationTypePattern getAnnotationPattern() { diff --git a/weaver/src/org/aspectj/weaver/patterns/TypePattern.java b/weaver/src/org/aspectj/weaver/patterns/TypePattern.java index 9763cf9e7..dd33ef30a 100644 --- a/weaver/src/org/aspectj/weaver/patterns/TypePattern.java +++ b/weaver/src/org/aspectj/weaver/patterns/TypePattern.java @@ -64,6 +64,10 @@ public abstract class TypePattern extends PatternNode { return annotationPattern == AnnotationTypePattern.ANY; } + public boolean isArray() { + return false; + } + protected TypePattern(boolean includeSubtypes) { this(includeSubtypes,false); } diff --git a/weaver/src/org/aspectj/weaver/patterns/WildTypePattern.java b/weaver/src/org/aspectj/weaver/patterns/WildTypePattern.java index 0dff4aaad..859391bdf 100644 --- a/weaver/src/org/aspectj/weaver/patterns/WildTypePattern.java +++ b/weaver/src/org/aspectj/weaver/patterns/WildTypePattern.java @@ -140,6 +140,10 @@ public class WildTypePattern extends TypePattern { return dim; } + public boolean isArray() { + return dim > 1; + } + /** * @param targetTypeName * @return -- 2.39.5