SameParameterValueOptimizer should ignore methods called from native code.


git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@7568 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/SameParameterValueOptimizer.java b/dev/core/src/com/google/gwt/dev/jjs/impl/SameParameterValueOptimizer.java
index c22d483..bdbf664 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/impl/SameParameterValueOptimizer.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/SameParameterValueOptimizer.java
@@ -29,6 +29,8 @@
 import com.google.gwt.dev.jjs.ast.JProgram;
 import com.google.gwt.dev.jjs.ast.JValueLiteral;
 import com.google.gwt.dev.jjs.ast.JVisitor;
+import com.google.gwt.dev.jjs.ast.js.JsniMethodBody;
+import com.google.gwt.dev.jjs.ast.js.JsniMethodRef;
 
 import java.util.HashSet;
 import java.util.IdentityHashMap;
@@ -103,6 +105,13 @@
     }
 
     @Override
+    public void endVisit(JsniMethodBody x, Context ctx) {
+      for (JsniMethodRef methodRef : x.getJsniMethodRefs()) {
+        rescuedMethods.add(methodRef.getTarget());
+      }
+    }
+
+    @Override
     public boolean visit(JMethod x, Context ctx) {
       Set<JMethod> overrides = program.typeOracle.getAllOverrides(x);
       if (!overrides.isEmpty()) {
diff --git a/dev/core/test/com/google/gwt/dev/jjs/impl/SameParameterValueOptimizerTest.java b/dev/core/test/com/google/gwt/dev/jjs/impl/SameParameterValueOptimizerTest.java
index 036d71a..196894b 100644
--- a/dev/core/test/com/google/gwt/dev/jjs/impl/SameParameterValueOptimizerTest.java
+++ b/dev/core/test/com/google/gwt/dev/jjs/impl/SameParameterValueOptimizerTest.java
@@ -52,6 +52,21 @@
         "  int j = 1;", "}");
   }
 
+  public void testJsniReferenceSaveMethod() throws Exception {
+    addSnippetClassDecl(
+        "public static native void someStaticMethod() /*-{" +
+        "  var foo = @test.EntryPoint::foo(Ljava/lang/String;)" +
+        "}-*/");
+    
+    assertOptimize(
+        "foo", 
+        "static void foo(String s) { String p = s; }",
+        "foo(\"\"); foo(\"\");").into(
+        "public static void foo(String s){",
+        "  String p = s;", 
+        "}");
+  }
+
   private OptimizationResult assertOptimize(String methodName,
       String methodDecl, String codeSnippet) throws UnableToCompleteException {
     addSnippetClassDecl(methodDecl);