Revision: 10645
Author: rj...@google.com
Date: Tue Sep 13 11:23:09 2011
Log: Makes the @GwtTransient mechanism work for any annotation with
that
simple name.
Review at http://gwt-code-reviews.appspot.com/1544803
Review by: cromwell...@google.com
http://code.google.com/p/google-web-toolkit/source/detail?r=10645
Added:
/trunk/user/test/com/google/gwt/user/rebind/rpc/GwtTransient.java
Modified:
/trunk/user/src/com/google/gwt/user/client/rpc/GwtTransient.java
/trunk/user/src/com/google/gwt/user/rebind/rpc/SerializableTypeOracleBuilder.java
/trunk/user/src/com/google/gwt/user/server/rpc/impl/SerializabilityUtil.java
/trunk/user/test/com/google/gwt/user/rebind/rpc/SerializableTypeOracleBuilderTest.java
===
--- /dev/null
+++ /trunk/user/test/com/google/gwt/user/rebind/rpc/GwtTransient.java Tue
Sep 13 11:23:09 2011
@@ -0,0 +1,24 @@
+/*
+ * Copyright 2011 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the License); you may
not
+ * use this file except in compliance with the License. You may obtain a
copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
under
+ * the License.
+ */
+package com.google.gwt.user.rebind.rpc;
+
+/**
+ * Used to test that any annotation named @GwtTransient gets the job done.
Need
+ * to define both a real class (TypeOracleMediator uses reflection) and a
Java
+ * source resource (for TypeOracle itself).
+ */
+public @interface GwtTransient {
+}
===
--- /trunk/user/src/com/google/gwt/user/client/rpc/GwtTransient.java Mon
May 18 11:47:32 2009
+++ /trunk/user/src/com/google/gwt/user/client/rpc/GwtTransient.java Tue
Sep 13 11:23:09 2011
@@ -27,6 +27,10 @@
* codetransient/code keyword should be used in preference to this
* annotation. However, for types used with multiple serialization
systems, it
* can be useful.
+ * p
+ * Note that GWT will actually accept any annotation named GwtTransient
for this
+ * purpose. This is done to allow libraries to support GWT serialization
without
+ * creating a direct dependency on the GWT distribution.
*/
@Documented
@Retention(RetentionPolicy.RUNTIME)
===
---
/trunk/user/src/com/google/gwt/user/rebind/rpc/SerializableTypeOracleBuilder.java
Thu Aug 4 06:02:26 2011
+++
/trunk/user/src/com/google/gwt/user/rebind/rpc/SerializableTypeOracleBuilder.java
Tue Sep 13 11:23:09 2011
@@ -451,6 +451,15 @@
return (JRealClassType) type;
}
+
+ static boolean hasGwtTransientAnnotation(JField field) {
+for (Annotation a : field.getAnnotations()) {
+ if
(a.annotationType().getSimpleName().equals(GwtTransient.class.getSimpleName()))
{
+return true;
+ }
+}
+return false;
+ }
/**
* @param type the type to query
@@ -607,7 +616,7 @@
return false;
}
-if (field.isAnnotationPresent(GwtTransient.class)) {
+if (hasGwtTransientAnnotation(field)) {
return false;
}
===
---
/trunk/user/src/com/google/gwt/user/server/rpc/impl/SerializabilityUtil.java
Fri Aug 26 07:32:45 2011
+++
/trunk/user/src/com/google/gwt/user/server/rpc/impl/SerializabilityUtil.java
Tue Sep 13 11:23:09 2011
@@ -25,6 +25,7 @@
import com.google.gwt.user.server.rpc.ServerCustomFieldSerializer;
import java.io.UnsupportedEncodingException;
+import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.GenericArrayType;
import java.lang.reflect.Modifier;
@@ -462,6 +463,18 @@
public static void resolveTypes(Type methodType,
DequeMapTypeVariable?, Type resolvedTypes) {
SerializabilityUtil.resolveTypesWorker(methodType, resolvedTypes,
true);
}
+
+ /**
+ * Returns true if this field has an annotation named GwtTransient.
+ */
+ static boolean hasGwtTransientAnnotation(Field field) {
+for (Annotation a : field.getAnnotations()) {
+ if
(a.annotationType().getSimpleName().equals(GwtTransient.class.getSimpleName()))
{
+return true;
+ }
+}
+return false;
+ }
static boolean isNotStaticTransientOrFinal(Field field) {
/*
@@ -470,7 +483,7 @@
*/
int fieldModifiers = field.getModifiers();
return !Modifier.isStatic(fieldModifiers)
!Modifier.isTransient(fieldModifiers)
- !field.isAnnotationPresent(GwtTransient.class)
!Modifier.isFinal(fieldModifiers);
+ !hasGwtTransientAnnotation(field)
!Modifier.isFinal(fieldModifiers);
}
/**
===
---