tilgalas commented on code in PR #32977:
URL: https://github.com/apache/beam/pull/32977#discussion_r2318772789
##########
sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/utils/AutoValueUtils.java:
##########
@@ -70,45 +72,71 @@
/** Utilities for managing AutoValue schemas. */
@SuppressWarnings({"rawtypes"})
public class AutoValueUtils {
+
+ private static final String AUTO_VALUE_GENERATED_PREFIX = "AutoValue_";
+
+ /**
+ * Walk the class hierarchy upwards and find the topmost {@link
TypeDescriptor} whose super class
+ * is not generated (whose class name doesn't contain the {@code AutoValue_}
prefix).
+ */
+ private static TypeDescriptor<?>
findFirstGeneratedAutoValue(TypeDescriptor<?> typeDescriptor) {
+ Class<?> rawType = typeDescriptor.getRawType();
+ for (Class superClass = rawType.getSuperclass();
+ superClass != null &&
superClass.getName().contains(AUTO_VALUE_GENERATED_PREFIX);
+ superClass = superClass.getSuperclass()) {
+ rawType = superClass;
+ }
+ return typeDescriptor.getSupertype((Class) rawType);
+ }
+
+ @SuppressWarnings("unchecked")
public static @Nullable TypeDescriptor<?> getBaseAutoValueClass(
TypeDescriptor<?> typeDescriptor) {
- // AutoValue extensions may be nested
- @Nullable TypeDescriptor<?> baseTypeDescriptor = typeDescriptor;
- while (baseTypeDescriptor != null
- && baseTypeDescriptor.getRawType().getName().contains("AutoValue_")) {
- baseTypeDescriptor =
- Optional.ofNullable(baseTypeDescriptor.getRawType().getSuperclass())
- .map(TypeDescriptor::of)
- .orElse(null);
+ if
(!typeDescriptor.getRawType().getName().contains(AUTO_VALUE_GENERATED_PREFIX)) {
+ // fast path for types which aren't autogenerated
+ return typeDescriptor;
}
- return baseTypeDescriptor;
+ // AutoValue extensions may be nested
+ TypeDescriptor<?> firstGeneratedTypeDescriptor =
findFirstGeneratedAutoValue(typeDescriptor);
+ return
Optional.ofNullable(firstGeneratedTypeDescriptor.getRawType().getSuperclass())
+ .map(superClass -> firstGeneratedTypeDescriptor.getSupertype((Class)
superClass))
Review Comment:
so the `findFirstGeneratedAutoValue` will return the topmost class which is
still generated, the `getBaseAutoValueClass` is supposed to return the
non-generated base class which is the superclass of that
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]