Skip to content

Commit 5533fca

Browse files
authored
Migrate from AnnotationValue#toString to auto-common's AnnotationValues.toString. (#2891)
This change will cause the string representation to use qualified names e.g. @com.google.Foo(value = com.google.Bar.BAZ). The latest versions of javac no longer use qualified names in the implementation of AnnotationValue#toString, so you get something like @foo(value = Bar.BAZ). This change is important primarily for code that uses the toString() representation in generated source code, since simple names may fail to compile unless additional imports are added. It is still worth considering for code that uses the string representation in diagnostics or assertion messages, since it makes it clearer which type is being referred to.
1 parent ba7e1dd commit 5533fca

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

encoders/firebase-encoders-processor/firebase-encoders-processor.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ dependencies {
2525
implementation 'com.squareup:javapoet:1.13.0'
2626
compileOnly 'javax.annotation:javax.annotation-api:1.3.2'
2727
implementation 'com.google.guava:guava:28.1-jre'
28-
28+
implementation 'com.google.auto:auto-common:1.1.2'
2929
implementation "com.google.auto.value:auto-value-annotations:1.6.6"
3030

3131
annotationProcessor "com.google.auto.value:auto-value:1.6.5"

encoders/firebase-encoders-processor/src/main/java/com/google/firebase/encoders/processor/EncodableProcessor.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package com.google.firebase.encoders.processor;
1616

1717
import androidx.annotation.VisibleForTesting;
18+
import com.google.auto.common.AnnotationValues;
1819
import com.google.auto.service.AutoService;
1920
import com.google.auto.value.AutoValue;
2021
import com.google.common.collect.ArrayListMultimap;
@@ -290,7 +291,8 @@ public VisitResult<Encoder> visit(TypeMirror type) {
290291
ClassName.get((TypeElement) desc.type().getAnnotationType().asElement()));
291292
codeBuilder.add(".withProperty($T.builder()\n", annotationBuilder);
292293
for (AnnotationProperty property : desc.properties()) {
293-
codeBuilder.add("$>.$L($L)\n$<", property.name(), property.value());
294+
codeBuilder.add(
295+
"$>.$L($L)\n$<", property.name(), AnnotationValues.toString(property.value()));
294296
}
295297
codeBuilder.add("$>.build())\n$<");
296298
}

0 commit comments

Comments
 (0)