1616
1717package dagger .internal .codegen .binding ;
1818
19- import static androidx .room .compiler .codegen .XTypeNameKt .toJavaPoet ;
2019import static androidx .room .compiler .processing .XTypeKt .isArray ;
2120import static dagger .internal .codegen .binding .SourceFiles .classFileName ;
2221import static dagger .internal .codegen .extension .DaggerStreams .toImmutableList ;
23- import static dagger .internal .codegen .javapoet .CodeBlocks .makeParametersCodeBlock ;
24- import static dagger .internal .codegen .javapoet .CodeBlocks .toParametersCodeBlock ;
2522import static dagger .internal .codegen .xprocessing .XAnnotationValues .characterLiteralWithSingleQuotes ;
23+ import static dagger .internal .codegen .xprocessing .XCodeBlocks .makeParametersCodeBlock ;
24+ import static dagger .internal .codegen .xprocessing .XCodeBlocks .toParametersCodeBlock ;
2625import static dagger .internal .codegen .xprocessing .XElements .getSimpleName ;
2726import static dagger .internal .codegen .xprocessing .XTypes .asArray ;
2827import static dagger .internal .codegen .xprocessing .XTypes .isTypeOf ;
2928
3029import androidx .room .compiler .codegen .XClassName ;
30+ import androidx .room .compiler .codegen .XCodeBlock ;
3131import androidx .room .compiler .processing .XAnnotation ;
3232import androidx .room .compiler .processing .XAnnotationValue ;
3333import androidx .room .compiler .processing .XType ;
3434import androidx .room .compiler .processing .XTypeElement ;
35- import com .squareup .javapoet .CodeBlock ;
3635import dagger .internal .codegen .xprocessing .XTypeNames ;
3736
3837/**
@@ -59,14 +58,14 @@ public final class AnnotationExpression {
5958 * Returns an expression that calls static methods on the annotation's creator class to create an
6059 * annotation instance equivalent the annotation passed to the constructor.
6160 */
62- CodeBlock getAnnotationInstanceExpression () {
61+ XCodeBlock getAnnotationInstanceExpression () {
6362 return getAnnotationInstanceExpression (annotation );
6463 }
6564
66- private CodeBlock getAnnotationInstanceExpression (XAnnotation annotation ) {
67- return CodeBlock .of (
68- "$T.$L($ L)" ,
69- toJavaPoet ( creatorClass ) ,
65+ private XCodeBlock getAnnotationInstanceExpression (XAnnotation annotation ) {
66+ return XCodeBlock .of (
67+ "%T.%L(% L)" ,
68+ creatorClass ,
7069 createMethodName (annotation .getType ().getTypeElement ()),
7170 makeParametersCodeBlock (
7271 annotation .getAnnotationValues ().stream ()
@@ -93,45 +92,43 @@ public static String createMethodName(XTypeElement annotationType) {
9392 * Returns an expression that evaluates to a {@code value} of a given type on an {@code
9493 * annotation}.
9594 */
96- CodeBlock getValueExpression (XAnnotationValue value ) {
95+ XCodeBlock getValueExpression (XAnnotationValue value ) {
9796 if (isArray (value .getValueType ())) {
9897 XType componentType = asArray (value .getValueType ()).getComponentType ();
99- return CodeBlock .of (
100- "new $ T[] {$ L}" ,
98+ return XCodeBlock .of (
99+ "new % T[] {% L}" ,
101100 // TODO(b/264464791): The KClass -> Class swap can be removed once this bug is fixed.
102- toJavaPoet (
103- isTypeOf (componentType , XTypeNames .KCLASS )
104- ? XTypeNames .CLASS
105- : componentType .getRawType ().asTypeName ()),
101+ isTypeOf (componentType , XTypeNames .KCLASS )
102+ ? XTypeNames .CLASS
103+ : componentType .getRawType ().asTypeName (),
106104 value .asAnnotationValueList ().stream ()
107105 .map (this ::getValueExpression )
108106 .collect (toParametersCodeBlock ()));
109107 } else if (value .hasEnumValue ()) {
110- return CodeBlock .of (
111- "$T.$L" ,
112- value .asEnum ().getEnclosingElement ().getClassName (),
113- getSimpleName (value .asEnum ()));
108+ return XCodeBlock .of (
109+ "%T.%L" ,
110+ value .asEnum ().getEnclosingElement ().asClassName (), getSimpleName (value .asEnum ()));
114111 } else if (value .hasAnnotationValue ()) {
115112 return getAnnotationInstanceExpression (value .asAnnotation ());
116113 } else if (value .hasTypeValue ()) {
117- return CodeBlock .of ("$ T.class" , value .asType ().getTypeElement ().getClassName ());
114+ return XCodeBlock .of ("% T.class" , value .asType ().getTypeElement ().asClassName ());
118115 } else if (value .hasStringValue ()) {
119- return CodeBlock .of ("$ S" , value .asString ());
116+ return XCodeBlock .of ("% S" , value .asString ());
120117 } else if (value .hasByteValue ()) {
121- return CodeBlock .of ("(byte) $ L" , value .asByte ());
118+ return XCodeBlock .of ("(byte) % L" , value .asByte ());
122119 } else if (value .hasCharValue ()) {
123120 // TODO(bcorso): Replace when https://github.com/square/javapoet/issues/698 is fixed.
124- return CodeBlock .of ("$ L" , characterLiteralWithSingleQuotes (value .asChar ()));
121+ return XCodeBlock .of ("% L" , characterLiteralWithSingleQuotes (value .asChar ()));
125122 } else if (value .hasDoubleValue ()) {
126- return CodeBlock .of ("$ LD" , value .asDouble ());
123+ return XCodeBlock .of ("% LD" , value .asDouble ());
127124 } else if (value .hasFloatValue ()) {
128- return CodeBlock .of ("$ LF" , value .asFloat ());
125+ return XCodeBlock .of ("% LF" , value .asFloat ());
129126 } else if (value .hasLongValue ()) {
130- return CodeBlock .of ("$ LL" , value .asLong ());
127+ return XCodeBlock .of ("% LL" , value .asLong ());
131128 } else if (value .hasShortValue ()) {
132- return CodeBlock .of ("(short) $ L" , value .asShort ());
129+ return XCodeBlock .of ("(short) % L" , value .asShort ());
133130 } else {
134- return CodeBlock .of ("$ L" , value .getValue ());
131+ return XCodeBlock .of ("% L" , value .getValue ());
135132 }
136133 }
137134}
0 commit comments