more changes.
[IRC.git] / Robust / src / Analysis / SSJava / MethodAnnotationCheck.java
index 9ef4b4a8c6701f32d2f81d29709696a2048996bf..f05fcff0fad2396e47046a74029e713eb1c46a86 100644 (file)
@@ -59,17 +59,19 @@ public class MethodAnnotationCheck {
       Object obj = toanalyze.iterator().next();
       ClassDescriptor cd = (ClassDescriptor) obj;
       toanalyze.remove(cd);
+
       if (!cd.isInterface()) {
         for (Iterator method_it = cd.getMethods(); method_it.hasNext();) {
           MethodDescriptor md = (MethodDescriptor) method_it.next();
           checkMethodBody(cd, md);
         }
       }
+
     }
 
     for (Iterator iterator = annotatedMDSet.iterator(); iterator.hasNext();) {
       MethodDescriptor md = (MethodDescriptor) iterator.next();
-      ssjava.putHasAnnotation(md);
+      ssjava.addAnnotationRequire(md);
     }
 
     Set<Pair> visited = new HashSet<Pair>();
@@ -79,6 +81,7 @@ public class MethodAnnotationCheck {
     while (!tovisit.isEmpty()) {
       MethodDescriptor callerMD = tovisit.iterator().next();
       tovisit.remove(callerMD);
+
       Set<MethodDescriptor> calleeSet = caller2calleeSet.get(callerMD);
       if (calleeSet != null) {
         for (Iterator iterator = calleeSet.iterator(); iterator.hasNext();) {
@@ -86,8 +89,22 @@ public class MethodAnnotationCheck {
           Pair p = new Pair(callerMD, calleeMD);
           if (!visited.contains(p)) {
             visited.add(p);
+
             tovisit.add(calleeMD);
-            ssjava.putHasAnnotation(calleeMD);
+
+            Set<MethodDescriptor> possibleCalleeSet =
+                (Set<MethodDescriptor>) ssjava.getCallGraph().getMethods(calleeMD);
+
+            for (Iterator iterator2 = possibleCalleeSet.iterator(); iterator2.hasNext();) {
+              MethodDescriptor possibleCallee = (MethodDescriptor) iterator2.next();
+
+              if (!possibleCallee.isAbstract()) {
+                ssjava.addAnnotationRequire(possibleCallee);
+                tovisit.add(possibleCallee);
+              }
+
+            }
+
           }
         }
       }
@@ -100,7 +117,7 @@ public class MethodAnnotationCheck {
     // be annotated.
 
     Set<MethodDescriptor> tovisit = new HashSet<MethodDescriptor>();
-    tovisit.addAll(ssjava.getMd2hasAnnotation().keySet());
+    tovisit.addAll(ssjava.getAnnotationRequireSet());
 
     while (!tovisit.isEmpty()) {
       MethodDescriptor md = tovisit.iterator().next();
@@ -117,12 +134,41 @@ public class MethodAnnotationCheck {
             MethodDescriptor matchmd = (MethodDescriptor) methodit.next();
             if (md.matches(matchmd)) {
               if (matchmd.getClassDesc().equals(subCD)) {
-                ssjava.putHasAnnotation(matchmd);
+                ssjava.addAnnotationRequire(matchmd);
               }
             }
           }
         }
       }
+
+      // need to check super classess if the current method is inherited from
+      // them, all of ancestor method should be annoated
+      ClassDescriptor currentCd = cd;
+      ClassDescriptor superCd = tu.getSuper(currentCd);
+      while (!superCd.getSymbol().equals("Object")) {
+        Set possiblematches = superCd.getMethodTable().getSet(md.getSymbol());
+        for (Iterator methodit = possiblematches.iterator(); methodit.hasNext();) {
+          MethodDescriptor matchmd = (MethodDescriptor) methodit.next();
+          if (md.matches(matchmd)) {
+            ssjava.addAnnotationRequire(matchmd);
+          }
+        }
+        currentCd = superCd;
+        superCd = tu.getSuper(currentCd);
+      }
+
+      Set<ClassDescriptor> superIFSet = tu.getSuperIFs(cd);
+      for (Iterator iterator = superIFSet.iterator(); iterator.hasNext();) {
+        ClassDescriptor parentInterface = (ClassDescriptor) iterator.next();
+        Set possiblematches = parentInterface.getMethodTable().getSet(md.getSymbol());
+        for (Iterator methodit = possiblematches.iterator(); methodit.hasNext();) {
+          MethodDescriptor matchmd = (MethodDescriptor) methodit.next();
+          if (md.matches(matchmd)) {
+            ssjava.addAnnotationRequire(matchmd);
+          }
+        }
+      }
+
     }
 
   }
@@ -165,7 +211,7 @@ public class MethodAnnotationCheck {
       break;
 
     case Kind.DeclarationNode:
-      // checkLocationFromDeclarationNode(md, nametable, (DeclarationNode) bsn);
+      checkDeclarationNode(md, nametable, (DeclarationNode) bsn, flag);
       break;
 
     case Kind.IfStatementNode:
@@ -183,14 +229,15 @@ public class MethodAnnotationCheck {
     }
   }
 
-  void checkDeclarationNode(MethodDescriptor md, SymbolTable nametable, DeclarationNode dn,
+  private void checkDeclarationNode(MethodDescriptor md, SymbolTable nametable, DeclarationNode dn,
       boolean flag) {
     if (dn.getExpression() != null) {
       checkExpressionNode(md, nametable, dn.getExpression(), flag);
     }
   }
 
-  void checkReturnNode(MethodDescriptor md, SymbolTable nametable, ReturnNode rn, boolean flag) {
+  private void checkReturnNode(MethodDescriptor md, SymbolTable nametable, ReturnNode rn,
+      boolean flag) {
     if (rn.getReturnExpression() != null) {
       if (md.getReturnType() != null) {
         checkExpressionNode(md, nametable, rn.getReturnExpression(), flag);
@@ -198,7 +245,7 @@ public class MethodAnnotationCheck {
     }
   }
 
-  void checkLoopNode(MethodDescriptor md, SymbolTable nametable, LoopNode ln, boolean flag) {
+  private void checkLoopNode(MethodDescriptor md, SymbolTable nametable, LoopNode ln, boolean flag) {
     if (ln.getType() == LoopNode.WHILELOOP || ln.getType() == LoopNode.DOWHILELOOP) {
       checkExpressionNode(md, nametable, ln.getCondition(), flag);
       checkBlockNode(md, nametable, ln.getBody(), flag);
@@ -218,8 +265,8 @@ public class MethodAnnotationCheck {
     }
   }
 
-  void checkIfStatementNode(MethodDescriptor md, SymbolTable nametable, IfStatementNode isn,
-      boolean flag) {
+  private void checkIfStatementNode(MethodDescriptor md, SymbolTable nametable,
+      IfStatementNode isn, boolean flag) {
     checkExpressionNode(md, nametable, isn.getCondition(), flag);
     checkBlockNode(md, nametable, isn.getTrueBlock(), flag);
     if (isn.getFalseBlock() != null) {