Revision: 9730
Author: [email protected]
Date: Fri Feb 11 10:29:39 2011
Log: 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
http://code.google.com/p/google-web-toolkit/source/detail?r=9730
Modified:
/trunk/dev/core/src/com/google/gwt/dev/javac/MethodArgNamesLookup.java
/trunk/dev/core/src/com/google/gwt/dev/javac/MethodParamCollector.java
/trunk/dev/core/test/com/google/gwt/dev/javac/CompilationStateTest.java
=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/javac/MethodArgNamesLookup.java
Thu Sep 23 07:20:47 2010
+++ /trunk/dev/core/src/com/google/gwt/dev/javac/MethodArgNamesLookup.java
Fri Feb 11 10:29:39 2011
@@ -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);
+ }
+}
=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/javac/MethodParamCollector.java
Wed Feb 9 10:04:25 2011
+++ /trunk/dev/core/src/com/google/gwt/dev/javac/MethodParamCollector.java
Fri Feb 11 10:29:39 2011
@@ -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
=======================================
--- /trunk/dev/core/test/com/google/gwt/dev/javac/CompilationStateTest.java
Mon Aug 30 09:54:26 2010
+++ /trunk/dev/core/test/com/google/gwt/dev/javac/CompilationStateTest.java
Fri Feb 11 10:29:39 2011
@@ -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);
}
@@ -218,6 +219,55 @@
assertNotNull(newBar);
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();
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors