001    
002    aspect ErrorCheck {
003         
004      // add error for missing return
005      public void MethodDecl.collectErrors(Collection c) {
006        super.collectErrors(c);
007        if(!endsWithReturn())
008          error(c, "Missing return in method " + getName());
009      }
010      
011      syn boolean MethodDecl.endsWithReturn() = getBody().endsWithReturn();
012      syn boolean Block.endsWithReturn() = getNumBlockStmt() > 0 ? getBlockStmt(getNumBlockStmt()-1).endsWithReturn() : false;
013      syn boolean BlockStmt.endsWithReturn() = false;
014      eq ReturnStmt.endsWithReturn() = true;
015      
016      
017      // add error for undeclared method
018      public void MethodUse.collectErrors(Collection c) {
019        super.collectErrors(c);
020        if (decl() == null) {
021                StringBuffer buf = new StringBuffer();
022                buf.append(getName() + "(");
023                for (int i = 0; i < getNumArg(); i++) {
024                        buf.append(getArg(i).type());
025                        if (i < getNumArg() - 1) 
026                                buf.append(","); {
027                        }
028                }
029                buf.append(")");
030                error(c, "Unknown method " + buf);
031        }
032      }
033    
034    }