Adds helpers to Serializable for J2CL. Change-Id: I6931a2ef62e8e7c0939bb7da3f31f1655fb5067f
diff --git a/dev/core/test/com/google/gwt/dev/CompilerTest.java b/dev/core/test/com/google/gwt/dev/CompilerTest.java index 2883ded..88fce34 100644 --- a/dev/core/test/com/google/gwt/dev/CompilerTest.java +++ b/dev/core/test/com/google/gwt/dev/CompilerTest.java
@@ -2746,6 +2746,8 @@ // always traversed fully and polute the tests, so they will be removed from stale type // comparisons. staleTypeNames.removeAll(Arrays.asList( + "java.io.HasSerializableTypeMarker", + "java.io.Serializable", "java.lang.Boolean", "java.lang.CharSequence", "java.lang.Comparable",
diff --git a/user/super/com/google/gwt/emul/java/io/HasSerializableTypeMarker.java b/user/super/com/google/gwt/emul/java/io/HasSerializableTypeMarker.java new file mode 100644 index 0000000..9de7ab1 --- /dev/null +++ b/user/super/com/google/gwt/emul/java/io/HasSerializableTypeMarker.java
@@ -0,0 +1,26 @@ +/* + * Copyright 2018 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 java.io; + +import jsinterop.annotations.JsPackage; +import jsinterop.annotations.JsProperty; +import jsinterop.annotations.JsType; + +@JsType(isNative = true, name = "*", namespace = JsPackage.GLOBAL) +interface HasSerializableTypeMarker { + @JsProperty(name = "$implements__java_io_Serializable") + boolean getTypeMarker(); +}
diff --git a/user/super/com/google/gwt/emul/java/io/Serializable.java b/user/super/com/google/gwt/emul/java/io/Serializable.java index 72e5f30..f47aa5d 100644 --- a/user/super/com/google/gwt/emul/java/io/Serializable.java +++ b/user/super/com/google/gwt/emul/java/io/Serializable.java
@@ -1,12 +1,12 @@ /* * Copyright 2007 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 @@ -15,10 +15,28 @@ */ package java.io; +import javaemul.internal.JsUtils; +import jsinterop.annotations.JsMethod; + /** * Provided for interoperability; RPC treats this interface synonymously with * {@link com.google.gwt.user.client.rpc.IsSerializable IsSerializable}. * The Java serialization protocol is explicitly not supported. */ public interface Serializable { + // CHECKSTYLE_OFF: Utility methods. + @JsMethod + static boolean $isInstance(HasSerializableTypeMarker instance) { + if (instance == null) { + return false; + } + + String type = JsUtils.typeOf(instance); + return type.equals("boolean") + || type.equals("number") + || type.equals("string") + || instance.getTypeMarker() + || instance.getClass().isArray(); + } + // CHECKSTYLE_ON: end utility methods }