]> source.dussan.org Git - aspectj.git/commitdiff
test and fix for pr114343
authoraclement <aclement>
Tue, 1 Nov 2005 11:22:49 +0000 (11:22 +0000)
committeraclement <aclement>
Tue, 1 Nov 2005 11:22:49 +0000 (11:22 +0000)
tests/bugs150/pr114343/Test.java [new file with mode: 0644]
tests/bugs150/pr114343/Test1.java [new file with mode: 0644]
tests/bugs150/pr114343/Test2.java [new file with mode: 0644]
tests/bugs150/pr114343/TestAspect.aj [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/Advice.java
weaver/src/org/aspectj/weaver/Lint.java
weaver/src/org/aspectj/weaver/XlintDefault.properties

diff --git a/tests/bugs150/pr114343/Test.java b/tests/bugs150/pr114343/Test.java
new file mode 100644 (file)
index 0000000..1a8a201
--- /dev/null
@@ -0,0 +1 @@
+public class Test {}
diff --git a/tests/bugs150/pr114343/Test1.java b/tests/bugs150/pr114343/Test1.java
new file mode 100644 (file)
index 0000000..3bd2195
--- /dev/null
@@ -0,0 +1,10 @@
+import java.util.*;
+
+public class Test1 extends Test {
+  Set<Integer> intsSet;
+
+  public Set<Integer> foo() {
+    return intsSet;
+  }
+}
+
diff --git a/tests/bugs150/pr114343/Test2.java b/tests/bugs150/pr114343/Test2.java
new file mode 100644 (file)
index 0000000..983fc38
--- /dev/null
@@ -0,0 +1,11 @@
+import java.util.*;
+
+public class Test2 extends Test {
+  Set<Double> doubSet;
+
+
+  public Set<Double> foo() {
+    return doubSet;
+  }
+}
+
diff --git a/tests/bugs150/pr114343/TestAspect.aj b/tests/bugs150/pr114343/TestAspect.aj
new file mode 100644 (file)
index 0000000..b0dcf02
--- /dev/null
@@ -0,0 +1,21 @@
+import java.util.*;
+
+public privileged aspect TestAspect {
+
+  pointcut p(Test t):
+    target(t) &&
+    get(!public Set<Number+> *Set) &&
+    !within(TestAspect);
+
+  Set around(Test t):p(t) {
+    Set s = proceed(t);
+    return s;
+  }
+
+  public static void main(String []argv) {
+
+    Set<Integer> si = new Test1().foo();
+    Set<Double>  sd = new Test2().foo();
+  }
+
+}
index 87d96f523cad00e81fd7c30d4cc6dc8e39ba8eef..3ae36e93fdb8f8febb24dbf1d4d544f38ce8903a 100644 (file)
@@ -51,11 +51,11 @@ public class Ajc150Tests extends org.aspectj.testing.XMLBasedAjcTestCase {
   public void testITDCtor_pr112783()       { runTest("Problem with constructor ITDs");}
   */
   
-  public void testUnboundFormal_pr112027() { runTest("unexpected error unboundFormalInPC");}
-  public void testCCEGenerics_pr113445()       { runTest("Generics ClassCastException");}
+  public void testUnboundFormal_pr112027()    { runTest("unexpected error unboundFormalInPC");}
+  public void testCCEGenerics_pr113445()      { runTest("Generics ClassCastException");}
   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 testBadDecp_pr110788_1() { runTest("bad generic decp - 1");}
   public void testBadDecp_pr110788_2() { runTest("bad generic decp - 2");}
index a5679fb3046d9ba9b65ad297bd61aba414a6ac45..45096e49630e46efc53dd85a783b48676c53a66c 100644 (file)
       </compile>
     </ajc-test>
     
+    <ajc-test dir="bugs150/pr114343" title="field-get, generics and around advice">
+      <compile files="Test.java,Test1.java,Test2.java,TestAspect.aj" options="-1.5">
+          <message kind="warning" line="7" text="unchecked conversion when advice applied at shadow field-get(java.util.Set Test1.intsSet), expected java.util.Set&lt;java.lang.Integer&gt; but advice uses java.util.Set"/>
+          <message kind="warning" line="8" text="unchecked conversion when advice applied at shadow field-get(java.util.Set Test2.doubSet), expected java.util.Set&lt;java.lang.Double&gt; but advice uses java.util.Set"/>
+      </compile>
+      <run class="TestAspect"/>
+    </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 07d7bc022b9e0930cd18c0fdbb28de041e973b57..173d4c3f9fa681557252462a3525b9b15316a38d 100644 (file)
@@ -161,7 +161,18 @@ public abstract class Advice extends ShadowMunger {
                                } else {
                                        ResolvedType shadowReturnType = shadow.getReturnType().resolve(world);
                                        ResolvedType adviceReturnType = getSignature().getGenericReturnType().resolve(world);
-                                       if(!shadowReturnType.isAssignableFrom(adviceReturnType)) {
+                                       
+                                       if (shadowReturnType.isParameterizedType() && adviceReturnType.isRawType()) { // Set<Integer> and Set
+                                               ResolvedType shadowReturnGenericType = shadowReturnType.getGenericType(); // Set
+                                               ResolvedType adviceReturnGenericType = adviceReturnType.getGenericType(); // Set
+                                               if (shadowReturnGenericType.isAssignableFrom(adviceReturnGenericType) && 
+                                                               world.getLint().uncheckedAdviceConversion.isEnabled()) {
+                                                       world.getLint().uncheckedAdviceConversion.signal(
+                                                               new String[]{shadow.toString(),shadowReturnType.getName(),adviceReturnType.getName()},
+                                                               shadow.getSourceLocation(),
+                                                               new ISourceLocation[]{getSourceLocation()});
+                                               }
+                                       } else if(!shadowReturnType.isAssignableFrom(adviceReturnType)) {
                                                //System.err.println(this + ", " + sourceContext + ", " + start);
                                                        world.showMessage(IMessage.ERROR,
                                                                        WeaverMessages.format(WeaverMessages.INCOMPATIBLE_RETURN_TYPE,shadow),
index aea2432bd6f89f4eb752f446efa4069812697d66..5713af3f977e9cc463e73315869a80284e588f46 100644 (file)
@@ -90,6 +90,9 @@ public class Lint {
        public final Kind uncheckedArgument =
                new Kind("uncheckedArgument","unchecked match of {0} with {1} when argument is an instance of {2} at join point {3}");
        
+       public final Kind uncheckedAdviceConversion =
+               new Kind("uncheckedAdviceConversion","unchecked conversion when advice applied at shadow {0}, expected {1} but advice uses {2}");
+       
     public Lint(World world) {
                this.world = world;
        }
index 826ee911a8860b83a746a6611bc415e766c87791..3f14de78631527fecc16a20d75fb1bb960cbaeca 100644 (file)
@@ -11,6 +11,8 @@ unmatchedSuperTypeInCall = warning
 
 canNotImplementLazyTjp = warning
 
+uncheckedAdviceConversion = warning
+
 needsSerialVersionUIDField = ignore
 brokeSerialVersionCompatibility = ignore