diff options
7 files changed, 113 insertions, 1 deletions
diff --git a/tests/bugs/pr72531/de/rohith/HelloWorld.java b/tests/bugs/pr72531/de/rohith/HelloWorld.java new file mode 100644 index 000000000..f2687aab9 --- /dev/null +++ b/tests/bugs/pr72531/de/rohith/HelloWorld.java @@ -0,0 +1,11 @@ +package de.rohith; +public class HelloWorld { + + public static void main(String[] args) { + PrinterWorld p = new PrinterWorld(); + p.print(); + Integer i = p.returnInt(); + Integer[] intArray = p.returnArrayWithCloning(); + Integer[] array2 = p.returnArrayWithoutCloning(); + } +} diff --git a/tests/bugs/pr72531/de/rohith/HelloWorldAspect.java b/tests/bugs/pr72531/de/rohith/HelloWorldAspect.java new file mode 100644 index 000000000..cbe1dc707 --- /dev/null +++ b/tests/bugs/pr72531/de/rohith/HelloWorldAspect.java @@ -0,0 +1,31 @@ +package de.rohith; +import java.lang.Object; + +public aspect HelloWorldAspect { + + private int callDepth = -1; + + public HelloWorldAspect() { + } + + pointcut hello(): !within(HelloWorldAspect); + + pointcut method(): execution(public (*[]) de..*(..)); + + pointcut cloning(): call(* java.lang.Object.clone()); + + declare warning: method() && hello(): "*[] returning method called" ; + + Object[] around(): cflow(method()) && cloning() && hello() { + print("", thisEnclosingJoinPointStaticPart); + Object[] ret = proceed(); + return (Object[])ret.clone(); + } + + private void print(String prefix, Object message) { + for (int i = 0, spaces = callDepth * 2; i < spaces; i++) { + System.out.print(" "); + } + System.out.println(prefix + message); + } +} diff --git a/tests/bugs/pr72531/de/rohith/PrinterWorld.java b/tests/bugs/pr72531/de/rohith/PrinterWorld.java new file mode 100644 index 000000000..cf4277643 --- /dev/null +++ b/tests/bugs/pr72531/de/rohith/PrinterWorld.java @@ -0,0 +1,25 @@ +package de.rohith; +public class PrinterWorld { + private Integer[] intArray = new Integer[2]; + public PrinterWorld() { + + } + public void print() { + System.out.println("Hello World!"); + } + + public Integer returnInt() { + return new Integer(3); + } + + public Integer[] returnArrayWithCloning() { + for (int i = 0; i < intArray.length; i++) { + intArray[i] = new Integer(i++); + } + return (Integer[])intArray.clone(); + } + + public Integer[] returnArrayWithoutCloning() { + return intArray; + } +} diff --git a/tests/src/org/aspectj/systemtest/ajc121/Ajc121Tests.java b/tests/src/org/aspectj/systemtest/ajc121/Ajc121Tests.java index bd1bb32bc..bdd752160 100644 --- a/tests/src/org/aspectj/systemtest/ajc121/Ajc121Tests.java +++ b/tests/src/org/aspectj/systemtest/ajc121/Ajc121Tests.java @@ -264,5 +264,8 @@ public class Ajc121Tests extends org.aspectj.testing.XMLBasedAjcTestCase { runTest("The introduction on interface causes the interface implementation class error (4)"); } + public void test050_typePatternMatchingWithArrays() { + runTest("declare warning warns at wrong points"); + } } diff --git a/tests/src/org/aspectj/systemtest/ajc121/ajc121-tests.xml b/tests/src/org/aspectj/systemtest/ajc121/ajc121-tests.xml index 98cb69fdd..edf21cf94 100644 --- a/tests/src/org/aspectj/systemtest/ajc121/ajc121-tests.xml +++ b/tests/src/org/aspectj/systemtest/ajc121/ajc121-tests.xml @@ -404,3 +404,12 @@ </compile> </ajc-test> + + <ajc-test dir="bugs/pr72531" pr="72531" + title="declare warning warns at wrong points"> + <compile files="de/rohith/HelloWorld.java,de/rohith/HelloWorldAspect.java,de/rohith/PrinterWorld.java"> + <message kind="warning" line="15" text="*[] returning method called"/> + <message kind="warning" line="22" text="*[] returning method called"/> + </compile> + </ajc-test> +
\ No newline at end of file diff --git a/weaver/src/org/aspectj/weaver/patterns/WildTypePattern.java b/weaver/src/org/aspectj/weaver/patterns/WildTypePattern.java index a5d1c42d2..d87ade6b1 100644 --- a/weaver/src/org/aspectj/weaver/patterns/WildTypePattern.java +++ b/weaver/src/org/aspectj/weaver/patterns/WildTypePattern.java @@ -96,6 +96,23 @@ public class WildTypePattern extends TypePattern { return innerMatchesExactly(targetTypeName); } + if (isStar()) { + // we match if the dimensions match + int numDimensionsInTargetType = 0; + if (dim > 0) { + int index; + while((index = targetTypeName.indexOf('[')) != -1) { + numDimensionsInTargetType++; + targetTypeName = targetTypeName.substring(index+1); + } + if (numDimensionsInTargetType == dim) { + return true; + } else { + return false; + } + } + } + // if our pattern is length 1, then known matches are exact matches // if it's longer than that, then known matches are prefixes of a sort if (namePatterns.length == 1) { @@ -308,7 +325,9 @@ public class WildTypePattern extends TypePattern { boolean allowBinding, boolean requireExactType) { if (isStar()) { - return TypePattern.ANY; //??? loses source location + if (dim == 0) { // pr72531 + return TypePattern.ANY; //??? loses source location + } } String simpleName = maybeGetSimpleName(); diff --git a/weaver/testsrc/org/aspectj/weaver/patterns/TypePatternTestCase.java b/weaver/testsrc/org/aspectj/weaver/patterns/TypePatternTestCase.java index 67615d944..ad6d7e45a 100644 --- a/weaver/testsrc/org/aspectj/weaver/patterns/TypePatternTestCase.java +++ b/weaver/testsrc/org/aspectj/weaver/patterns/TypePatternTestCase.java @@ -201,6 +201,20 @@ public class TypePatternTestCase extends TestCase { } + + public void testArrayMatch() { + world = new BcelWorld(); + checkMatch("*[][]","java.lang.Object",false); + checkMatch("*[]","java.lang.Object[]",true); + checkMatch("*[][]","java.lang.Object[][]",true); + checkMatch("java.lang.Object[]","java.lang.Object",false); + checkMatch("java.lang.Object[]","java.lang.Object[]",true); + checkMatch("java.lang.Object[][]","java.lang.Object[][]",true); + checkMatch("java.lang.String[]","java.lang.Object",false); + checkMatch("java.lang.String[]","java.lang.Object[]",false); + checkMatch("java.lang.String[][]","java.lang.Object[][]",false); + checkMatch("java.lang.Object+[]","java.lang.String[]",true); + } private void checkIllegalInstanceofMatch(String pattern, String name) { try { |