]> source.dussan.org Git - aspectj.git/commitdiff
fix for Bugzilla Bug 72531
authoracolyer <acolyer>
Tue, 24 Aug 2004 21:10:56 +0000 (21:10 +0000)
committeracolyer <acolyer>
Tue, 24 Aug 2004 21:10:56 +0000 (21:10 +0000)
  declare warning warns at wrong points

tests/bugs/pr72531/de/rohith/HelloWorld.java [new file with mode: 0644]
tests/bugs/pr72531/de/rohith/HelloWorldAspect.java [new file with mode: 0644]
tests/bugs/pr72531/de/rohith/PrinterWorld.java [new file with mode: 0644]
tests/src/org/aspectj/systemtest/ajc121/Ajc121Tests.java
tests/src/org/aspectj/systemtest/ajc121/ajc121-tests.xml
weaver/src/org/aspectj/weaver/patterns/WildTypePattern.java
weaver/testsrc/org/aspectj/weaver/patterns/TypePatternTestCase.java

diff --git a/tests/bugs/pr72531/de/rohith/HelloWorld.java b/tests/bugs/pr72531/de/rohith/HelloWorld.java
new file mode 100644 (file)
index 0000000..f2687aa
--- /dev/null
@@ -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 (file)
index 0000000..cbe1dc7
--- /dev/null
@@ -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 (file)
index 0000000..cf42776
--- /dev/null
@@ -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;
+    }
+}
index bd1bb32bcf7675e1cf1d8c835b8585a6fc7d9741..bdd7521605bb045922c32987e82d5839c3afaa33 100644 (file)
@@ -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");
+  }
 }
 
index 98cb69fddf0b5af88fd1fbd22f967ea1fdd75d4c..edf21cf949227e9d5985106362b5048759640699 100644 (file)
                </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
index a5d1c42d2d4b502cd82110211f717d2bffb7101c..d87ade6b1abd06203583389856edcc70b69875bc 100644 (file)
@@ -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();
index 67615d9440d1c2bb24ce5e7a79eec413d7a9836e..ad6d7e45aa4257160585a2f6b320c791b68b8fa5 100644 (file)
@@ -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 {