Revision: 10183
Author: sco...@google.com
Date: Fri May 13 08:44:36 2011
Log: Decentralize nullmethod/nullfield.
http://gwt-code-reviews.appspot.com/1442802/
Review by: jbrosenb...@google.com
http://code.google.com/p/google-web-toolkit/source/detail?r=10183
Modified:
/trunk/dev/core/src/com/google/gwt/dev/jjs/ast/JField.java
/trunk/dev/core/src/com/google/gwt/dev/jjs/ast/JMethod.java
/trunk/dev/core/src/com/google/gwt/dev/jjs/ast/JProgram.java
/trunk/dev/core/src/com/google/gwt/dev/jjs/ast/js/JsniClassLiteral.java
/trunk/dev/core/src/com/google/gwt/dev/jjs/ast/js/JsniFieldRef.java
/trunk/dev/core/src/com/google/gwt/dev/jjs/ast/js/JsniMethodRef.java
/trunk/dev/core/src/com/google/gwt/dev/jjs/impl/GwtAstBuilder.java
/trunk/dev/core/src/com/google/gwt/dev/jjs/impl/ImplementClassLiteralsAsFields.java
=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/jjs/ast/JField.java Tue Apr 19
10:10:18 2011
+++ /trunk/dev/core/src/com/google/gwt/dev/jjs/ast/JField.java Fri May 13
08:44:36 2011
@@ -67,6 +67,17 @@
}
}
+ private static class ExternalSerializedNullField implements Serializable
{
+ public static final ExternalSerializedNullField INSTANCE = new
ExternalSerializedNullField();
+
+ private Object readResolve() {
+ return NULL_FIELD;
+ }
+ }
+
+ public static final JField NULL_FIELD = new
JField(SourceOrigin.UNKNOWN, "nullField", null,
+ JNullType.INSTANCE, false, Disposition.FINAL);
+
private final JDeclaredType enclosingType;
private final boolean isCompileTimeConstant;
private final boolean isStatic;
@@ -153,6 +164,8 @@
protected Object writeReplace() {
if (enclosingType != null && enclosingType.isExternal()) {
return new ExternalSerializedForm(this);
+ } else if (this == NULL_FIELD) {
+ return ExternalSerializedNullField.INSTANCE;
} else {
return this;
}
=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/jjs/ast/JMethod.java Thu May 5
06:03:58 2011
+++ /trunk/dev/core/src/com/google/gwt/dev/jjs/ast/JMethod.java Fri May 13
08:44:36 2011
@@ -55,8 +55,24 @@
}
}
+ private static class ExternalSerializedNullMethod implements
Serializable {
+ public static final ExternalSerializedNullMethod INSTANCE = new
ExternalSerializedNullMethod();
+
+ private Object readResolve() {
+ return NULL_METHOD;
+ }
+ }
+
+ public static final JMethod NULL_METHOD = new
JMethod(SourceOrigin.UNKNOWN, "nullMethod", null,
+ JNullType.INSTANCE, false, false, true, false);
+
private static final String TRACE_METHOD_WILDCARD = "*";
+ static {
+ NULL_METHOD.setSynthetic();
+ NULL_METHOD.freezeParamTypes();
+ }
+
private static void trace(String title, String code) {
System.out.println("---------------------------");
System.out.println(title + ":");
@@ -352,6 +368,8 @@
protected Object writeReplace() {
if (enclosingType != null && enclosingType.isExternal()) {
return new ExternalSerializedForm(this);
+ } else if (this == NULL_METHOD) {
+ return ExternalSerializedNullMethod.INSTANCE;
} else {
return this;
}
=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/jjs/ast/JProgram.java Tue May 10
05:59:20 2011
+++ /trunk/dev/core/src/com/google/gwt/dev/jjs/ast/JProgram.java Fri May 13
08:44:36 2011
@@ -335,10 +335,6 @@
private final Map<JMethod, JMethod> instanceToStaticMap = new
IdentityHashMap<JMethod, JMethod>();
- private JField nullField;
-
- private JMethod nullMethod;
-
private Map<JReferenceType, Integer> queryIds;
/**
@@ -855,22 +851,11 @@
}
public JField getNullField() {
- if (nullField == null) {
- nullField =
- new
JField(createSourceInfoSynthetic(JProgram.class), "nullField", null,
- JNullType.INSTANCE, false, Disposition.FINAL);
- }
- return nullField;
+ return JField.NULL_FIELD;
}
public JMethod getNullMethod() {
- if (nullMethod == null) {
- nullMethod =
- new
JMethod(createSourceInfoSynthetic(JProgram.class), "nullMethod", null,
- JNullType.INSTANCE, false, false, true, false);
- nullMethod.setSynthetic();
- }
- return nullMethod;
+ return JMethod.NULL_METHOD;
}
public int getQueryId(JReferenceType elementType) {
=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/jjs/ast/js/JsniClassLiteral.java
Tue May 10 05:59:20 2011
+++ /trunk/dev/core/src/com/google/gwt/dev/jjs/ast/js/JsniClassLiteral.java
Fri May 13 08:44:36 2011
@@ -28,6 +28,7 @@
public JsniClassLiteral(SourceInfo info, String ident, JType type) {
super(info, type);
+ assert ident != null;
this.ident = ident;
}
=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/jjs/ast/js/JsniFieldRef.java Tue
Apr 19 10:10:18 2011
+++ /trunk/dev/core/src/com/google/gwt/dev/jjs/ast/js/JsniFieldRef.java Fri
May 13 08:44:36 2011
@@ -34,6 +34,7 @@
public JsniFieldRef(SourceInfo info, String ident, JField field,
JDeclaredType enclosingType,
boolean isLvalue) {
super(info, field.isStatic() ? null : JNullLiteral.INSTANCE, field,
enclosingType);
+ assert ident != null;
this.ident = ident;
this.isLvalue = isLvalue;
}
=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/jjs/ast/js/JsniMethodRef.java
Tue Apr 19 10:10:18 2011
+++ /trunk/dev/core/src/com/google/gwt/dev/jjs/ast/js/JsniMethodRef.java
Fri May 13 08:44:36 2011
@@ -35,6 +35,7 @@
public JsniMethodRef(SourceInfo info, String ident, JMethod method,
JClassType jsoType) {
// Just use a null literal as the qualifier on a non-static method
super(info, method.isStatic() ? null : JNullLiteral.INSTANCE, method);
+ assert ident != null;
this.ident = ident;
this.jsoType = jsoType;
}
=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/jjs/impl/GwtAstBuilder.java Thu
May 12 10:09:08 2011
+++ /trunk/dev/core/src/com/google/gwt/dev/jjs/impl/GwtAstBuilder.java Fri
May 13 08:44:36 2011
@@ -249,6 +249,12 @@
SourceInfo info = x.getSourceInfo();
if (binding == null) {
assert ident.startsWith("@null::");
+ if ("@null::nullMethod()".equals(ident)) {
+ processMethod(x, info, JMethod.NULL_METHOD);
+ } else {
+ assert "@null::nullField".equals(ident);
+ processField(x, info, JField.NULL_FIELD, ctx);
+ }
} else if (binding instanceof TypeBinding) {
JType type = typeMap.get((TypeBinding) binding);
processClassLiteral(x, info, type, ctx);
=======================================
---
/trunk/dev/core/src/com/google/gwt/dev/jjs/impl/ImplementClassLiteralsAsFields.java
Wed Apr 20 08:47:17 2011
+++
/trunk/dev/core/src/com/google/gwt/dev/jjs/impl/ImplementClassLiteralsAsFields.java
Fri May 13 08:44:36 2011
@@ -76,6 +76,19 @@
new ImplementClassLiteralsAsFields(program).execImpl();
normalizerEvent.end();
}
+
+ private static String createIdent(JMethod method) {
+ StringBuilder sb = new StringBuilder();
+ sb.append(method.getEnclosingType().getName());
+ sb.append("::");
+ sb.append(method.getName());
+ sb.append('(');
+ for (JType type : method.getOriginalParamTypes()) {
+ sb.append(type.getJsniSignatureName());
+ }
+ sb.append(')');
+ return sb.toString();
+ }
private static String getClassName(String fullName) {
int pos = fullName.lastIndexOf(".");
@@ -223,8 +236,10 @@
if (valueOfMethod == null) {
throw new InternalCompilerException("Could not find enum
valueOf() method");
}
- call.addArg(new JsniMethodRef(info, null, valuesMethod,
program.getJavaScriptObject()));
- call.addArg(new JsniMethodRef(info, null, valueOfMethod,
program.getJavaScriptObject()));
+ call.addArg(new JsniMethodRef(info, createIdent(valuesMethod),
valuesMethod, program
+ .getJavaScriptObject()));
+ call.addArg(new JsniMethodRef(info, createIdent(valueOfMethod),
valueOfMethod, program
+ .getJavaScriptObject()));
} else if (isEnumOrSubclass) {
// A subclass of an enum class
call.addArg(JNullLiteral.INSTANCE);
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors