Moved the checkExceptions method so that instead of a static method, it becomes
an instance method of ApiAbstractMethod class.

Review by: scottb (TBR)



git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@3373 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/tools/api-checker/src/com/google/gwt/tools/apichecker/ApiAbstractMethod.java b/tools/api-checker/src/com/google/gwt/tools/apichecker/ApiAbstractMethod.java
index 7089ef5..6164817 100644
--- a/tools/api-checker/src/com/google/gwt/tools/apichecker/ApiAbstractMethod.java
+++ b/tools/api-checker/src/com/google/gwt/tools/apichecker/ApiAbstractMethod.java
@@ -19,7 +19,10 @@
 import com.google.gwt.core.ext.typeinfo.JClassType;
 import com.google.gwt.core.ext.typeinfo.JParameter;
 import com.google.gwt.core.ext.typeinfo.JType;
+import com.google.gwt.core.ext.typeinfo.TypeOracle;
 
+import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 
 /**
@@ -142,6 +145,39 @@
     return computeApiSignature(method);
   }
 
+  List<ApiChange> checkExceptions(ApiAbstractMethod newMethod) {
+    ArrayList<JType> legalTypes = new ArrayList<JType>();
+
+    // A throw declaration for an unchecked exception does not change the API.
+    TypeOracle newTypeOracle = newMethod.getMethod().getEnclosingType().getOracle();
+    JClassType errorType = newTypeOracle.findType(Error.class.getName());
+    if (errorType != null) {
+      legalTypes.add(errorType);
+    }
+    JClassType rteType = newTypeOracle.findType(RuntimeException.class.getName());
+    if (rteType != null) {
+      legalTypes.add(rteType);
+    }
+
+    legalTypes.addAll(Arrays.asList(getMethod().getThrows()));
+    List<ApiChange> ret = new ArrayList<ApiChange>();
+    for (JType newException : newMethod.getMethod().getThrows()) {
+      boolean isSubclass = false;
+      for (JType legalType : legalTypes) {
+        if (ApiDiffGenerator.isFirstTypeAssignableToSecond(newException,
+            legalType)) {
+          isSubclass = true;
+          break;
+        }
+      }
+      if (!isSubclass) {
+        ret.add(new ApiChange(this, ApiChange.Status.EXCEPTION_TYPE_ERROR,
+            "unhandled exception in new code " + newException));
+      }
+    }
+    return ret;
+  }
+
   abstract ApiChange checkReturnTypeCompatibility(ApiAbstractMethod newMethod);
 
   String getApiSignature() {
@@ -172,7 +208,7 @@
    * 
    */
   abstract List<ApiChange.Status> getModifierChanges(ApiAbstractMethod newMethod);
-
+  
   private String computeRelativeSignature() {
     String signature = computeInternalSignature(method);
     if (ApiCompatibilityChecker.DEBUG) {
diff --git a/tools/api-checker/src/com/google/gwt/tools/apichecker/ApiClassDiffGenerator.java b/tools/api-checker/src/com/google/gwt/tools/apichecker/ApiClassDiffGenerator.java
index 2eb26e5..334e134 100644
--- a/tools/api-checker/src/com/google/gwt/tools/apichecker/ApiClassDiffGenerator.java
+++ b/tools/api-checker/src/com/google/gwt/tools/apichecker/ApiClassDiffGenerator.java
@@ -17,12 +17,9 @@
 package com.google.gwt.tools.apichecker;
 
 import com.google.gwt.core.ext.typeinfo.JClassType;
-import com.google.gwt.core.ext.typeinfo.JType;
 import com.google.gwt.core.ext.typeinfo.NotFoundException;
-import com.google.gwt.core.ext.typeinfo.TypeOracle;
 
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.EnumMap;
@@ -49,42 +46,7 @@
     sb.append("\n");
     return sb.toString();
   }
-
-  private static List<ApiChange> checkExceptions(ApiAbstractMethod newMethod,
-      ApiAbstractMethod oldMethod) {
-
-    ArrayList<JType> legalTypes = new ArrayList<JType>();
-
-    // A throw declaration for an unchecked exception does not change the API.
-    TypeOracle newTypeOracle = newMethod.getMethod().getEnclosingType().getOracle();
-    JClassType errorType = newTypeOracle.findType(Error.class.getName());
-    if (errorType != null) {
-      legalTypes.add(errorType);
-    }
-    JClassType rteType = newTypeOracle.findType(RuntimeException.class.getName());
-    if (rteType != null) {
-      legalTypes.add(rteType);
-    }
-
-    legalTypes.addAll(Arrays.asList(oldMethod.getMethod().getThrows()));
-    List<ApiChange> ret = new ArrayList<ApiChange>();
-    for (JType newException : newMethod.getMethod().getThrows()) {
-      boolean isSubclass = false;
-      for (JType legalType : legalTypes) {
-        if (ApiDiffGenerator.isFirstTypeAssignableToSecond(newException,
-            legalType)) {
-          isSubclass = true;
-          break;
-        }
-      }
-      if (!isSubclass) {
-        ret.add(new ApiChange(oldMethod, ApiChange.Status.EXCEPTION_TYPE_ERROR,
-            "unhandled exception in new code " + newException));
-      }
-    }
-    return ret;
-  }
-
+  
   private Set<ApiField> allIntersectingFields = new HashSet<ApiField>();
   /**
    * Find all constructors, methods, fields that are present in either
@@ -380,8 +342,7 @@
             if (returnType != null) {
               addProperty(intersectingElements, methodInExisting, returnType);
             }
-            for (ApiChange apiChange : checkExceptions(methodInNew,
-                methodInExisting)) {
+            for (ApiChange apiChange : methodInExisting.checkExceptions(methodInNew)) {
               addProperty(intersectingElements, methodInExisting, apiChange);
             }
             for (ApiChange.Status status : methodInExisting.getModifierChanges(methodInNew)) {