]> source.dussan.org Git - aspectj.git/commitdiff
*Now* we're moving - more and more stuff from GenericsTests is working :) see pr11210...
authoraclement <aclement>
Thu, 20 Oct 2005 14:47:22 +0000 (14:47 +0000)
committeraclement <aclement>
Thu, 20 Oct 2005 14:47:22 +0000 (14:47 +0000)
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/AjLookupEnvironment.java
tests/java5/generics/genericaspects/GenericAspectK.aj
tests/java5/generics/genericaspects/GenericAspectK2.aj [new file with mode: 0644]
tests/src/org/aspectj/systemtest/ajc150/GenericsTests.java
tests/src/org/aspectj/systemtest/ajc150/ajc150.xml
weaver/src/org/aspectj/weaver/ResolvedType.java

index c3756aec0e9bcc9f5001a84ede48c98c03909064..cb5d706e1bf5a6abb8cf85569e696dba61c2573e 100644 (file)
@@ -26,6 +26,7 @@ import java.util.Set;
 import org.aspectj.ajdt.internal.compiler.ast.AspectDeclaration;
 import org.aspectj.ajdt.internal.compiler.ast.PointcutDeclaration;
 import org.aspectj.bridge.IMessage;
+import org.aspectj.bridge.MessageUtil;
 import org.aspectj.bridge.WeaveMessage;
 import org.aspectj.bridge.context.CompilationAndWeavingContext;
 import org.aspectj.bridge.context.ContextToken;
@@ -57,6 +58,7 @@ import org.aspectj.weaver.AsmRelationshipProvider;
 import org.aspectj.weaver.ConcreteTypeMunger;
 import org.aspectj.weaver.ReferenceType;
 import org.aspectj.weaver.ResolvedType;
+import org.aspectj.weaver.TypeVariable;
 import org.aspectj.weaver.UnresolvedType;
 import org.aspectj.weaver.WeaverMessages;
 import org.aspectj.weaver.WeaverStateInfo;
@@ -213,6 +215,13 @@ public class AjLookupEnvironment extends LookupEnvironment implements AnonymousC
                        }
                }
                
+               for (int i = lastCompletedUnitIndex +1; i<=lastUnitIndex; i++) {
+                       SourceTypeBinding[] b = units[i].scope.topLevelTypes;
+            for (int j = 0; j < b.length; j++) {
+               verifyAnyTypeParametersMeetBounds(b[j]);
+            }
+               }
+               
         for (int i = lastCompletedUnitIndex + 1; i <= lastUnitIndex; i++) {
             SourceTypeBinding[] b = units[i].scope.topLevelTypes;
             for (int j = 0; j < b.length; j++) {
@@ -242,6 +251,42 @@ public class AjLookupEnvironment extends LookupEnvironment implements AnonymousC
        }
        
        
+       /**
+        * For any given sourcetypebinding, this method checks that if it is a parameterized aspect that
+        * the type parameters specified for any supertypes meet the bounds for the generic type
+        * variables.
+        */
+       private void verifyAnyTypeParametersMeetBounds(SourceTypeBinding sourceType) {
+               ResolvedType onType = factory.fromEclipse(sourceType);
+               if (onType.isAspect()) {
+                       ResolvedType superType = factory.fromEclipse(sourceType.superclass);
+                       // Don't need to check if it was used in its RAW form or isnt generic
+                       if (superType.isGenericType() || superType.isParameterizedType()) {
+                               TypeVariable[] typeVariables         = superType.getTypeVariables();
+                               UnresolvedType[] typeParams          = superType.getTypeParameters();
+                               if (typeVariables!=null && typeParams!=null) {
+                                       for (int i = 0; i < typeVariables.length; i++) {
+                                               boolean ok = typeVariables[i].canBeBoundTo(typeParams[i].resolve(factory.getWorld()));
+                                               if (!ok) { // the supplied parameter violates the bounds
+                                                       // Type {0} does not meet the specification for type parameter {1} ({2}) in generic type {3}
+                                                       String msg = 
+                                                               WeaverMessages.format(
+                                                                       WeaverMessages.VIOLATES_TYPE_VARIABLE_BOUNDS,
+                                                                       typeParams[i],
+                                                                       new Integer(i+1),
+                                                                       typeVariables[i].getDisplayName(),
+                                                                       superType.getGenericType().getName());
+                                                       factory.getWorld().getMessageHandler().handleMessage(MessageUtil.error(msg,onType.getSourceLocation()));
+                                               }
+                                       }
+                       }
+                       }
+               }
+               
+               
+               
+       }
+
        /**
         * Find all the ITDs and Declares, but it is important we do this from the supertypes
         * down to the subtypes.
@@ -443,8 +488,12 @@ public class AjLookupEnvironment extends LookupEnvironment implements AnonymousC
                        Collection declareParents, Collection declareAnnotationOnTypes, boolean skipInners) {
 
                ContextToken tok = CompilationAndWeavingContext.enteringPhase(CompilationAndWeavingContext.WEAVING_INTERTYPE_DECLARATIONS, sourceType.sourceName);
-               
+
+
                ResolvedType onType = factory.fromEclipse(sourceType);
+               
+
+               
                // AMC we shouldn't need this when generic sigs are fixed??
                if (onType.isRawType()) onType = onType.getGenericType();
 
@@ -550,24 +599,11 @@ public class AjLookupEnvironment extends LookupEnvironment implements AnonymousC
                                        needOldStyleWarning = false;
                                }
                                onType.addInterTypeMunger(munger);
-                                /*
-                               //TODO: Andy Should be done at weave time.
-                               // Unfortunately we can't do it at weave time unless the type mungers remember where
-                               // they came from.  Thats why we do it here during complation because at this time
-                               // they do know their source location.  I've put a flag in ResolvedTypeMunger that
-                               // records whether type mungers are currently set to remember their source location.
-                               // The flag is currently set to false, it should be set to true when we do the
-                               // work to version all AspectJ attributes.
-                               // (When done at weave time, it is done by invoking addRelationship() on 
-                               // AsmRelationshipProvider (see BCELTypeMunger)
-                               if (!ResolvedTypeMunger.persistSourceLocation) // Do it up front if we bloody have to
-                                AsmInterTypeRelationshipProvider.getDefault().addRelationship(onType, munger);
-                                */
                        }
                }
                
                
-        //???onType.checkInterTypeMungers();
+
         onType.checkInterTypeMungers();
                for (Iterator i = onType.getInterTypeMungers().iterator(); i.hasNext();) {
                        EclipseTypeMunger munger = (EclipseTypeMunger) i.next();
index 5c4b72f93c8b3658d5f3858df016093ce3932a88..2a15c0aeeb8fbe2ba37eaf54ace72913dbe93f1e 100644 (file)
@@ -4,13 +4,13 @@ abstract aspect GenericAspect<A,B> {
 
   interface SimpleI<L extends Number> {}
 
-  declare parents: A implements SimpleI<B>;
+  declare parents: A implements SimpleI<B>; // Error: 'B' specified in the GenericAspect declaration doesnt say 'B extends Number'
 
   public N SimpleI<N>.m4(N n) { System.err.println(n);return n;}
 
 }
 
-aspect GenericAspectI extends GenericAspect<Base,String> { // error, String doesnt meet bounds in SimpleI<> in the generic aspect
+aspect GenericAspectK extends GenericAspect<Base,String> {  // Error: String doesnt extend Number
   public static void main(String []argv) {
     Base b = new Base();
     String s = b.m4("hello");
diff --git a/tests/java5/generics/genericaspects/GenericAspectK2.aj b/tests/java5/generics/genericaspects/GenericAspectK2.aj
new file mode 100644 (file)
index 0000000..2c4ce99
--- /dev/null
@@ -0,0 +1,23 @@
+import java.util.*;
+
+abstract aspect GenericAspect<A,B extends Number> {
+
+  interface SimpleI<L extends Number> {}
+
+  declare parents: A implements SimpleI<B>;
+
+  public N SimpleI<N>.m4(N n) { System.err.println(n);return n;}
+
+}
+
+aspect GenericAspectK2 extends GenericAspect<Base,String> { // Error: String doesnt meet bounds for B in GenericAspect
+  public static void main(String []argv) {
+    Base b = new Base();
+    String s = b.m4("hello");
+    if (!s.equals("hello"))
+      throw new RuntimeException("Not hello?? "+s);
+  }
+}
+
+class Base {}
+
index 6348d63714e98a6b989f9489addadffe4428ad16..a3462950a40f6d437ed018e6cef48f831e499233 100644 (file)
@@ -347,14 +347,13 @@ public class GenericsTests extends XMLBasedAjcTestCase {
        public void testSophisticatedAspectsC() {runTest("uberaspects - C");}
        public void testSophisticatedAspectsD() {runTest("uberaspects - D");}
        public void testSophisticatedAspectsE() {runTest("uberaspects - E");}
-//     public void testSophisticatedAspectsF() {runTest("uberaspects - F");} field ITD collapses to Number from tvar..
+       public void testSophisticatedAspectsF() {runTest("uberaspects - F");}
        public void testSophisticatedAspectsG() {runTest("uberaspects - G");}
        public void testSophisticatedAspectsH() {runTest("uberaspects - H");}
        public void testSophisticatedAspectsI() {runTest("uberaspects - I");}
        public void testSophisticatedAspectsJ() {runTest("uberaspects - J");}
-       // next test commented out, error message is less than ideal - see 
-       // comment in test program as to what should be expected
-    //public void testSophisticatedAspectsK() {runTest("uberaspects - K");}
+    public void testSophisticatedAspectsK() {runTest("uberaspects - K");}
+    public void testSophisticatedAspectsK2(){runTest("uberaspects - K2");}
        public void testSophisticatedAspectsL() {runTest("uberaspects - L");}
     public void testSophisticatedAspectsM() {runTest("uberaspects - M");}
        public void testSophisticatedAspectsN() {runTest("uberaspects - N");}
index b4648155f577982b654ee4433357c607a9a7490d..d0aaa64ca71d370c8d01f70b1f40e38583812144 100644 (file)
    </ajc-test>
    <ajc-test dir="java5/generics/genericaspects/" title="uberaspects - K">
      <compile files="GenericAspectK.aj" options="-1.5">
+       <message kind="error" line="7" text="B does not meet the specification for type parameter 1 (L extends java.lang.Number) in generic type GenericAspect$SimpleI"/>
        <message kind="error" line="16" text="The method m4(String) is undefined for the type Base"/>
      </compile>
    </ajc-test>
+   <ajc-test dir="java5/generics/genericaspects/" title="uberaspects - K2">
+     <compile files="GenericAspectK2.aj" options="-1.5">
+       <message kind="error" line="13" text="Type java.lang.String does not meet the specification for type parameter 2 (B extends java.lang.Number) in generic type GenericAspect"/>
+     </compile>
+   </ajc-test>
    <ajc-test dir="java5/generics/genericaspects/" title="uberaspects - L">
      <compile files="GenericAspectL.aj" options="-1.5"/>
      <run class="GenericAspectL"/>
index 257cfb58ca7645f7a13586116401fa7b387885fa..e5bccfa479ae70feeabcef0c379dc442f6e22f3b 100644 (file)
@@ -1151,7 +1151,7 @@ public abstract class ResolvedType extends UnresolvedType implements AnnotatedEl
                        ConcreteTypeMunger munger = (ConcreteTypeMunger) iter.next();
             if (munger.getSignature() != null && munger.getSignature().isAbstract()) { // Rule 1
                 if (munger.getMunger().getKind() == ResolvedTypeMunger.MethodDelegate) {
-                    ;//ignore for @AJ ITD as munger.getSingature() is the interface method hence abstract
+                    ;//ignore for @AJ ITD as munger.getSignature() is the interface method hence abstract
                 } else {
                 world.getMessageHandler().handleMessage(
                     new Message("must implement abstract inter-type declaration: " + munger.getSignature(),