Skip to content

Commit c3a155d

Browse files
cpovirkGoogle Java Core Libraries
authored and
Google Java Core Libraries
committedMay 26, 2023
Remove Enums from guava-gwt at compile time.
Previously, parts of it were present but failed at runtime when used under J2CL. And soon, J2CL may drop support for the reflective enum-related APIs that it depends on. `guava-gwt` is used by both GWT and J2CL users, so we have to keep our code buildable against both. If this CL causes trouble for you as a GWT user, let us know, and we can investigate options further. In the worst case, you can copy the implementations as needed, since the class contains only static methods. RELNOTES=`collect`: Removed `Enums` from `guava-gwt` to prepare for the removal of reflective enum-related APIs from J2CL. If this causes you problems as a GWT user, let us know. PiperOrigin-RevId: 535585561
1 parent feb83a1 commit c3a155d

File tree

5 files changed

+20
-18
lines changed

5 files changed

+20
-18
lines changed
 

‎android/guava-tests/test/com/google/common/base/EnumsTest.java

+7-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import static com.google.common.base.StandardSystemProperty.PATH_SEPARATOR;
2121
import static com.google.common.truth.Truth.assertThat;
2222

23-
import com.google.common.annotations.GwtCompatible;
2423
import com.google.common.annotations.GwtIncompatible;
2524
import com.google.common.annotations.J2ktIncompatible;
2625
import com.google.common.collect.ImmutableList;
@@ -45,7 +44,7 @@
4544
*
4645
* @author Steve McKay
4746
*/
48-
@GwtCompatible(emulated = true)
47+
@GwtIncompatible
4948
@J2ktIncompatible
5049
public class EnumsTest extends TestCase {
5150

@@ -117,6 +116,7 @@ private WeakReference<?> doTestClassUnloading() throws Exception {
117116
return new WeakReference<>(shadowLoader);
118117
}
119118

119+
@GwtIncompatible // stringConverter
120120
public void testStringConverter_convert() {
121121
Converter<String, TestEnum> converter = Enums.stringConverter(TestEnum.class);
122122
assertEquals(TestEnum.CHEETO, converter.convert("CHEETO"));
@@ -126,6 +126,7 @@ public void testStringConverter_convert() {
126126
assertNull(converter.reverse().convert(null));
127127
}
128128

129+
@GwtIncompatible // stringConverter
129130
public void testStringConverter_convertError() {
130131
Converter<String, TestEnum> converter = Enums.stringConverter(TestEnum.class);
131132
try {
@@ -135,6 +136,7 @@ public void testStringConverter_convertError() {
135136
}
136137
}
137138

139+
@GwtIncompatible // stringConverter
138140
public void testStringConverter_reverse() {
139141
Converter<String, TestEnum> converter = Enums.stringConverter(TestEnum.class);
140142
assertEquals("CHEETO", converter.reverse().convert(TestEnum.CHEETO));
@@ -143,13 +145,14 @@ public void testStringConverter_reverse() {
143145
}
144146

145147
@J2ktIncompatible
146-
@GwtIncompatible // NullPointerTester
148+
@GwtIncompatible // stringConverter
147149
public void testStringConverter_nullPointerTester() throws Exception {
148150
Converter<String, TestEnum> converter = Enums.stringConverter(TestEnum.class);
149151
NullPointerTester tester = new NullPointerTester();
150152
tester.testAllPublicInstanceMethods(converter);
151153
}
152154

155+
@GwtIncompatible // stringConverter
153156
public void testStringConverter_nullConversions() {
154157
Converter<String, TestEnum> converter = Enums.stringConverter(TestEnum.class);
155158
assertNull(converter.convert(null));
@@ -164,6 +167,7 @@ public void testStringConverter_toString() {
164167
Enums.stringConverter(TestEnum.class).toString());
165168
}
166169

170+
@GwtIncompatible // stringConverter
167171
public void testStringConverter_serialization() {
168172
SerializableTester.reserializeAndAssert(Enums.stringConverter(TestEnum.class));
169173
}

‎android/guava/src/com/google/common/base/Enums.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
import static com.google.common.base.Preconditions.checkNotNull;
1818

19-
import com.google.common.annotations.GwtCompatible;
2019
import com.google.common.annotations.GwtIncompatible;
2120
import com.google.common.annotations.J2ktIncompatible;
2221
import java.io.Serializable;
@@ -34,7 +33,7 @@
3433
* @author Steve McKay
3534
* @since 9.0
3635
*/
37-
@GwtCompatible(emulated = true)
36+
@GwtIncompatible
3837
@J2ktIncompatible
3938
@ElementTypesAreNonnullByDefault
4039
public final class Enums {
@@ -108,10 +107,12 @@ static <T extends Enum<T>> Map<String, WeakReference<? extends Enum<?>>> getEnum
108107
*
109108
* @since 16.0
110109
*/
110+
@GwtIncompatible
111111
public static <T extends Enum<T>> Converter<String, T> stringConverter(Class<T> enumClass) {
112112
return new StringConverter<>(enumClass);
113113
}
114114

115+
@GwtIncompatible
115116
private static final class StringConverter<T extends Enum<T>> extends Converter<String, T>
116117
implements Serializable {
117118

‎guava-gwt/src-super/com/google/common/base/super/com/google/common/base/Platform.java

-8
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,6 @@ static CharMatcher precomputeCharMatcher(CharMatcher matcher) {
3232
return matcher;
3333
}
3434

35-
static <T extends Enum<T>> Optional<T> getEnumIfPresent(Class<T> enumClass, String value) {
36-
try {
37-
return Optional.of(Enum.valueOf(enumClass, value));
38-
} catch (IllegalArgumentException iae) {
39-
return Optional.absent();
40-
}
41-
}
42-
4335
static String formatCompact4Digits(double value) {
4436
return "" + ((Number) (Object) value).toPrecision(4);
4537
}

‎guava-tests/test/com/google/common/base/EnumsTest.java

+7-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import static com.google.common.base.StandardSystemProperty.PATH_SEPARATOR;
2121
import static com.google.common.truth.Truth.assertThat;
2222

23-
import com.google.common.annotations.GwtCompatible;
2423
import com.google.common.annotations.GwtIncompatible;
2524
import com.google.common.annotations.J2ktIncompatible;
2625
import com.google.common.collect.ImmutableList;
@@ -45,7 +44,7 @@
4544
*
4645
* @author Steve McKay
4746
*/
48-
@GwtCompatible(emulated = true)
47+
@GwtIncompatible
4948
@J2ktIncompatible
5049
public class EnumsTest extends TestCase {
5150

@@ -117,6 +116,7 @@ private WeakReference<?> doTestClassUnloading() throws Exception {
117116
return new WeakReference<>(shadowLoader);
118117
}
119118

119+
@GwtIncompatible // stringConverter
120120
public void testStringConverter_convert() {
121121
Converter<String, TestEnum> converter = Enums.stringConverter(TestEnum.class);
122122
assertEquals(TestEnum.CHEETO, converter.convert("CHEETO"));
@@ -126,6 +126,7 @@ public void testStringConverter_convert() {
126126
assertNull(converter.reverse().convert(null));
127127
}
128128

129+
@GwtIncompatible // stringConverter
129130
public void testStringConverter_convertError() {
130131
Converter<String, TestEnum> converter = Enums.stringConverter(TestEnum.class);
131132
try {
@@ -135,6 +136,7 @@ public void testStringConverter_convertError() {
135136
}
136137
}
137138

139+
@GwtIncompatible // stringConverter
138140
public void testStringConverter_reverse() {
139141
Converter<String, TestEnum> converter = Enums.stringConverter(TestEnum.class);
140142
assertEquals("CHEETO", converter.reverse().convert(TestEnum.CHEETO));
@@ -143,13 +145,14 @@ public void testStringConverter_reverse() {
143145
}
144146

145147
@J2ktIncompatible
146-
@GwtIncompatible // NullPointerTester
148+
@GwtIncompatible // stringConverter
147149
public void testStringConverter_nullPointerTester() throws Exception {
148150
Converter<String, TestEnum> converter = Enums.stringConverter(TestEnum.class);
149151
NullPointerTester tester = new NullPointerTester();
150152
tester.testAllPublicInstanceMethods(converter);
151153
}
152154

155+
@GwtIncompatible // stringConverter
153156
public void testStringConverter_nullConversions() {
154157
Converter<String, TestEnum> converter = Enums.stringConverter(TestEnum.class);
155158
assertNull(converter.convert(null));
@@ -164,6 +167,7 @@ public void testStringConverter_toString() {
164167
Enums.stringConverter(TestEnum.class).toString());
165168
}
166169

170+
@GwtIncompatible // stringConverter
167171
public void testStringConverter_serialization() {
168172
SerializableTester.reserializeAndAssert(Enums.stringConverter(TestEnum.class));
169173
}

‎guava/src/com/google/common/base/Enums.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
import static com.google.common.base.Preconditions.checkNotNull;
1818

19-
import com.google.common.annotations.GwtCompatible;
2019
import com.google.common.annotations.GwtIncompatible;
2120
import com.google.common.annotations.J2ktIncompatible;
2221
import java.io.Serializable;
@@ -34,7 +33,7 @@
3433
* @author Steve McKay
3534
* @since 9.0
3635
*/
37-
@GwtCompatible(emulated = true)
36+
@GwtIncompatible
3837
@J2ktIncompatible
3938
@ElementTypesAreNonnullByDefault
4039
public final class Enums {
@@ -108,10 +107,12 @@ static <T extends Enum<T>> Map<String, WeakReference<? extends Enum<?>>> getEnum
108107
*
109108
* @since 16.0
110109
*/
110+
@GwtIncompatible
111111
public static <T extends Enum<T>> Converter<String, T> stringConverter(Class<T> enumClass) {
112112
return new StringConverter<>(enumClass);
113113
}
114114

115+
@GwtIncompatible
115116
private static final class StringConverter<T extends Enum<T>> extends Converter<String, T>
116117
implements Serializable {
117118

0 commit comments

Comments
 (0)
Please sign in to comment.