Updated doc and a couple of identifiers to illuminate hosted mode class rewriting a bit.
Review by: jat (desk)
git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@2511 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/dev/core/src/com/google/gwt/dev/shell/CompilingClassLoader.java b/dev/core/src/com/google/gwt/dev/shell/CompilingClassLoader.java
index 9304833..af00878 100644
--- a/dev/core/src/com/google/gwt/dev/shell/CompilingClassLoader.java
+++ b/dev/core/src/com/google/gwt/dev/shell/CompilingClassLoader.java
@@ -24,7 +24,7 @@
import com.google.gwt.dev.jdt.ByteCodeCompiler;
import com.google.gwt.dev.jdt.CacheManager;
import com.google.gwt.dev.shell.rewrite.HostedModeClassRewriter;
-import com.google.gwt.dev.shell.rewrite.HostedModeClassRewriter.InstanceMethodMapper;
+import com.google.gwt.dev.shell.rewrite.HostedModeClassRewriter.InstanceMethodOracle;
import com.google.gwt.dev.util.JsniRef;
import com.google.gwt.util.tools.Utility;
@@ -245,11 +245,15 @@
}
}
- private class MyMethodDeclarationMapper implements InstanceMethodMapper {
+ /**
+ * Implements {@link InstanceMethodOracle} on behalf of the
+ * {@link HostedModeClassRewriter}. Implemented using {@link TypeOracle}.
+ */
+ private class MyInstanceMethodOracle implements InstanceMethodOracle {
private final Map<String, Set<JClassType>> signatureToDeclaringClasses = new HashMap<String, Set<JClassType>>();
- public MyMethodDeclarationMapper(Set<JClassType> jsoTypes,
+ public MyInstanceMethodOracle(Set<JClassType> jsoTypes,
JClassType javaLangObject) {
// Populate the map.
for (JClassType type : jsoTypes) {
@@ -276,7 +280,7 @@
}
}
- public String findDeclaringClass(String desc, String signature) {
+ public String findOriginalDeclaringClass(String desc, String signature) {
// Lookup the method.
Set<JClassType> declaringClasses = signatureToDeclaringClasses.get(signature);
if (declaringClasses.size() == 1) {
@@ -396,8 +400,8 @@
jsoTypeNames.add(getBinaryName(type));
}
- MyMethodDeclarationMapper mapper = new MyMethodDeclarationMapper(
- jsoTypes, typeOracle.getJavaLangObject());
+ MyInstanceMethodOracle mapper = new MyInstanceMethodOracle(jsoTypes,
+ typeOracle.getJavaLangObject());
classRewriter = new HostedModeClassRewriter(jsoTypeNames, mapper);
} else {
// If we couldn't find the JSO class, we don't need to do any rewrites.
diff --git a/dev/core/src/com/google/gwt/dev/shell/rewrite/HostedModeClassRewriter.java b/dev/core/src/com/google/gwt/dev/shell/rewrite/HostedModeClassRewriter.java
index fde11c4..4e7653f 100644
--- a/dev/core/src/com/google/gwt/dev/shell/rewrite/HostedModeClassRewriter.java
+++ b/dev/core/src/com/google/gwt/dev/shell/rewrite/HostedModeClassRewriter.java
@@ -46,24 +46,33 @@
* @see WriteJsoImpl
*/
public class HostedModeClassRewriter {
+ /*
+ * Note: this rewriter operates on a class-by-class basis and has no global
+ * view on the entire system. However, its operation requires certain global
+ * state information. Therefore, all such global state must be passed into the
+ * constructor.
+ */
/**
- * Maps instance methods to the class in which they are declared.
+ * Maps instance methods to the class in which they are declared. This must be
+ * provided by the caller since it requires global program state.
*/
- public interface InstanceMethodMapper {
+ public interface InstanceMethodOracle {
/**
- * For a given instance method and declared qualifying class, find the class
- * in which that method was first declared. Methods declared on Object will
- * return "java/lang/Object". Static methods will always return
- * <code>declaredClass</code>.
+ * For a given instance method and declared enclosing class (which must be a
+ * JSO subtype), find the class in which that method was originally
+ * declared. Methods declared on Object will return "java/lang/Object".
+ * Static methods will always return <code>declaredClass</code>.
*
- * @param desc a descriptor of the static type of the qualifier
+ * @param declaredClass a descriptor of the static type of the qualifier
* @param signature the binary signature of the method
- * @return the descriptor of the class in which that method was declared
+ * @return the descriptor of the class in which that method was declared,
+ * which will either be <code>declaredClass</code> or some
+ * superclass
* @throws IllegalArgumentException if the method could not be found
*/
- String findDeclaringClass(String desc, String signature);
+ String findOriginalDeclaringClass(String declaredClass, String signature);
}
static final String REFERENCE_FIELD = JsValueGlue.HOSTED_MODE_REFERENCE;
@@ -97,7 +106,7 @@
/**
* Maps methods to the class in which they are declared.
*/
- private InstanceMethodMapper mapper;
+ private InstanceMethodOracle mapper;
/**
* Creates a new {@link HostedModeClassRewriter} for a specified set of
@@ -108,7 +117,7 @@
* @param mapper maps methods to the class in which they are declared
*/
public HostedModeClassRewriter(Set<String> jsoSubtypes,
- InstanceMethodMapper mapper) {
+ InstanceMethodOracle mapper) {
Set<String> buildJsoIntfDescriptors = new HashSet<String>();
Set<String> buildJsoImplDescriptors = new HashSet<String>();
for (String jsoSubtype : jsoSubtypes) {
diff --git a/dev/core/src/com/google/gwt/dev/shell/rewrite/RewriteRefsToJsoClasses.java b/dev/core/src/com/google/gwt/dev/shell/rewrite/RewriteRefsToJsoClasses.java
index 6be81e7..3a45363 100644
--- a/dev/core/src/com/google/gwt/dev/shell/rewrite/RewriteRefsToJsoClasses.java
+++ b/dev/core/src/com/google/gwt/dev/shell/rewrite/RewriteRefsToJsoClasses.java
@@ -21,7 +21,7 @@
import com.google.gwt.dev.asm.MethodVisitor;
import com.google.gwt.dev.asm.Opcodes;
import com.google.gwt.dev.asm.commons.Remapper;
-import com.google.gwt.dev.shell.rewrite.HostedModeClassRewriter.InstanceMethodMapper;
+import com.google.gwt.dev.shell.rewrite.HostedModeClassRewriter.InstanceMethodOracle;
import java.util.Set;
@@ -80,7 +80,7 @@
if (jsoDescriptors.contains(owner)) {
// Find the class that actually declared the method.
if (opcode == Opcodes.INVOKEVIRTUAL) {
- owner = mapper.findDeclaringClass(owner, name + desc);
+ owner = mapper.findOriginalDeclaringClass(owner, name + desc);
}
if (!owner.equals("java/lang/Object")) {
if (opcode == Opcodes.INVOKEVIRTUAL
@@ -121,7 +121,7 @@
/**
* Maps methods to the class in which they are declared.
*/
- private InstanceMethodMapper mapper;
+ private InstanceMethodOracle mapper;
/**
* Construct a new rewriter instance.
@@ -132,7 +132,7 @@
* @param mapper maps methods to the class in which they are declared
*/
public RewriteRefsToJsoClasses(ClassVisitor cv, Set<String> jsoDescriptors,
- InstanceMethodMapper mapper) {
+ InstanceMethodOracle mapper) {
super(cv);
this.jsoDescriptors = jsoDescriptors;
this.mapper = mapper;
diff --git a/dev/core/src/com/google/gwt/dev/shell/rewrite/WriteJsoImpl.java b/dev/core/src/com/google/gwt/dev/shell/rewrite/WriteJsoImpl.java
index af0bb7f..8561b42 100644
--- a/dev/core/src/com/google/gwt/dev/shell/rewrite/WriteJsoImpl.java
+++ b/dev/core/src/com/google/gwt/dev/shell/rewrite/WriteJsoImpl.java
@@ -20,7 +20,7 @@
import com.google.gwt.dev.asm.FieldVisitor;
import com.google.gwt.dev.asm.MethodVisitor;
import com.google.gwt.dev.asm.Opcodes;
-import com.google.gwt.dev.shell.rewrite.HostedModeClassRewriter.InstanceMethodMapper;
+import com.google.gwt.dev.shell.rewrite.HostedModeClassRewriter.InstanceMethodOracle;
import java.util.ArrayList;
import java.util.Set;
@@ -49,7 +49,7 @@
/**
* Maps methods to the class in which they are declared.
*/
- private InstanceMethodMapper mapper;
+ private InstanceMethodOracle mapper;
/**
* The original name of the class being visited.
@@ -65,7 +65,7 @@
* @param mapper maps methods to the class in which they are declared
*/
public WriteJsoImpl(ClassVisitor cv, Set<String> jsoDescriptors,
- InstanceMethodMapper mapper) {
+ InstanceMethodOracle mapper) {
super(cv);
this.jsoDescriptors = jsoDescriptors;
this.mapper = mapper;
@@ -119,7 +119,7 @@
}
private boolean isObjectMethod(String signature) {
- return "java/lang/Object".equals(mapper.findDeclaringClass(originalName,
+ return "java/lang/Object".equals(mapper.findOriginalDeclaringClass(originalName,
signature));
}