Proactively gathers more method names for MethodArgNamesLookup.  Before this
logic was only interested in abstract methods.  Now it collects any non local methods
with at least one argument.

Review at http://gwt-code-reviews.appspot.com/1359801


git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@9730 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/dev/core/src/com/google/gwt/dev/javac/MethodArgNamesLookup.java b/dev/core/src/com/google/gwt/dev/javac/MethodArgNamesLookup.java
index b4bb5a3..4732f31 100644
--- a/dev/core/src/com/google/gwt/dev/javac/MethodArgNamesLookup.java
+++ b/dev/core/src/com/google/gwt/dev/javac/MethodArgNamesLookup.java
@@ -22,6 +22,7 @@
 
 import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration;
 
+import java.io.Serializable;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -29,7 +30,7 @@
  * Keeps track of method argument names that cannot be read from just the
  * bytecode.
  */
-public class MethodArgNamesLookup {
+public class MethodArgNamesLookup implements Serializable {
 
   private Map<String, String[]> methodArgs;
 
@@ -97,4 +98,19 @@
     String key = StringInterner.get().intern(buf.toString());
     methodArgs.put(key, argNames);
   }
+
+  /**
+   * For Unit Testing: returns an array of methods with arguments.
+   */
+  String[] getMethods() {
+    return methodArgs.keySet().toArray(new String[0]);
+  }
+
+  /**
+   * For Unit Testing: returns an array of argument names for the specified
+   * method.
+   */
+  String[] lookup(String methodName) {
+    return methodArgs.get(methodName);
+  }
 }
diff --git a/dev/core/src/com/google/gwt/dev/javac/MethodParamCollector.java b/dev/core/src/com/google/gwt/dev/javac/MethodParamCollector.java
index 4c4b589..901e512 100644
--- a/dev/core/src/com/google/gwt/dev/javac/MethodParamCollector.java
+++ b/dev/core/src/com/google/gwt/dev/javac/MethodParamCollector.java
@@ -18,6 +18,7 @@
 import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration;
 import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration;
 import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
+import org.eclipse.jdt.internal.compiler.lookup.MethodBinding;
 
 /**
  * Collects method parameter names.
@@ -32,10 +33,20 @@
       this.methodArgs = methodArgs;
     }
 
+    /**
+     * Collect information on methods with at least one argument that will be
+     * visible in the TypeOracle.
+     */
     @Override
     protected boolean interestingMethod(AbstractMethodDeclaration method) {
-      return method.arguments != null && method.arguments.length > 0
-          && method.isAbstract();
+      if (method.arguments == null || method.arguments.length == 0) {
+        return false;
+      }
+      MethodBinding binding = method.binding;
+      if (binding == null || binding.declaringClass.isLocalType()) {
+        return false;
+      }
+      return true;
     }
 
     @Override
diff --git a/dev/core/test/com/google/gwt/dev/javac/CompilationStateTest.java b/dev/core/test/com/google/gwt/dev/javac/CompilationStateTest.java
index d477a61..0bfa8b7 100644
--- a/dev/core/test/com/google/gwt/dev/javac/CompilationStateTest.java
+++ b/dev/core/test/com/google/gwt/dev/javac/CompilationStateTest.java
@@ -20,6 +20,7 @@
 import com.google.gwt.dev.javac.impl.MockResourceOracle;
 import com.google.gwt.dev.javac.impl.TweakedMockJavaResource;
 
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -74,7 +75,7 @@
     testCaching(JavaResourceBase.FOO);
   }
 
-  /* test that mutiple generated units, if unchanged, are reused */
+  /* test that multiple generated units, if unchanged, are reused */
   public void testCachingOfMultipleUnits() {
     testCaching(JavaResourceBase.BAR, JavaResourceBase.FOO);
   }
@@ -219,6 +220,55 @@
     assertNotSame(oldBar, newBar);
   }
 
+  public void testMethodArgs() {
+    MockJavaResource resource = new MockJavaResource("test.MethodArgsTest") {
+      @Override
+      protected CharSequence getContent() {
+        StringBuffer code = new StringBuffer();
+        code.append("package test;\n");
+        code.append("public abstract class MethodArgsTest {\n");
+        code.append("  public abstract void anAbstractMethod(String aArg1);\n");
+        code.append("  public native void aNativeMethod(String nArg1, int nArg2);\n");
+        code.append("  public void aMethod(String mArg1, int mArg2, char mArg3) {}\n");
+        code.append("  public void aNoArgMethod() {}\n");
+        code.append("}\n");
+        return code;
+      }
+    };
+
+    validateCompilationState();
+    oracle.add(resource);
+    rebuildCompilationState();
+    validateCompilationState();
+    Map<String, CompilationUnit> unitMap = state.getCompilationUnitMap();
+    MethodArgNamesLookup methodArgs = unitMap.get(Shared.getTypeName(resource)).getMethodArgs();
+    String[] methods = methodArgs.getMethods();
+    assertEquals(3, methods.length);
+    Arrays.sort(methods);
+    assertEquals("test.MethodArgsTest.aMethod(Ljava/lang/String;IC)V",
+        methods[0]);
+    assertEquals("test.MethodArgsTest.aNativeMethod(Ljava/lang/String;I)V",
+        methods[1]);
+    assertEquals("test.MethodArgsTest.anAbstractMethod(Ljava/lang/String;)V",
+        methods[2]);
+
+    String[] names;
+    names = methodArgs.lookup(methods[0]);
+    assertEquals(3, names.length);
+    assertEquals("mArg1", names[0]);
+    assertEquals("mArg2", names[1]);
+    assertEquals("mArg3", names[2]);
+
+    names = methodArgs.lookup(methods[1]);
+    assertEquals(2, names.length);
+    assertEquals("nArg1", names[0]);
+    assertEquals("nArg2", names[1]);
+
+    names = methodArgs.lookup(methods[2]);
+    assertEquals(1, names.length);
+    assertEquals("aArg1", names[0]);
+  }
+
   public void testSourceOracleAdd() {
     validateCompilationState();