Skip to content

Commit 6a2216c

Browse files
authored
Add missing interfaces to emulated classes (#10245)
Some missing interfaces found when working on #10208 Out of scope here: * adding default implementations to `RandomGenerator` (#10214) * adding `Serializable` to any classes * implementing methods in `Constable` / `ConstantDesc` -- only use those as tagging interfaces for now * adding `Readable` interface as it depends on `nio` * adding `Cloneable` to `Locale` * adding any new interfaces to `java.lang.reflect` or `java.lang.invoke` implemented by `Class`
1 parent 7096a3f commit 6a2216c

22 files changed

Lines changed: 250 additions & 73 deletions

user/super/com/google/gwt/emul/java/io/PrintStream.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
* See <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/io/PrintStream.html">the official Java
2020
* API doc</a> for details.
2121
*/
22-
public class PrintStream extends FilterOutputStream {
22+
public class PrintStream extends FilterOutputStream implements Appendable {
2323

2424
/** Indicates whether or not this PrintStream has incurred an error. */
2525
private boolean ioError = false;
@@ -195,4 +195,22 @@ protected void clearError() {
195195
private void newline() {
196196
print('\n');
197197
}
198+
199+
@Override
200+
public Appendable append(CharSequence csq) {
201+
print(csq);
202+
return this;
203+
}
204+
205+
@Override
206+
public Appendable append(CharSequence csq, int start, int end) {
207+
print(csq.subSequence(start, end));
208+
return this;
209+
}
210+
211+
@Override
212+
public Appendable append(char c) {
213+
print(c);
214+
return this;
215+
}
198216
}

user/super/com/google/gwt/emul/java/io/Reader.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
/**
1919
* Reads a stream of characters.
2020
*/
21-
public abstract class Reader {
21+
public abstract class Reader implements Closeable {
2222
/**
2323
* The maximum buffer size to incrementally read in {@link #skip}.
2424
*/
@@ -27,6 +27,7 @@ public abstract class Reader {
2727
/**
2828
* Closes the reader, and releases any associated resources.
2929
*/
30+
@Override
3031
public abstract void close() throws IOException;
3132

3233
/**

user/super/com/google/gwt/emul/java/lang/Boolean.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,14 @@
1818
import static javaemul.internal.InternalPreconditions.checkNotNull;
1919

2020
import java.io.Serializable;
21+
import java.lang.constant.Constable;
2122
import javaemul.internal.JsUtils;
2223
import jsinterop.annotations.JsMethod;
2324

2425
/**
2526
* Wraps native <code>boolean</code> as an object.
2627
*/
27-
public final class Boolean implements Comparable<Boolean>, Serializable {
28+
public final class Boolean implements Comparable<Boolean>, Serializable, Constable {
2829

2930
public static final Boolean FALSE = false;
3031
public static final Boolean TRUE = true;

user/super/com/google/gwt/emul/java/lang/Byte.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@
1515
*/
1616
package java.lang;
1717

18+
import java.lang.constant.Constable;
19+
1820
/**
1921
* Wraps native <code>byte</code> as an object.
2022
*/
21-
public final class Byte extends Number implements Comparable<Byte> {
23+
public final class Byte extends Number implements Comparable<Byte>, Constable {
2224

2325
public static final byte MIN_VALUE = (byte) 0x80;
2426
public static final byte MAX_VALUE = (byte) 0x7F;

user/super/com/google/gwt/emul/java/lang/Class.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import com.google.gwt.core.client.JavaScriptObject;
1919

20+
import java.lang.constant.Constable;
2021
import java.lang.reflect.Type;
2122
import javaemul.internal.annotations.DoNotInline;
2223

@@ -29,7 +30,7 @@
2930
*
3031
* @param <T> the type of the object
3132
*/
32-
public final class Class<T> implements Type {
33+
public final class Class<T> implements Type, Constable {
3334

3435
private static final int PRIMITIVE = 0x00000001;
3536
private static final int INTERFACE = 0x00000002;

user/super/com/google/gwt/emul/java/lang/Enum.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import com.google.gwt.core.client.JavaScriptObject;
2222

2323
import java.io.Serializable;
24+
import java.lang.constant.Constable;
2425
import jsinterop.annotations.JsIgnore;
2526
import jsinterop.annotations.JsNonNull;
2627
import jsinterop.annotations.JsType;
@@ -31,7 +32,7 @@
3132
* @param <E>
3233
*/
3334
@JsType
34-
public abstract class Enum<E extends Enum<E>> implements Comparable<E>, Serializable {
35+
public abstract class Enum<E extends Enum<E>> implements Comparable<E>, Serializable, Constable {
3536

3637
@JsIgnore
3738
public static <T extends Enum<T>> T valueOf(Class<T> enumType, String name) {

user/super/com/google/gwt/emul/java/lang/Float.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@
1515
*/
1616
package java.lang;
1717

18+
import java.lang.constant.Constable;
19+
import java.lang.constant.ConstantDesc;
1820
import javaemul.internal.JsUtils;
1921

2022
/**
2123
* Wraps a primitive <code>float</code> as an object.
2224
*/
23-
public final class Float extends Number implements Comparable<Float> {
25+
public final class Float extends Number implements Comparable<Float>, Constable, ConstantDesc {
2426
public static final float MAX_VALUE = 3.4028235e+38f;
2527
public static final float MIN_VALUE = 1.4e-45f;
2628
public static final int MAX_EXPONENT = 127;

user/super/com/google/gwt/emul/java/lang/Integer.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@
1515
*/
1616
package java.lang;
1717

18+
import java.lang.constant.Constable;
19+
import java.lang.constant.ConstantDesc;
1820
import javaemul.internal.JsUtils;
1921
import javaemul.internal.annotations.HasNoSideEffects;
2022

2123
/**
2224
* Wraps a primitive <code>int</code> as an object.
2325
*/
24-
public final class Integer extends Number implements Comparable<Integer> {
26+
public final class Integer extends Number implements Comparable<Integer>, Constable, ConstantDesc {
2527

2628
public static final int MAX_VALUE = 0x7fffffff;
2729
public static final int MIN_VALUE = 0x80000000;

user/super/com/google/gwt/emul/java/lang/Long.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@
1515
*/
1616
package java.lang;
1717

18+
import java.lang.constant.Constable;
19+
import java.lang.constant.ConstantDesc;
1820
import javaemul.internal.LongUtils;
1921
import javaemul.internal.annotations.HasNoSideEffects;
2022

2123
/** Wraps a primitive <code>long</code> as an object. */
22-
public final class Long extends Number implements Comparable<Long> {
24+
public final class Long extends Number implements Comparable<Long>, Constable, ConstantDesc {
2325

2426
/** Use nested class to avoid clinit on outer. */
2527
static class BoxedValues {

user/super/com/google/gwt/emul/java/lang/String.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424

2525
import java.io.Serializable;
2626
import java.io.UnsupportedEncodingException;
27+
import java.lang.constant.Constable;
28+
import java.lang.constant.ConstantDesc;
2729
import java.nio.charset.Charset;
2830
import java.nio.charset.UnsupportedCharsetException;
2931
import java.util.Comparator;
@@ -55,7 +57,7 @@
5557
// Needed to have constructors not fail compilation internally at Google
5658
@SuppressWarnings({ "ReturnValueIgnored", "unusable-by-js" })
5759
public final class String implements Comparable<String>, CharSequence,
58-
Serializable {
60+
Serializable, Constable, ConstantDesc {
5961
/* TODO(jat): consider whether we want to support the following methods;
6062
*
6163
* <ul>

0 commit comments

Comments
 (0)