]> source.dussan.org Git - aspectj.git/commitdiff
fix for latest variant of 114343 (see comment #5): around advice on method returning...
authoraclement <aclement>
Thu, 3 Nov 2005 10:31:03 +0000 (10:31 +0000)
committeraclement <aclement>
Thu, 3 Nov 2005 10:31:03 +0000 (10:31 +0000)
tests/bugs150/pr114343/case2/TTT.java [new file with mode: 0644]
tests/bugs150/pr114343/case2/Test.java [new file with mode: 0644]
tests/bugs150/pr114343/case2/TestAspect.java [new file with mode: 0644]
tests/src/org/aspectj/systemtest/ajc150/Ajc150Tests.java
tests/src/org/aspectj/systemtest/ajc150/ajc150.xml
weaver/src/org/aspectj/weaver/ReferenceType.java
weaver/src/org/aspectj/weaver/ResolvedType.java
weaver/src/org/aspectj/weaver/TypeFactory.java
weaver/src/org/aspectj/weaver/World.java

diff --git a/tests/bugs150/pr114343/case2/TTT.java b/tests/bugs150/pr114343/case2/TTT.java
new file mode 100644 (file)
index 0000000..732e0d3
--- /dev/null
@@ -0,0 +1,11 @@
+import java.util.*;
+
+public class TTT {
+  public void foo() {
+    System.err.println("Creating Test<Integer> instance");
+    Test<Integer> mt = new Test<Integer>();
+    System.err.println("Calling toArray");
+    Integer[] arr = mt.toArray(new Integer[]{});
+    System.err.println("done");
+  }
+}
diff --git a/tests/bugs150/pr114343/case2/Test.java b/tests/bugs150/pr114343/case2/Test.java
new file mode 100644 (file)
index 0000000..7580949
--- /dev/null
@@ -0,0 +1,11 @@
+import java.util.*;
+
+public class Test<T> {
+
+       Set<T> set = new HashSet<T>();
+
+       public <T> T[] toArray(T[] a) {
+    System.err.println("In toArray()");
+               return set.toArray(a);
+       }
+}
diff --git a/tests/bugs150/pr114343/case2/TestAspect.java b/tests/bugs150/pr114343/case2/TestAspect.java
new file mode 100644 (file)
index 0000000..fcc760a
--- /dev/null
@@ -0,0 +1,25 @@
+import java.util.*;
+
+public privileged aspect TestAspect {
+
+      pointcut TestToArray(Test mt) :
+                target(mt) &&
+                !within(TestAspect);
+
+
+    Object[] around(Test mt, Object[] objs) :
+            TestToArray(mt) &&
+            args(objs) &&
+            execution(Object[] Test.toArray(Object[])) {
+
+    System.err.println("In around advice");
+        objs = proceed(mt, objs);
+        return objs;
+    }
+
+  public static void main(String[] argv) {
+     System.err.println("TestAspect.main: Calling foo");
+     new TTT().foo();   
+     System.err.println("TestAspect.main: done");
+  }
+}
index 54677b88cca9f03b1c979a209f4e16d966bce6c3..c3a77ad2ed67a9798852a27b1899a387b021a543 100644 (file)
@@ -56,6 +56,7 @@ public class Ajc150Tests extends org.aspectj.testing.XMLBasedAjcTestCase {
   public void testMatthewsAspect_pr113947_1() { runTest("maws generic aspect - 1");}
   public void testMatthewsAspect_pr113947_2() { runTest("maws generic aspect - 2");}
   public void testFieldGet_pr114343()         { runTest("field-get, generics and around advice");}
+  public void testFieldGet_pr114343_2()       { runTest("field-get, generics and around advice - 2");}
   public void testCaptureBinding_pr114744()   { runTest("capturebinding wildcard problem");}
   
   public void testBadDecp_pr110788_1() { runTest("bad generic decp - 1");}
index 852ccb9812c75078327ebdcb0ab6b5cb54ccc6bd..8d10e7563b2c060b540b5f345f19a82c1a07566c 100644 (file)
       <run class="TestAspect"/>
     </ajc-test>
     
+    <ajc-test dir="bugs150/pr114343/case2" title="field-get, generics and around advice - 2">
+      <compile files="Test.java,TTT.java,TestAspect.java" options="-1.5"/>
+      <run class="TestAspect">
+        <stderr>
+          <line text="TestAspect.main: Calling foo"/>
+          <line text="Creating Test&lt;Integer&gt; instance"/>
+          <line text="Calling toArray"/>
+          <line text="In around advice"/>
+          <line text="In toArray()"/>
+          <line text="done"/>
+          <line text="TestAspect.main: done"/>
+        </stderr>
+      </run>
+    </ajc-test>
+    
     <ajc-test dir="bugs150/pr113947/case1" title="maws generic aspect - 1">
         <compile files="AbstractListSupport.java,AnotherItem.java,Item.java,LinkedList.java,LinkedListItem.java,ListItem.java,StringList.java" options="-1.5">
           <!-- the 'static ref' messages are a bit poor and ought to be eliminated... -->
index 111762cf2a696a151d1f0788d5f64f8fe6df2b6a..f31cf2e9615f99e450de9b7d4e3d9e742a09d448 100644 (file)
@@ -288,6 +288,11 @@ public class ReferenceType extends ResolvedType {
                        }
                }
 
+               if (isTypeVariableReference() && !other.isTypeVariableReference()) { // eg. this=T  other=Ljava/lang/Object;
+                   TypeVariable aVar = ((TypeVariableReference)this).getTypeVariable();
+                   return aVar.getFirstBound().resolve(world).isAssignableFrom(other);
+               } 
+               
                if (other.isTypeVariableReference()) {
                        TypeVariableReferenceType otherType = (TypeVariableReferenceType) other;
                        if (this instanceof TypeVariableReference) {
index b6683f724ac753c50314bf88ad003bc1c619ea21..464c1675cf18b5c6754d4874172d2b7746364887 100644 (file)
@@ -744,14 +744,17 @@ public abstract class ResolvedType extends UnresolvedType implements AnnotatedEl
     // ---- types
     public static ResolvedType makeArray(ResolvedType type, int dim) {
        if (dim == 0) return type;
-       ResolvedType array = new Array("[" + type.getSignature(),type.getWorld(),type);
+       ResolvedType array = new Array("[" + type.getSignature(),"["+type.getErasureSignature(),type.getWorld(),type);
        return makeArray(array,dim-1);
     }
     
     static class Array extends ResolvedType {
         ResolvedType componentType;
-        Array(String s, World world, ResolvedType componentType) {
-            super(s, world);
+       
+        
+        // Sometimes the erasure is different, eg.  [TT;  and [Ljava/lang/Object; 
+        Array(String sig, String erasureSig,World world, ResolvedType componentType) {
+            super(sig,erasureSig, world);
             this.componentType = componentType;
         }
         public final ResolvedMember[] getDeclaredFields() {
index b921d0aad50597486430434957dd1515b42c6491..eb6350b3393fda625b5ee031fe42bb1ac419047e 100644 (file)
@@ -110,6 +110,12 @@ public class TypeFactory {
                                typeVariableName = typeVariableName.substring(0, typeVariableName.length() -1);
                        }
                        return new UnresolvedTypeVariableReferenceType(new TypeVariable(typeVariableName));
+               } else if (signature.startsWith("[")) {
+                       int dims = 0;
+                       while (signature.charAt(dims)=='[') dims++;
+                       UnresolvedType componentType = createTypeFromSignature(signature.substring(dims));
+                       return new UnresolvedType(signature,
+                                       signature.substring(0,dims)+componentType.getErasureSignature());
                }
                return new UnresolvedType(signature);
        }
index 423898524de8674476110d4359a6966e3d4e6d84..29810f984a16761db05cf1a4f9258622b030cc9f 100644 (file)
@@ -204,10 +204,11 @@ public abstract class World implements Dump.INode {
         
         // no existing resolved type, create one
         if (ty.isArray()) {
-            ret = new ResolvedType.Array(signature, 
+               ResolvedType componentType = resolve(ty.getComponentType(),allowMissing);
+               String brackets = signature.substring(0,signature.lastIndexOf("[")+1);
+            ret = new ResolvedType.Array(signature, brackets+componentType.getErasureSignature(),
                                             this, 
-                                            resolve(ty.getComponentType(), 
-                                            allowMissing));
+                                            componentType);
         } else {
             ret = resolveToReferenceType(ty);
             if (!allowMissing && ret == ResolvedType.MISSING) {
@@ -264,7 +265,8 @@ public abstract class World implements Dump.INode {
        return resolve(UnresolvedType.forName(name),allowMissing);
     }
     
-       
+       private ResolvedType currentlyResolvingBaseType;
+
        /**
         * Resolve to a ReferenceType - simple, raw, parameterized, or generic.
      * Raw, parameterized, and generic versions of a type share a delegate.
@@ -273,8 +275,10 @@ public abstract class World implements Dump.INode {
                if (ty.isParameterizedType()) {
                        // ======= parameterized types ================
                        ReferenceType genericType = (ReferenceType)resolveGenericTypeFor(ty,false);
+                       currentlyResolvingBaseType = genericType;
                        ReferenceType parameterizedType = 
                                TypeFactory.createParameterizedType(genericType, ty.typeParameters, this);
+                       currentlyResolvingBaseType = null;
                        return parameterizedType;
                        
                } else if (ty.isGenericType()) {