]> source.dussan.org Git - aspectj.git/commitdiff
better error handling for cases where type name is required
authorjhugunin <jhugunin>
Tue, 17 Dec 2002 22:18:57 +0000 (22:18 +0000)
committerjhugunin <jhugunin>
Tue, 17 Dec 2002 22:18:57 +0000 (22:18 +0000)
instead of type pattern

23 files changed:
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/AjLookupEnvironment.java
weaver/src/org/aspectj/weaver/Shadow.java
weaver/src/org/aspectj/weaver/bcel/BcelShadow.java
weaver/src/org/aspectj/weaver/patterns/AndTypePattern.java
weaver/src/org/aspectj/weaver/patterns/ArgsPointcut.java
weaver/src/org/aspectj/weaver/patterns/DeclareDominates.java
weaver/src/org/aspectj/weaver/patterns/DeclareParents.java
weaver/src/org/aspectj/weaver/patterns/DeclareSoft.java
weaver/src/org/aspectj/weaver/patterns/ExactTypePattern.java
weaver/src/org/aspectj/weaver/patterns/HandlerPointcut.java
weaver/src/org/aspectj/weaver/patterns/NotTypePattern.java
weaver/src/org/aspectj/weaver/patterns/OrTypePattern.java
weaver/src/org/aspectj/weaver/patterns/ReferencePointcut.java
weaver/src/org/aspectj/weaver/patterns/SignaturePattern.java
weaver/src/org/aspectj/weaver/patterns/ThisOrTargetPointcut.java
weaver/src/org/aspectj/weaver/patterns/ThrowsPattern.java
weaver/src/org/aspectj/weaver/patterns/TypePattern.java
weaver/src/org/aspectj/weaver/patterns/TypePatternList.java
weaver/src/org/aspectj/weaver/patterns/WildTypePattern.java
weaver/src/org/aspectj/weaver/patterns/WithinPointcut.java
weaver/testsrc/org/aspectj/weaver/patterns/BindingTestCase.java
weaver/testsrc/org/aspectj/weaver/patterns/TypePatternListTestCase.java
weaver/testsrc/org/aspectj/weaver/patterns/TypePatternTestCase.java

index e09f859fc56104d13d2f7edada7ee0b50ea7c5c6..cbd1e13678ffcab73648153b703718f86cc022f0 100644 (file)
@@ -140,7 +140,8 @@ public class AjLookupEnvironment extends LookupEnvironment {
 
        private void addParent(DeclareParents declareParents, ClassScope scope, TypePattern typePattern) {
                SourceTypeBinding sourceType = scope.referenceContext.binding;
-               if (!typePattern.assertExactType(world.getMessageHandler())) return;
+               //if (!typePattern.assertExactType(world.getMessageHandler())) return;
+               if (typePattern == TypePattern.NO) return;  // already had an error here
                TypeX iType = typePattern.getExactType();
 //             if (iType == null) {
 //                     throw new RuntimeException("yikes: " + typePattern);
index fd5c37fa7fdb4546d364d4f9266368fd9fb9729e..1051194203061562f1cb89207bae69e172c8e5f5 100644 (file)
@@ -103,6 +103,7 @@ public abstract class Shadow {
        
        public TypeX getReturnType() {
                if (kind == ConstructorCall) return getSignature().getDeclaringType();
+               else if (kind == FieldSet) return ResolvedTypeX.VOID;
                return getSignature().getReturnType();
        }
 
index 5f77b50efce86d0df64971ff6d5616949235a3fe..8fad558e1d1c17fa4a7a475ff733c2c60f5333ba 100644 (file)
@@ -1706,12 +1706,10 @@ public class BcelShadow extends Shadow {
         }
         
         TypeX returnType;
-        if (getKind() == ConstructorCall) {
-               returnType = getSignature().getDeclaringType();
-        } else if (getKind() == PreInitialization) {
+        if (getKind() == PreInitialization) {
                returnType = TypeX.OBJECTARRAY;
         } else {
-               returnType = getSignature().getReturnType();
+               returnType = getReturnType();
         }
         return
             new LazyMethodGen(
index 86a63f971b73d936e515644a759bd5867faf82d6..e39b0a830685d8281764bc820051e52b49bfa830 100644 (file)
@@ -66,9 +66,11 @@ public class AndTypePattern extends TypePattern {
        public TypePattern resolveBindings(
                IScope scope,
                Bindings bindings,
-               boolean allowBinding) {
-               left = left.resolveBindings(scope, bindings, false);
-               right = right.resolveBindings(scope, bindings, false);
+               boolean allowBinding, boolean requireExactType)
+       {
+               if (requireExactType) return notExactType(scope);
+               left = left.resolveBindings(scope, bindings, false, false);
+               right = right.resolveBindings(scope, bindings, false, false);
                return this;
        }
        
index 34eabf9361ec08137a0ae042dc63c253a4bdbf37..986d15eee647b1624882f54126b2ac459c0e96a3 100644 (file)
@@ -68,7 +68,7 @@ public class ArgsPointcut extends NameBindingPointcut {
     }
   
        public void resolveBindings(IScope scope, Bindings bindings) {
-               arguments.resolveBindings(scope, bindings, true);
+               arguments.resolveBindings(scope, bindings, true, true);
                if (arguments.ellipsisCount > 1) {
                        scope.message(IMessage.ERROR, this,
                                        "uses more than one .. in args (compiler limitation)");
index 964f6659d5352266b3d7c05af3620af39c8ab7d6..23b0a45f2f6b592245c401c487dd16d21339bd2d 100644 (file)
@@ -63,7 +63,7 @@ public class DeclareDominates extends Declare {
        }
        
     public void resolve(IScope scope) {
-       patterns = patterns.resolveBindings(scope, Bindings.NONE, false);       
+       patterns = patterns.resolveBindings(scope, Bindings.NONE, false, false);        
     }
 
        public TypePatternList getPatterns() {
index d34d69ab19cd3a6f6c231de091644212072180d0..38e5de365171083ca66a42f2470b93ece3db8001 100644 (file)
@@ -78,11 +78,11 @@ public class DeclareParents extends Declare {
        }
        
     public void resolve(IScope scope) {
-       child = child.resolveBindings(scope, Bindings.NONE, false);
-       parents = parents.resolveBindings(scope, Bindings.NONE, false); 
-       for (int i=0; i < parents.size(); i++) {
-               parents.get(i).assertExactType(scope.getMessageHandler());
-               }
+       child = child.resolveBindings(scope, Bindings.NONE, false, false);
+       parents = parents.resolveBindings(scope, Bindings.NONE, false, true); 
+//     for (int i=0; i < parents.size(); i++) {
+//             parents.get(i).assertExactType(scope.getMessageHandler());
+//             }
     }
 
        public TypePatternList getParents() {
index b80c17a2150961e504392d1bd8dd19a1d4573554..c249340e402ac855d863c7b0134d1c24874b04d3 100644 (file)
@@ -77,7 +77,7 @@ public class DeclareSoft extends Declare {
        }
 
     public void resolve(IScope scope) {
-       exception = exception.resolveBindings(scope, null, false);
+       exception = exception.resolveBindings(scope, null, false, true);
        pointcut = pointcut.resolve(scope);     
     }
     
index b98463eadab4fdb176ae33b7e2016ce4f7e7a9b1..203a9b6ffc8e47d6690c5e4ef35c2d03d5a68a68 100644 (file)
@@ -70,11 +70,9 @@ public class ExactTypePattern extends TypePattern {
        //Thread.currentThread().dumpStack();
        return "ExactTypePattern(" + type.toString() + (includeSubtypes ? "+" : "") + ")";
     }
-       public TypePattern resolveBindings(
-               IScope scope,
-               Bindings bindings,
-               boolean allowBinding) 
-       {
+       public TypePattern resolveBindings(IScope scope, Bindings bindings, 
+                                                               boolean allowBinding, boolean requireExactType)
+    { 
                throw new BCException("trying to re-resolve");
                
        }
index 4f9d1659688562c3b98573820a78ca73895ccff9..61651beb81b0fa7bf9a0450276b15ba3d1c5e18c 100644 (file)
@@ -81,7 +81,7 @@ public class HandlerPointcut extends Pointcut {
        // We want to do something here to make sure we don't sidestep the parameter
        // list in capturing type identifiers.
        public void resolveBindings(IScope scope, Bindings bindings) {
-               exceptionType = exceptionType.resolveBindings(scope, bindings, false);
+               exceptionType = exceptionType.resolveBindings(scope, bindings, false, false);
                //XXX add error if exact binding and not an exception
        }
        public Test findResidue(Shadow shadow, ExposedState state) {
index f62d693c789d91124cee7334191d60c6acb10a5f..4dbe32059bcdf336f2e6e1a496cb6f91541f1d7f 100644 (file)
@@ -64,8 +64,10 @@ public class NotTypePattern extends TypePattern {
        public TypePattern resolveBindings(
                IScope scope,
                Bindings bindings,
-               boolean allowBinding) {
-               pattern = pattern.resolveBindings(scope, bindings, false);
+               boolean allowBinding, boolean requireExactType)
+       {
+               if (requireExactType) return notExactType(scope);
+               pattern = pattern.resolveBindings(scope, bindings, false, false);
                return this;
        }
 
index 6cb043bc51a7af00f9e04466bc4d5b0bda7172dd..3697e90d89bc3eaba02a7d691b5c85f378c2d2c3 100644 (file)
@@ -66,9 +66,11 @@ public class OrTypePattern extends TypePattern {
        public TypePattern resolveBindings(
                IScope scope,
                Bindings bindings,
-               boolean allowBinding) {
-               left = left.resolveBindings(scope, bindings, false);
-               right = right.resolveBindings(scope, bindings, false);
+               boolean allowBinding, boolean requireExactType)
+       {
+               if (requireExactType) return notExactType(scope);
+               left = left.resolveBindings(scope, bindings, false, false);
+               right = right.resolveBindings(scope, bindings, false, false);
                return this;
        }
        
index 518172ed51aa5f83f1d394145300937ddf3e7e14..b774ebdf054cd614542bda1850d58afda28f6ec5 100644 (file)
@@ -116,7 +116,7 @@ public class ReferencePointcut extends Pointcut {
                }
                
                
-               arguments.resolveBindings(scope, bindings, true);
+               arguments.resolveBindings(scope, bindings, true, true);
                //XXX ensure that arguments has no ..'s in it
                
                // check that I refer to a real pointcut declaration and that I match
index fe47e13f416b96d7d4054970865afa9a968bb4e4..b5f8368402c9b2170fa8ae407ec1bfec3f1e5aaf 100644 (file)
@@ -45,13 +45,13 @@ public class SignaturePattern extends PatternNode {
        
     public SignaturePattern resolveBindings(IScope scope, Bindings bindings) { 
                if (returnType != null) {
-                       returnType = returnType.resolveBindings(scope, bindings, false);
+                       returnType = returnType.resolveBindings(scope, bindings, false, false);
                } 
                if (declaringType != null) {
-                       declaringType = declaringType.resolveBindings(scope, bindings, false);
+                       declaringType = declaringType.resolveBindings(scope, bindings, false, false);
                }
                if (parameterTypes != null) {
-                       parameterTypes = parameterTypes.resolveBindings(scope, bindings, false);
+                       parameterTypes = parameterTypes.resolveBindings(scope, bindings, false, false);
                }
                if (throwsPattern != null) {
                        throwsPattern = throwsPattern.resolveBindings(scope, bindings);
index 9baf92e105b85ff37c1a832c9266d1bf2d40da07..1351ac07514b24356f1cc119e75cc26951fe481a 100644 (file)
@@ -69,7 +69,8 @@ public class ThisOrTargetPointcut extends NameBindingPointcut {
        }
 
        public void resolveBindings(IScope scope, Bindings bindings) {
-               type = type.resolveBindings(scope, bindings, true);
+               type = type.resolveBindings(scope, bindings, true, true);
+               
                // ??? handle non-formal
        }
        
index 5917879117386384f5364e02ac2d7ff9eac10c22..3849c3ca4f0d114b2f5b7f7d4572aeea17a0fc2d 100644 (file)
@@ -58,8 +58,8 @@ public class ThrowsPattern extends PatternNode {
     
     public ThrowsPattern resolveBindings(IScope scope, Bindings bindings) {
        if (this == ANY) return this;
-       required = required.resolveBindings(scope, bindings, false);
-       forbidden = forbidden.resolveBindings(scope, bindings, false);
+       required = required.resolveBindings(scope, bindings, false, false);
+       forbidden = forbidden.resolveBindings(scope, bindings, false, false);
        return this;
     }
     
index 341138756ceea537c4ec7c44587b741bbe90487b..9da50242ef528f9d92a2d00ea51175d575b0038f 100644 (file)
@@ -41,6 +41,7 @@ public abstract class TypePattern extends PatternNode {
        
        public static final TypePattern ELLIPSIS = new EllipsisTypePattern();
        public static final TypePattern ANY = new AnyTypePattern();
+       public static final TypePattern NO = new NoTypePattern();
        
        
        protected boolean includeSubtypes;
@@ -91,8 +92,8 @@ public abstract class TypePattern extends PatternNode {
        }
        
        public TypeX resolveExactType(IScope scope, Bindings bindings) {
-               TypePattern p = resolveBindings(scope, bindings, false);
-               if (!p.assertExactType(scope.getMessageHandler())) return ResolvedTypeX.MISSING;
+               TypePattern p = resolveBindings(scope, bindings, false, true);
+               if (p == NO) return ResolvedTypeX.MISSING;
                
                return ((ExactTypePattern)p).getType();
        }
@@ -102,18 +103,25 @@ public abstract class TypePattern extends PatternNode {
                else return ResolvedTypeX.MISSING;
        }
        
-       public boolean assertExactType(IMessageHandler m) {
-               if (this instanceof ExactTypePattern) return true;
-               
-               //XXX should try harder to avoid multiple errors for one problem
-               m.handleMessage(MessageUtil.error("exact type pattern required", getSourceLocation()));
-               return false;
+       protected TypePattern notExactType(IScope s) {
+               s.getMessageHandler().handleMessage(MessageUtil.error("exact type pattern required", getSourceLocation()));
+               return NO;
        }
+       
+//     public boolean assertExactType(IMessageHandler m) {
+//             if (this instanceof ExactTypePattern) return true;
+//             
+//             //XXX should try harder to avoid multiple errors for one problem
+//             m.handleMessage(MessageUtil.error("exact type pattern required", getSourceLocation()));
+//             return false;
+//     }
 
        /**
         * This can modify in place, or return a new TypePattern if the type changes.
         */
-    public TypePattern resolveBindings(IScope scope, Bindings bindings, boolean allowBinding) { 
+    public TypePattern resolveBindings(IScope scope, Bindings bindings, 
+                                                               boolean allowBinding, boolean requireExactType)
+    { 
        return this;
     }
     
@@ -157,6 +165,7 @@ public abstract class TypePattern extends PatternNode {
        public static final byte NOT = 6;
        public static final byte OR = 7;
        public static final byte AND = 8;
+       public static final byte NO_KEY = 9;
 
        public static TypePattern read(DataInputStream s, ISourceContext context) throws IOException {
                byte key = s.readByte();
@@ -166,6 +175,7 @@ public abstract class TypePattern extends PatternNode {
                        case BINDING: return BindingTypePattern.read(s, context);
                        case ELLIPSIS_KEY: return ELLIPSIS;
                        case ANY_KEY: return ANY;
+                       case NO_KEY: return NO;
                        case NOT: return NotTypePattern.read(s, context);
                        case OR: return OrTypePattern.read(s, context);
                        case AND: return AndTypePattern.read(s, context);
@@ -259,5 +269,54 @@ class AnyTypePattern extends TypePattern {
        }
        
        public String toString() { return "*"; }
+}
 
+class NoTypePattern extends TypePattern {
+       
+       public NoTypePattern() {
+               super(false);
+       }
+
+       /**
+        * @see org.aspectj.weaver.patterns.TypePattern#matchesExactly(IType)
+        */
+       protected boolean matchesExactly(ResolvedTypeX type) {
+               return false;
+       }
+
+       /**
+        * @see org.aspectj.weaver.patterns.TypePattern#matchesInstanceof(IType)
+        */
+       public FuzzyBoolean matchesInstanceof(ResolvedTypeX type) {
+               return FuzzyBoolean.NO;
+       }
+
+       /**
+        * @see org.aspectj.weaver.patterns.PatternNode#write(DataOutputStream)
+        */
+       public void write(DataOutputStream s) throws IOException {
+               s.writeByte(NO_KEY);
+       }
+
+       /**
+        * @see org.aspectj.weaver.patterns.TypePattern#matches(IType, MatchKind)
+        */
+//     public FuzzyBoolean matches(IType type, MatchKind kind) {
+//             return FuzzyBoolean.YES;
+//     }
+
+       /**
+        * @see org.aspectj.weaver.patterns.TypePattern#matchesSubtypes(IType)
+        */
+       protected boolean matchesSubtypes(ResolvedTypeX type) {
+               return false;
+       }
+       
+       
+       public boolean isStar() {
+               return false;
+       }
+       
+       public String toString() { return "<nothing>"; }
 }
+
index 1f7abffc08b7f7c19c024ce16eb24d1de2d69af8..c4ccc1bd92f2476acf1c20c27e6dcacf14056618 100644 (file)
@@ -162,11 +162,11 @@ public class TypePatternList extends PatternNode {
         }
     }
     
-       public TypePatternList resolveBindings(IScope scope, Bindings bindings, boolean allowBinding) {
+       public TypePatternList resolveBindings(IScope scope, Bindings bindings, boolean allowBinding, boolean requireExactType) {
                for (int i=0; i<typePatterns.length; i++) {
                        TypePattern p = typePatterns[i];
                        if (p != null) {
-                               typePatterns[i] = typePatterns[i].resolveBindings(scope, bindings, allowBinding);
+                               typePatterns[i] = typePatterns[i].resolveBindings(scope, bindings, allowBinding, requireExactType);
                        }
                }
                return this;
index 4f1bfe3f002b1d1819c6a8aacc217195ad6f914b..90f8c31b7ecfbda7f0de6729ad1a7baad6e6efd2 100644 (file)
@@ -287,8 +287,10 @@ public class WildTypePattern extends TypePattern {
         * 
         * We will be replaced by what we return
         */
-       public TypePattern resolveBindings(IScope scope, Bindings bindings, boolean allowBinding) {
-               if (isStar()) {
+       public TypePattern resolveBindings(IScope scope, Bindings bindings, 
+                                                               boolean allowBinding, boolean requireExactType)
+    {          
+       if (isStar()) {
                        return TypePattern.ANY;  //??? loses source location
                }
 
@@ -320,7 +322,16 @@ public class WildTypePattern extends TypePattern {
                                cleanName = cleanName.substring(0, lastDot) + '$' + cleanName.substring(lastDot+1);
                        }
                        if (type == ResolvedTypeX.MISSING) {
-                               if (scope.getWorld().getLint().invalidAbsoluteTypeName.isEnabled()) {
+                               if (requireExactType) {
+                                       if (!allowBinding) {
+                                               scope.getWorld().getMessageHandler().handleMessage(
+                                                       MessageUtil.error("can't bind type name '" + cleanName + "'",
+                                                                                       getSourceLocation()));
+                                       } else if (scope.getWorld().getLint().invalidAbsoluteTypeName.isEnabled()) {
+                                               scope.getWorld().getLint().invalidAbsoluteTypeName.signal(cleanName, getSourceLocation());
+                                       }
+                                       return NO;
+                               } else if (scope.getWorld().getLint().invalidAbsoluteTypeName.isEnabled()) {
                                        scope.getWorld().getLint().invalidAbsoluteTypeName.signal(cleanName, getSourceLocation());
                                }
                        } else {
@@ -330,6 +341,12 @@ public class WildTypePattern extends TypePattern {
                                return ret;
                        }
                } else {
+                       if (requireExactType) {
+                               scope.getWorld().getMessageHandler().handleMessage(
+                                       MessageUtil.error("wildcard type pattern not allowed, must use type name",
+                                                                               getSourceLocation()));
+                               return NO;
+                       }
                        //XXX need to implement behavior for Lint.invalidWildcardTypeName
                }
                
index 2b931985b2628f3f4cbc869b42fb699b83c2f2ed..7e8663ca2ee2449e3b5b6d8bf793d1276652058a 100644 (file)
@@ -50,7 +50,7 @@ public class WithinPointcut extends Pointcut {
        }
 
        public void resolveBindings(IScope scope, Bindings bindings) {
-               type = type.resolveBindings(scope, bindings, false);
+               type = type.resolveBindings(scope, bindings, false, false);
        }
 
        public void postRead(ResolvedTypeX enclosingType) {
index d7b598f38802991801732beb0570aa4be4a4f69c..18829b9fbda0b74ea66497d15d42af06581e3832 100644 (file)
@@ -43,7 +43,7 @@ public class BindingTestCase extends TestCase {
                BindingTypePattern[] b = new BindingTypePattern[] {null, bt};
                
                checkBindings("this(b)",b);
-               checkBindings("this(Foo)", none);
+               checkBindings("this(java.lang.String)", none);
                checkBindings("this(*)", none);
                checkBindings("this(a)", a);
                
@@ -65,12 +65,12 @@ public class BindingTestCase extends TestCase {
                //checkBindingFailure("this(a) && this(b)");
 
                checkBindingFailure("this(a) || this(b)", "inconsistent");
-               checkBindingFailure("this(A) || this(b)", "inconsistent");
-               checkBindingFailure("this(a) || this(B)", "inconsistent");
+               checkBindingFailure("this(java.lang.String) || this(b)", "inconsistent");
+               checkBindingFailure("this(a) || this(java.lang.String)", "inconsistent");
                checkBindings("this(a) || this(a)", a);
                
-               checkBindings("!this(Foo)", none);
-               checkBindings("!this(Foo) && this(a)", a);
+               checkBindings("!this(java.lang.String)", none);
+               checkBindings("!this(java.lang.String) && this(a)", a);
                checkBindingFailure("!this(a)", "negation");
                //checkBindingFailure("this(a)");
        
index e756d11f4dcc703510b7bb113956537a927c2423..b584b635f35ed9c4586842f5cf83ec9b289fe7c8 100644 (file)
@@ -113,7 +113,7 @@ public class TypePatternListTestCase extends TestCase {
             types[i] = world.resolve(names[i]);
         }
         
-        p.resolveBindings(makeTestScope(), Bindings.NONE, false);
+        p.resolveBindings(makeTestScope(), Bindings.NONE, false, false);
                //System.out.println("type: " + type);
                FuzzyBoolean result = p.matches(types, TypePattern.STATIC);
                String msg = "matches statically " + pattern + " to " + Arrays.asList(types);
@@ -127,7 +127,7 @@ public class TypePatternListTestCase extends TestCase {
            
     public void stupidCheck(String pattern, boolean[] matches) {
         TypePatternList p = makeArgumentsPattern(pattern);
-        p.resolveBindings(makeTestScope(), Bindings.NONE, false);
+        p.resolveBindings(makeTestScope(), Bindings.NONE, false, false);
         
         int len = matches.length;
         
index 5b3c702e8260c115b40e9c473ab0bbe3bb720223..7c6ea7a4ffa9d65166f628e011f0c066b402c001 100644 (file)
@@ -173,7 +173,7 @@ public class TypePatternTestCase extends TestCase {
                TestScope scope = makeTestScope();
                scope.setImportedPrefixes(importedPrefixes);
                scope.setImportedNames(importedNames);
-               return (WildTypePattern) unresolved.resolveBindings(scope, Bindings.NONE, false);
+               return (WildTypePattern) unresolved.resolveBindings(scope, Bindings.NONE, false, false);
        }
 
 
@@ -218,7 +218,7 @@ public class TypePatternTestCase extends TestCase {
                TypePattern p = makeTypePattern(pattern);
                ResolvedTypeX type = world.resolve(name);
                
-               p = p.resolveBindings(makeTestScope(), null, false);
+               p = p.resolveBindings(makeTestScope(), null, false, false);
                
                
                //System.out.println("type: " + p);
@@ -238,7 +238,7 @@ public class TypePatternTestCase extends TestCase {
 
        private void checkMatch(String pattern, String name, boolean shouldMatch) {
                TypePattern p = makeTypePattern(pattern);
-               p = p.resolveBindings(makeTestScope(), null, false);
+               p = p.resolveBindings(makeTestScope(), null, false, false);
                checkPatternMatch(p, name, shouldMatch);
        }