Factors out TypeOracleMediator.computeBinaryClassName() to be a method on JType.
This function doesn't really have anything to do with the type oracle mediator.
Moving it gets rid of most code references to the TypeOracleMediator class.
This change is in preparation for some refactoring TypeOracleMediator and friends.
Review at http://gwt-code-reviews.appspot.com/1144801
git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@9337 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/dev/core/src/com/google/gwt/core/ext/typeinfo/JType.java b/dev/core/src/com/google/gwt/core/ext/typeinfo/JType.java
index 368d785..dd92a7c 100644
--- a/dev/core/src/com/google/gwt/core/ext/typeinfo/JType.java
+++ b/dev/core/src/com/google/gwt/core/ext/typeinfo/JType.java
@@ -44,10 +44,15 @@
}
/**
- * TODO(scottb): remove if we can resolve param names differently.
+ * A binary type name as specified by the
+ * <a href="http://java.sun.com/docs/books/jls/second_edition/html/binaryComp.doc.html">
+ * Java Language Spec, Edition 2</a>.
*/
public abstract String getQualifiedBinaryName();
+ /**
+ * A type name as it would be specified in Java source.
+ */
public abstract String getQualifiedSourceName();
public abstract String getSimpleSourceName();
diff --git a/dev/core/src/com/google/gwt/dev/javac/TypeOracleMediator.java b/dev/core/src/com/google/gwt/dev/javac/TypeOracleMediator.java
index de54903..68ebdd7 100644
--- a/dev/core/src/com/google/gwt/dev/javac/TypeOracleMediator.java
+++ b/dev/core/src/com/google/gwt/dev/javac/TypeOracleMediator.java
@@ -91,47 +91,6 @@
*/
private static final boolean TRACE_CLASSES = false;
- /**
- * Returns the binary name of a type. This is the same name that would be
- * returned by {@link Class#getName()} for this type.
- *
- * @param type TypeOracle type to get the name for
- * @return binary name for a type
- */
- public static String computeBinaryClassName(JType type) {
- JPrimitiveType primitiveType = type.isPrimitive();
- if (primitiveType != null) {
- return primitiveType.getJNISignature();
- }
-
- JArrayType arrayType = type.isArray();
- if (arrayType != null) {
- JType component = arrayType.getComponentType();
- if (component.isClassOrInterface() != null) {
- return "[L" + computeBinaryClassName(arrayType.getComponentType())
- + ";";
- } else {
- return "[" + computeBinaryClassName(arrayType.getComponentType());
- }
- }
-
- JParameterizedType parameterizedType = type.isParameterized();
- if (parameterizedType != null) {
- return computeBinaryClassName(parameterizedType.getBaseType());
- }
-
- JClassType classType = type.isClassOrInterface();
- assert (classType != null);
-
- JClassType enclosingType = classType.getEnclosingType();
- if (enclosingType != null) {
- return computeBinaryClassName(enclosingType) + "$"
- + classType.getSimpleSourceName();
- }
-
- return classType.getQualifiedSourceName();
- }
-
private static JTypeParameter[] collectTypeParams(String signature) {
if (signature != null) {
List<JTypeParameter> params = new ArrayList<JTypeParameter>();
diff --git a/dev/core/src/com/google/gwt/dev/javac/asm/ResolveTypeSignature.java b/dev/core/src/com/google/gwt/dev/javac/asm/ResolveTypeSignature.java
index 049590e..57aa8a7 100644
--- a/dev/core/src/com/google/gwt/dev/javac/asm/ResolveTypeSignature.java
+++ b/dev/core/src/com/google/gwt/dev/javac/asm/ResolveTypeSignature.java
@@ -24,8 +24,8 @@
import com.google.gwt.core.ext.typeinfo.JType;
import com.google.gwt.core.ext.typeinfo.JTypeParameter;
import com.google.gwt.core.ext.typeinfo.JWildcardType;
-import com.google.gwt.core.ext.typeinfo.NotFoundException;
import com.google.gwt.core.ext.typeinfo.JWildcardType.BoundType;
+import com.google.gwt.core.ext.typeinfo.NotFoundException;
import com.google.gwt.dev.asm.signature.SignatureVisitor;
import com.google.gwt.dev.javac.Resolver;
import com.google.gwt.dev.javac.TypeParameterLookup;
diff --git a/user/src/com/google/gwt/rpc/rebind/RpcProxyCreator.java b/user/src/com/google/gwt/rpc/rebind/RpcProxyCreator.java
index c9d1062..644501d 100644
--- a/user/src/com/google/gwt/rpc/rebind/RpcProxyCreator.java
+++ b/user/src/com/google/gwt/rpc/rebind/RpcProxyCreator.java
@@ -30,7 +30,6 @@
import com.google.gwt.core.ext.typeinfo.JPrimitiveType;
import com.google.gwt.core.ext.typeinfo.JType;
import com.google.gwt.core.ext.typeinfo.TypeOracle;
-import com.google.gwt.dev.javac.TypeOracleMediator;
import com.google.gwt.dev.util.collect.Lists;
import com.google.gwt.rpc.client.impl.CommandToStringWriter;
import com.google.gwt.rpc.client.impl.RpcServiceProxy;
@@ -71,7 +70,7 @@
if (paramType.isClass() != null) {
return "GWT.isScript() ? Impl.getNameOf(\"@"
+ paramType.getQualifiedSourceName() + "\") : \""
- + TypeOracleMediator.computeBinaryClassName(paramType) + "\"";
+ + SerializationUtils.getRpcTypeName(paramType) + "\"";
} else {
/*
* Consider the case of service methods that have interface parameters;
@@ -79,7 +78,7 @@
* encode these type names in a way that can always be distinguished from
* obfuscated type names.
*/
- return "\" " + TypeOracleMediator.computeBinaryClassName(paramType)
+ return "\" " + SerializationUtils.getRpcTypeName(paramType)
+ "\"";
}
}
@@ -292,7 +291,7 @@
names = Lists.add(names, serializableFields[i].getName());
}
- data.setFields(TypeOracleMediator.computeBinaryClassName(type), names);
+ data.setFields(SerializationUtils.getRpcTypeName(type), names);
}
ctx.commitArtifact(logger, data);
diff --git a/user/src/com/google/gwt/user/rebind/rpc/FieldSerializerCreator.java b/user/src/com/google/gwt/user/rebind/rpc/FieldSerializerCreator.java
index b25a8ca..dab6529 100644
--- a/user/src/com/google/gwt/user/rebind/rpc/FieldSerializerCreator.java
+++ b/user/src/com/google/gwt/user/rebind/rpc/FieldSerializerCreator.java
@@ -29,7 +29,6 @@
import com.google.gwt.core.ext.typeinfo.JType;
import com.google.gwt.core.ext.typeinfo.JTypeParameter;
import com.google.gwt.core.ext.typeinfo.TypeOracle;
-import com.google.gwt.dev.javac.TypeOracleMediator;
import com.google.gwt.user.client.rpc.SerializationException;
import com.google.gwt.user.client.rpc.SerializationStreamReader;
import com.google.gwt.user.client.rpc.SerializationStreamWriter;
@@ -603,7 +602,7 @@
sourceWriter.println("}");
sourceWriter.println();
} else {
- String jsniTypeRef = TypeOracleMediator.computeBinaryClassName(serializableClass);
+ String jsniTypeRef = SerializationUtils.getRpcTypeName(serializableClass);
sourceWriter.println("public static native Class<?> concreteType() /*-{");
sourceWriter.indentln("return @" + jsniTypeRef + "::class;");
sourceWriter.println("}-*/;");
@@ -681,7 +680,7 @@
sourceWriter.indent();
sourceWriter.print("return instance.@");
- sourceWriter.print(TypeOracleMediator.computeBinaryClassName(serializableClass));
+ sourceWriter.print(SerializationUtils.getRpcTypeName(serializableClass));
sourceWriter.print("::");
sourceWriter.print(fieldName);
sourceWriter.println(";");
@@ -712,7 +711,7 @@
sourceWriter.indent();
sourceWriter.print("instance.@");
- sourceWriter.print(TypeOracleMediator.computeBinaryClassName(serializableClass));
+ sourceWriter.print(SerializationUtils.getRpcTypeName(serializableClass));
sourceWriter.print("::");
sourceWriter.print(fieldName);
sourceWriter.println(" = value;");
diff --git a/user/src/com/google/gwt/user/rebind/rpc/ProxyCreator.java b/user/src/com/google/gwt/user/rebind/rpc/ProxyCreator.java
index 6e5ac08..5cde3d4 100644
--- a/user/src/com/google/gwt/user/rebind/rpc/ProxyCreator.java
+++ b/user/src/com/google/gwt/user/rebind/rpc/ProxyCreator.java
@@ -36,7 +36,6 @@
import com.google.gwt.core.ext.typeinfo.NotFoundException;
import com.google.gwt.core.ext.typeinfo.TypeOracle;
import com.google.gwt.dev.generator.NameFactory;
-import com.google.gwt.dev.javac.TypeOracleMediator;
import com.google.gwt.dev.util.Util;
import com.google.gwt.http.client.Request;
import com.google.gwt.http.client.RequestBuilder;
@@ -338,7 +337,7 @@
String remoteServiceInterfaceName = elideTypeNames
? TypeNameObfuscator.SERVICE_INTERFACE_ID
- : TypeOracleMediator.computeBinaryClassName(serviceIntf);
+ : SerializationUtils.getRpcTypeName(serviceIntf);
generateProxyFields(srcWriter, typesSentFromBrowser,
serializationPolicyStrongName, remoteServiceInterfaceName);
@@ -385,7 +384,7 @@
if (typeStrings.containsKey(paramType)) {
typeName = typeStrings.get(paramType);
} else {
- typeName = TypeOracleMediator.computeBinaryClassName(paramType);
+ typeName = SerializationUtils.getRpcTypeName(paramType);
}
return typeName == null ? null : ('"' + typeName + '"');
}
@@ -738,7 +737,7 @@
for (int i = 0; i < serializableTypes.length; ++i) {
JType type = serializableTypes[i];
- String binaryTypeName = TypeOracleMediator.computeBinaryClassName(type);
+ String binaryTypeName = SerializationUtils.getRpcTypeName(type);
pw.print(binaryTypeName);
pw.print(", "
+ Boolean.toString(deserializationSto.isSerializable(type)));
diff --git a/user/src/com/google/gwt/user/rebind/rpc/SerializationUtils.java b/user/src/com/google/gwt/user/rebind/rpc/SerializationUtils.java
index c8e05ba..5eb5779 100644
--- a/user/src/com/google/gwt/user/rebind/rpc/SerializationUtils.java
+++ b/user/src/com/google/gwt/user/rebind/rpc/SerializationUtils.java
@@ -20,9 +20,9 @@
import com.google.gwt.core.ext.typeinfo.JClassType;
import com.google.gwt.core.ext.typeinfo.JField;
import com.google.gwt.core.ext.typeinfo.JParameterizedType;
+import com.google.gwt.core.ext.typeinfo.JPrimitiveType;
import com.google.gwt.core.ext.typeinfo.JType;
import com.google.gwt.core.ext.typeinfo.TypeOracle;
-import com.google.gwt.dev.javac.TypeOracleMediator;
import com.google.gwt.dev.util.Util;
import java.io.UnsupportedEncodingException;
@@ -69,6 +69,47 @@
}
/**
+ * Returns the binary name of a type. This is the same name that would be
+ * returned by {@link Class#getName()} for this type.
+ *
+ * @param type TypeOracle type to get the name for
+ * @return binary name for a type
+ */
+ public static String getRpcTypeName(JType type) {
+ JPrimitiveType primitiveType = type.isPrimitive();
+ if (primitiveType != null) {
+ return primitiveType.getJNISignature();
+ }
+
+ JArrayType arrayType = type.isArray();
+ if (arrayType != null) {
+ JType component = arrayType.getComponentType();
+ if (component.isClassOrInterface() != null) {
+ return "[L" + getRpcTypeName(arrayType.getComponentType())
+ + ";";
+ } else {
+ return "[" + getRpcTypeName(arrayType.getComponentType());
+ }
+ }
+
+ JParameterizedType parameterizedType = type.isParameterized();
+ if (parameterizedType != null) {
+ return getRpcTypeName(parameterizedType.getBaseType());
+ }
+
+ JClassType classType = type.isClassOrInterface();
+ assert (classType != null);
+
+ JClassType enclosingType = classType.getEnclosingType();
+ if (enclosingType != null) {
+ return getRpcTypeName(enclosingType) + "$"
+ + classType.getSimpleSourceName();
+ }
+
+ return classType.getQualifiedSourceName();
+ }
+
+ /**
* Returns the set of fields that are serializable for a given class type.
* This method does not consider any superclass fields.
*
@@ -218,7 +259,7 @@
return;
}
- String serializedTypeName = TypeOracleMediator.computeBinaryClassName(type);
+ String serializedTypeName = getRpcTypeName(type);
crc.update(serializedTypeName.getBytes(Util.DEFAULT_ENCODING));
if (excludeImplementationFromSerializationSignature(type)) {
@@ -240,7 +281,7 @@
assert (field != null);
crc.update(field.getName().getBytes(Util.DEFAULT_ENCODING));
- crc.update(TypeOracleMediator.computeBinaryClassName(field.getType()).getBytes(
+ crc.update(getRpcTypeName(field.getType()).getBytes(
Util.DEFAULT_ENCODING));
}
@@ -250,5 +291,4 @@
}
}
}
-
}
diff --git a/user/src/com/google/gwt/user/rebind/rpc/TypeSerializerCreator.java b/user/src/com/google/gwt/user/rebind/rpc/TypeSerializerCreator.java
index ef8f3ff..f391d2c 100644
--- a/user/src/com/google/gwt/user/rebind/rpc/TypeSerializerCreator.java
+++ b/user/src/com/google/gwt/user/rebind/rpc/TypeSerializerCreator.java
@@ -28,7 +28,6 @@
import com.google.gwt.core.ext.typeinfo.JParameterizedType;
import com.google.gwt.core.ext.typeinfo.JType;
import com.google.gwt.core.ext.typeinfo.TypeOracle;
-import com.google.gwt.dev.javac.TypeOracleMediator;
import com.google.gwt.user.client.rpc.SerializationStreamReader;
import com.google.gwt.user.client.rpc.SerializationStreamWriter;
import com.google.gwt.user.client.rpc.impl.SerializerBase;
@@ -287,7 +286,7 @@
* @return
*/
private String getTypeString(JType type) {
- String typeString = TypeOracleMediator.computeBinaryClassName(type) + "/"
+ String typeString = SerializationUtils.getRpcTypeName(type) + "/"
+ SerializationUtils.getSerializationSignature(typeOracle, type);
return typeString;
}
@@ -522,7 +521,7 @@
}
String jsniTypeRef;
- jsniTypeRef = TypeOracleMediator.computeBinaryClassName(type.getLeafType());
+ jsniTypeRef = SerializationUtils.getRpcTypeName(type.getLeafType());
while (type.isArray() != null) {
jsniTypeRef += "[]";
type = type.isArray().getComponentType();