Allow @AutoCodec field annotation even when field's type is private.
Also clean up some warnings.
PiperOrigin-RevId: 233468538
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec/AutoCodecProcessor.java b/src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec/AutoCodecProcessor.java
index b50681d..cb27015 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec/AutoCodecProcessor.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec/AutoCodecProcessor.java
@@ -156,7 +156,7 @@
.addSuperinterface(RegisteredSingletonDoNotUse.class)
.addField(
FieldSpec.builder(
- TypeName.get(symbol.asType()),
+ Object.class,
CodecScanningConstants.REGISTERED_SINGLETON_INSTANCE_VAR_NAME,
Modifier.PUBLIC,
Modifier.STATIC,
@@ -323,7 +323,7 @@
if (method.getModifiers().contains(Modifier.STATIC)
&& !method.getModifiers().contains(Modifier.ABSTRACT)
&& method.getParameters().isEmpty()
- && method.getReturnType().equals(builderType.asType())) {
+ && isSameReturnType(method, builderType)) {
if (builderMethod != null) {
throw new IllegalArgumentException(
"Type "
@@ -353,7 +353,7 @@
continue;
}
if (method.getParameters().isEmpty()
- && method.getReturnType().equals(encodedType.asType())
+ && isSameReturnType(method, encodedType)
&& method.getModifiers().contains(Modifier.ABSTRACT)) {
if (abstractBuildMethod != null) {
throw new IllegalArgumentException(
@@ -422,7 +422,7 @@
if (!method.getModifiers().contains(Modifier.STATIC)
&& !method.getModifiers().contains(Modifier.PRIVATE)
&& setterNames.contains(method.getSimpleName().toString())
- && method.getReturnType().equals(builderType.asType())
+ && isSameReturnType(method, builderType)
&& method.getParameters().size() == 1
&& env.getTypeUtils()
.isSubtype(type, Iterables.getOnlyElement(method.getParameters()).asType())) {
@@ -760,11 +760,8 @@
return Optional.empty();
}
- /** True when {@code type} has the same type as {@code clazz}. */
- private boolean matchesType(TypeMirror type, Class<?> clazz) {
- return env.getTypeUtils()
- .isSameType(
- type, env.getElementUtils().getTypeElement((clazz.getCanonicalName())).asType());
+ private boolean isSameReturnType(ExecutableElement method, TypeElement typeElement) {
+ return env.getTypeUtils().isSameType(method.getReturnType(), typeElement.asType());
}
/** Emits a note to BUILD log during annotation processing for debugging. */