]> source.dussan.org Git - aspectj.git/commitdiff
generic decp: now polices you supply the right number of parameters and they have...
authoraclement <aclement>
Wed, 27 Jul 2005 13:43:29 +0000 (13:43 +0000)
committeraclement <aclement>
Wed, 27 Jul 2005 13:43:29 +0000 (13:43 +0000)
tests/src/org/aspectj/systemtest/ajc150/GenericsTests.java
tests/src/org/aspectj/systemtest/ajc150/ajc150.xml
weaver/src/org/aspectj/weaver/patterns/WildTypePattern.java

index 32a77320c08588c118aebde089d6175c552cd11b..589e0cf848f66b28af1ca5f971e29f438cfe38ef 100644 (file)
@@ -163,6 +163,10 @@ public class GenericsTests extends XMLBasedAjcTestCase {
        public void testGenericITDComplex() {
                runTest("more complex static member itd");
        }
+       
+//     public void testGenericITFSharingTypeVariable() {
+//             runTest("generic intertype field declaration, sharing type variable");
+//     }
 
 //     public void testItdOnGenericType() {
 //             runTest("ITDs on generic type");
@@ -229,17 +233,17 @@ public class GenericsTests extends XMLBasedAjcTestCase {
                verifyClassSignature("Basic6","<J:Ljava/lang/Object;>Ljava/lang/Object;LI<TJ;>;LK<Ljava/lang/Integer;>;");
        }
        
-//     public void testGenericDecpIncorrectNumberOfTypeParams() {
-//             runTest("generic decp - incorrect number of type parameters");
-//     }
+       public void testGenericDecpIncorrectNumberOfTypeParams() {
+               runTest("generic decp - incorrect number of type parameters");
+       }
        
        public void testGenericDecpSpecifyingBounds() {
                runTest("generic decp - specifying bounds");
        }
        
-//     public void testGenericDecpViolatingBounds() {
-//             runTest("generic decp - specifying bounds but breaking them");
-//     }
+       public void testGenericDecpViolatingBounds() {
+               runTest("generic decp - specifying bounds but breaking them");
+       }
        
        // need separate compilation test to verify signatures are ok
 //
index 6b3e4d27f46d820181248c1beada4d5f94297b55..5e0101ec1191aca0dc4b898711366941c6373003 100644 (file)
      </run>
    </ajc-test>
    
+   <ajc-test dir="java5/generics/itds" title="generic intertype field declaration, sharing type variable">
+     <compile files="FieldITDOnGeneric.aj" options="-1.5"/>
+     <run class="FieldITDOnGeneric">
+       <stderr>
+         <line text="foo"/>
+       </stderr>
+     </run>
+   </ajc-test>
+   
    <ajc-test dir="java5/generics/itds" title="Parsing generic ITDs - 1">
      <compile files="Parse1.java" options="-1.5"/>
    </ajc-test>
      <weave classesFiles="Base4.java" aspectsFiles="Asp4.aj" options="-1.5,-showWeaveInfo"/>
    </ajc-test>
    
-   <ajc-test dir="java5/generics/decp" title="generic decp - incorrect number of type parameters">
-     <compile files="Basic3.aj" options="-1.5"/>
-     <run class="Basic3"/>
-   </ajc-test>
-
    <ajc-test dir="java5/generics/decp" title="generic decp - incorrect number of type parameters">
      <compile files="Basic3.aj" options="-1.5">
-       <message kind="error" line="10" text="Wrong number of type arguments; Type I requires 1"/>
+       <message kind="error" line="10" text="Type pattern does not match because the wrong number of type parameters are specified: Type I requires 1 parameter(s)"/>
      </compile>
    </ajc-test>
    
    
    <ajc-test dir="java5/generics/decp" title="generic decp - specifying bounds but breaking them">
      <compile files="Basic5.aj" options="-1.5">
-       <message kind="error" line="7" text="Type String does not meet the specification for type parameter 1 in generic type I&lt;T extends Number&gt;"/>
+       <message kind="error" line="7" text="Type java.lang.String does not meet the specification for type parameter 1 (T extends java.lang.Number) in generic type I"/>
      </compile>
    </ajc-test>
      
index b1fbba5ed474b56fdea11d37506cb6616633c64a..4382bcff8353ceea5fb0fcfd10eabffa04ee8b97 100644 (file)
@@ -647,17 +647,17 @@ public class WildTypePattern extends TypePattern {
                if (type == ResolvedType.MISSING) {
                        return resolveBindingsForMissingType(resolvedTypeInTheWorld, originalName, scope, bindings, allowBinding, requireExactType);
                } else {
-                       return resolveBindingsForExactType(scope,type,fullyQualifiedName);
+                       return resolveBindingsForExactType(scope,type,fullyQualifiedName,requireExactType);
                }
        }
        
-       private TypePattern resolveBindingsForExactType(IScope scope, UnresolvedType aType, String fullyQualifiedName) {
+       private TypePattern resolveBindingsForExactType(IScope scope, UnresolvedType aType, String fullyQualifiedName,boolean requireExactType) {
                TypePattern ret = null;
                if (aType.isTypeVariableReference()) {
                        // we have to set the bounds on it based on the bounds of this pattern
                        ret = resolveBindingsForTypeVariable(scope, (UnresolvedTypeVariableReferenceType) aType);
                } else if (typeParameters.size()>0) {
-                       if (!verifyTypeParameters(aType.resolve(scope.getWorld()),scope)) return TypePattern.NO; // messages already isued
+                       if (!verifyTypeParameters(aType.resolve(scope.getWorld()),scope,requireExactType)) return TypePattern.NO; // messages already isued
                        // Only if the type is exact *and* the type parameters are exact should we create an 
                        // ExactTypePattern for this WildTypePattern                                    
                        if (typeParameters.areAllExact()) {
@@ -777,7 +777,7 @@ public class WildTypePattern extends TypePattern {
         *  If any of these checks fail, a warning message is issued and we return false.
         * @return
         */
-       private boolean verifyTypeParameters(ResolvedType baseType,IScope scope) {
+       private boolean verifyTypeParameters(ResolvedType baseType,IScope scope, boolean requireExactType) {
                ResolvedType genericType = baseType.getGenericType();
                if (genericType == null) {
                        // issue message "does not match because baseType.getName() is not generic"
@@ -803,9 +803,10 @@ public class WildTypePattern extends TypePattern {
                        (!foundEllipsis && minRequiredTypeParameters != tvs.length))
                {
                        // issue message "does not match because wrong no of type params"
-                       scope.message(MessageUtil.warn(
-                                       WeaverMessages.format(WeaverMessages.INCORRECT_NUMBER_OF_TYPE_ARGUMENTS,genericType.getName(),new Integer(tvs.length)),
-                                       getSourceLocation()));
+                       String msg = WeaverMessages.format(WeaverMessages.INCORRECT_NUMBER_OF_TYPE_ARGUMENTS,
+                                                                  genericType.getName(),new Integer(tvs.length));
+                       if (requireExactType)   scope.message(MessageUtil.error(msg,getSourceLocation()));
+                       else                                    scope.message(MessageUtil.warn(msg,getSourceLocation()));
                        return false;
                } 
                
@@ -818,14 +819,15 @@ public class WildTypePattern extends TypePattern {
                                        // issue message that type parameter does not meet specification
                                        String parameterName = ut.getName();
                                        if (ut.isTypeVariableReference()) parameterName = ((TypeVariableReference)ut).getTypeVariable().getDisplayName();
-                                       scope.message(MessageUtil.warn(
-                                                       WeaverMessages.format(
-                                                                               WeaverMessages.VIOLATES_TYPE_VARIABLE_BOUNDS,
-                                                                               parameterName,
-                                                                               new Integer(i+1),
-                                                                               tvs[i].getDisplayName(),
-                                                                               genericType.getName()),
-                                                       getSourceLocation()));                                  
+                                       String msg = 
+                                               WeaverMessages.format(
+                                                       WeaverMessages.VIOLATES_TYPE_VARIABLE_BOUNDS,
+                                                       parameterName,
+                                                       new Integer(i+1),
+                                                       tvs[i].getDisplayName(),
+                                                       genericType.getName());
+                                       if (requireExactType)  scope.message(MessageUtil.error(msg,getSourceLocation()));       
+                                       else                               scope.message(MessageUtil.warn(msg,getSourceLocation()));    
                                        return false;
                                }
                        }