Search in sources :

Example 26 with CodeBlock

use of com.squareup.javapoet.CodeBlock in project auto by google.

the class ImmutableMapSerializerExtensionTest method toProxy.

@Test
public void toProxy() {
    TypeMirror typeMirror = declaredTypeOf(ImmutableMap.class, Integer.class, String.class);
    Serializer serializer = extension.getSerializer(typeMirror, fakeSerializerFactory, mockProcessingEnvironment).get();
    CodeBlock actualCodeBlock = serializer.toProxy(CodeBlock.of("x"));
    assertThat(actualCodeBlock.toString()).isEqualTo(String.format("x.entrySet().stream().collect(%s.toImmutableMap(value$ -> %s.<%s," + " %s>wrapper(element$ -> element$).apply(value$.getKey()), value$ -> %s.<%s," + " %s>wrapper(element$ -> element$).apply(value$.getValue())))", IMMUTABLE_MAP, FUNCTION_WITH_EXCEPTIONS, INTEGER, INTEGER, FUNCTION_WITH_EXCEPTIONS, STRING, STRING));
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror) CodeBlock(com.squareup.javapoet.CodeBlock) Serializer(com.google.auto.value.extension.serializable.serializer.interfaces.Serializer) Test(org.junit.Test) CompilationAbstractTest(com.google.auto.value.extension.serializable.serializer.utils.CompilationAbstractTest)

Example 27 with CodeBlock

use of com.squareup.javapoet.CodeBlock in project auto by google.

the class IdentitySerializerFactoryTest method fromProxy_isUnchanged.

@Test
public void fromProxy_isUnchanged() throws Exception {
    TypeMirror typeMirror = typeMirrorOf(String.class);
    CodeBlock inputExpression = CodeBlock.of("x");
    CodeBlock outputExpression = IdentitySerializerFactory.getSerializer(typeMirror).fromProxy(inputExpression);
    assertThat(outputExpression).isSameInstanceAs(inputExpression);
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror) CodeBlock(com.squareup.javapoet.CodeBlock) CompilationAbstractTest(com.google.auto.value.extension.serializable.serializer.utils.CompilationAbstractTest) Test(org.junit.Test)

Example 28 with CodeBlock

use of com.squareup.javapoet.CodeBlock in project auto by google.

the class IdentitySerializerFactoryTest method toProxy_isUnchanged.

@Test
public void toProxy_isUnchanged() throws Exception {
    TypeMirror typeMirror = typeMirrorOf(String.class);
    CodeBlock inputExpression = CodeBlock.of("x");
    CodeBlock outputExpression = IdentitySerializerFactory.getSerializer(typeMirror).toProxy(inputExpression);
    assertThat(outputExpression).isSameInstanceAs(inputExpression);
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror) CodeBlock(com.squareup.javapoet.CodeBlock) CompilationAbstractTest(com.google.auto.value.extension.serializable.serializer.utils.CompilationAbstractTest) Test(org.junit.Test)

Example 29 with CodeBlock

use of com.squareup.javapoet.CodeBlock in project auto by google.

the class ImmutableMapSerializerExtensionTest method fromProxy.

@Test
public void fromProxy() {
    TypeMirror typeMirror = declaredTypeOf(ImmutableMap.class, Integer.class, String.class);
    Serializer serializer = extension.getSerializer(typeMirror, fakeSerializerFactory, mockProcessingEnvironment).get();
    CodeBlock actualCodeBlock = serializer.fromProxy(CodeBlock.of("x"));
    assertThat(actualCodeBlock.toString()).isEqualTo(String.format("x.entrySet().stream().collect(%s.toImmutableMap(value$ -> %s.<%s," + " %s>wrapper(element$ -> element$).apply(value$.getKey()), value$ -> %s.<%s," + " %s>wrapper(element$ -> element$).apply(value$.getValue())))", IMMUTABLE_MAP, FUNCTION_WITH_EXCEPTIONS, INTEGER, INTEGER, FUNCTION_WITH_EXCEPTIONS, STRING, STRING));
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror) CodeBlock(com.squareup.javapoet.CodeBlock) Serializer(com.google.auto.value.extension.serializable.serializer.interfaces.Serializer) Test(org.junit.Test) CompilationAbstractTest(com.google.auto.value.extension.serializable.serializer.utils.CompilationAbstractTest)

Example 30 with CodeBlock

use of com.squareup.javapoet.CodeBlock in project auto by google.

the class OptionalSerializerExtensionTest method fromProxy.

@Test
public void fromProxy() {
    TypeMirror typeMirror = declaredTypeOf(Optional.class, Integer.class);
    Serializer serializer = extension.getSerializer(typeMirror, fakeSerializerFactory, mockProcessingEnvironment).get();
    CodeBlock actualCodeBlock = serializer.fromProxy(CodeBlock.of("x"));
    assertThat(actualCodeBlock.toString()).isEqualTo("java.util.Optional.ofNullable(x == null ? null : x)");
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror) CodeBlock(com.squareup.javapoet.CodeBlock) Serializer(com.google.auto.value.extension.serializable.serializer.interfaces.Serializer) CompilationAbstractTest(com.google.auto.value.extension.serializable.serializer.utils.CompilationAbstractTest) Test(org.junit.Test)

Aggregations

CodeBlock (com.squareup.javapoet.CodeBlock)42 MethodSpec (com.squareup.javapoet.MethodSpec)19 TypeMirror (javax.lang.model.type.TypeMirror)13 ParameterizedTypeName (com.squareup.javapoet.ParameterizedTypeName)11 TypeName (com.squareup.javapoet.TypeName)10 CompilationAbstractTest (com.google.auto.value.extension.serializable.serializer.utils.CompilationAbstractTest)8 ClassName (com.squareup.javapoet.ClassName)8 WireField (com.squareup.wire.WireField)8 Field (com.squareup.wire.schema.Field)8 ByteString (okio.ByteString)8 Test (org.junit.Test)8 JvmLanguages.builtInAdapterString (com.squareup.wire.schema.internal.JvmLanguages.builtInAdapterString)7 ArrayList (java.util.ArrayList)7 Serializer (com.google.auto.value.extension.serializable.serializer.interfaces.Serializer)6 ParameterSpec (com.squareup.javapoet.ParameterSpec)6 AnnotationSpec (com.squareup.javapoet.AnnotationSpec)4 TypeSpec (com.squareup.javapoet.TypeSpec)3 Element (javax.lang.model.element.Element)3 Predicate (com.google.common.base.Predicate)2 FieldSpec (com.squareup.javapoet.FieldSpec)2