mirror of
https://github.com/fankes/moshi.git
synced 2025-10-19 16:09:21 +08:00
Move the Kotlin code generator to the kotlin/ module
This commit is contained in:
@@ -10,7 +10,7 @@
|
|||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>moshi-kotlin-codegen-compiler</artifactId>
|
<artifactId>moshi-kotlin-codegen</artifactId>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
@@ -13,7 +13,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package com.squareup.moshi
|
package com.squareup.moshi.kotlin.codegen
|
||||||
|
|
||||||
import com.squareup.kotlinpoet.ARRAY
|
import com.squareup.kotlinpoet.ARRAY
|
||||||
import com.squareup.kotlinpoet.AnnotationSpec
|
import com.squareup.kotlinpoet.AnnotationSpec
|
||||||
@@ -30,6 +30,11 @@ import com.squareup.kotlinpoet.TypeSpec
|
|||||||
import com.squareup.kotlinpoet.TypeVariableName
|
import com.squareup.kotlinpoet.TypeVariableName
|
||||||
import com.squareup.kotlinpoet.asClassName
|
import com.squareup.kotlinpoet.asClassName
|
||||||
import com.squareup.kotlinpoet.asTypeName
|
import com.squareup.kotlinpoet.asTypeName
|
||||||
|
import com.squareup.moshi.JsonAdapter
|
||||||
|
import com.squareup.moshi.JsonDataException
|
||||||
|
import com.squareup.moshi.JsonReader
|
||||||
|
import com.squareup.moshi.JsonWriter
|
||||||
|
import com.squareup.moshi.Moshi
|
||||||
import me.eugeniomarletti.kotlin.metadata.isDataClass
|
import me.eugeniomarletti.kotlin.metadata.isDataClass
|
||||||
import me.eugeniomarletti.kotlin.metadata.shadow.metadata.ProtoBuf.Visibility
|
import me.eugeniomarletti.kotlin.metadata.shadow.metadata.ProtoBuf.Visibility
|
||||||
import me.eugeniomarletti.kotlin.metadata.visibility
|
import me.eugeniomarletti.kotlin.metadata.visibility
|
||||||
@@ -101,7 +106,7 @@ internal class AdapterGenerator(
|
|||||||
|
|
||||||
generatedOption?.let {
|
generatedOption?.let {
|
||||||
result.addAnnotation(AnnotationSpec.builder(it.asClassName())
|
result.addAnnotation(AnnotationSpec.builder(it.asClassName())
|
||||||
.addMember("%S", JsonClassCodeGenProcessor::class.java.canonicalName)
|
.addMember("%S", JsonClassCodegenProcessor::class.java.canonicalName)
|
||||||
.addMember("%S", "https://github.com/square/moshi")
|
.addMember("%S", "https://github.com/square/moshi")
|
||||||
.build())
|
.build())
|
||||||
}
|
}
|
@@ -13,7 +13,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package com.squareup.moshi
|
package com.squareup.moshi.kotlin.codegen
|
||||||
|
|
||||||
import com.squareup.kotlinpoet.TypeName
|
import com.squareup.kotlinpoet.TypeName
|
||||||
import com.squareup.kotlinpoet.TypeVariableName
|
import com.squareup.kotlinpoet.TypeVariableName
|
@@ -13,7 +13,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package com.squareup.moshi
|
package com.squareup.moshi.kotlin.codegen
|
||||||
|
|
||||||
import com.google.auto.common.MoreTypes
|
import com.google.auto.common.MoreTypes
|
||||||
import com.squareup.kotlinpoet.AnnotationSpec
|
import com.squareup.kotlinpoet.AnnotationSpec
|
||||||
@@ -29,6 +29,8 @@ import com.squareup.kotlinpoet.TypeName
|
|||||||
import com.squareup.kotlinpoet.TypeVariableName
|
import com.squareup.kotlinpoet.TypeVariableName
|
||||||
import com.squareup.kotlinpoet.WildcardTypeName
|
import com.squareup.kotlinpoet.WildcardTypeName
|
||||||
import com.squareup.kotlinpoet.asTypeName
|
import com.squareup.kotlinpoet.asTypeName
|
||||||
|
import com.squareup.moshi.JsonAdapter
|
||||||
|
import com.squareup.moshi.Types
|
||||||
import java.lang.annotation.ElementType
|
import java.lang.annotation.ElementType
|
||||||
import java.lang.annotation.RetentionPolicy
|
import java.lang.annotation.RetentionPolicy
|
||||||
import javax.annotation.processing.Messager
|
import javax.annotation.processing.Messager
|
@@ -13,10 +13,11 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package com.squareup.moshi
|
package com.squareup.moshi.kotlin.codegen
|
||||||
|
|
||||||
import com.google.auto.service.AutoService
|
import com.google.auto.service.AutoService
|
||||||
import com.squareup.kotlinpoet.TypeSpec
|
import com.squareup.kotlinpoet.TypeSpec
|
||||||
|
import com.squareup.moshi.JsonClass
|
||||||
import me.eugeniomarletti.kotlin.metadata.KotlinMetadataUtils
|
import me.eugeniomarletti.kotlin.metadata.KotlinMetadataUtils
|
||||||
import me.eugeniomarletti.kotlin.metadata.declaresDefaultValue
|
import me.eugeniomarletti.kotlin.metadata.declaresDefaultValue
|
||||||
import me.eugeniomarletti.kotlin.processing.KotlinAbstractProcessor
|
import me.eugeniomarletti.kotlin.processing.KotlinAbstractProcessor
|
||||||
@@ -41,7 +42,7 @@ import javax.tools.Diagnostic.Kind.ERROR
|
|||||||
* If you don't want this though, you can use the runtime [JsonClass] factory implementation.
|
* If you don't want this though, you can use the runtime [JsonClass] factory implementation.
|
||||||
*/
|
*/
|
||||||
@AutoService(Processor::class)
|
@AutoService(Processor::class)
|
||||||
class JsonClassCodeGenProcessor : KotlinAbstractProcessor(), KotlinMetadataUtils {
|
class JsonClassCodegenProcessor : KotlinAbstractProcessor(), KotlinMetadataUtils {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
/**
|
/**
|
@@ -13,7 +13,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package com.squareup.moshi
|
package com.squareup.moshi.kotlin.codegen
|
||||||
|
|
||||||
import com.squareup.kotlinpoet.BOOLEAN
|
import com.squareup.kotlinpoet.BOOLEAN
|
||||||
import com.squareup.kotlinpoet.NameAllocator
|
import com.squareup.kotlinpoet.NameAllocator
|
@@ -13,7 +13,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package com.squareup.moshi
|
package com.squareup.moshi.kotlin.codegen
|
||||||
|
|
||||||
import me.eugeniomarletti.kotlin.metadata.KotlinClassMetadata
|
import me.eugeniomarletti.kotlin.metadata.KotlinClassMetadata
|
||||||
import me.eugeniomarletti.kotlin.metadata.isPrimary
|
import me.eugeniomarletti.kotlin.metadata.isPrimary
|
@@ -13,7 +13,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package com.squareup.moshi
|
package com.squareup.moshi.kotlin.codegen
|
||||||
|
|
||||||
import me.eugeniomarletti.kotlin.metadata.shadow.metadata.ProtoBuf.ValueParameter
|
import me.eugeniomarletti.kotlin.metadata.shadow.metadata.ProtoBuf.ValueParameter
|
||||||
import javax.lang.model.element.VariableElement
|
import javax.lang.model.element.VariableElement
|
@@ -13,10 +13,12 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package com.squareup.moshi
|
package com.squareup.moshi.kotlin.codegen
|
||||||
|
|
||||||
import com.google.auto.common.AnnotationMirrors
|
import com.google.auto.common.AnnotationMirrors
|
||||||
import com.squareup.kotlinpoet.TypeName
|
import com.squareup.kotlinpoet.TypeName
|
||||||
|
import com.squareup.moshi.Json
|
||||||
|
import com.squareup.moshi.JsonQualifier
|
||||||
import me.eugeniomarletti.kotlin.metadata.declaresDefaultValue
|
import me.eugeniomarletti.kotlin.metadata.declaresDefaultValue
|
||||||
import me.eugeniomarletti.kotlin.metadata.hasSetter
|
import me.eugeniomarletti.kotlin.metadata.hasSetter
|
||||||
import me.eugeniomarletti.kotlin.metadata.shadow.metadata.ProtoBuf.Property
|
import me.eugeniomarletti.kotlin.metadata.shadow.metadata.ProtoBuf.Property
|
@@ -13,7 +13,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package com.squareup.moshi
|
package com.squareup.moshi.kotlin.codegen
|
||||||
|
|
||||||
import com.squareup.kotlinpoet.ClassName
|
import com.squareup.kotlinpoet.ClassName
|
||||||
import com.squareup.kotlinpoet.KModifier
|
import com.squareup.kotlinpoet.KModifier
|
@@ -13,7 +13,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package com.squareup.moshi
|
package com.squareup.moshi.kotlin.codegen
|
||||||
|
|
||||||
import com.squareup.kotlinpoet.ARRAY
|
import com.squareup.kotlinpoet.ARRAY
|
||||||
import com.squareup.kotlinpoet.BOOLEAN
|
import com.squareup.kotlinpoet.BOOLEAN
|
||||||
@@ -31,6 +31,7 @@ import com.squareup.kotlinpoet.TypeName
|
|||||||
import com.squareup.kotlinpoet.TypeVariableName
|
import com.squareup.kotlinpoet.TypeVariableName
|
||||||
import com.squareup.kotlinpoet.WildcardTypeName
|
import com.squareup.kotlinpoet.WildcardTypeName
|
||||||
import com.squareup.kotlinpoet.asTypeName
|
import com.squareup.kotlinpoet.asTypeName
|
||||||
|
import com.squareup.moshi.Types
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Renders literals like `Types.newParameterizedType(List::class.java, String::class.java)`.
|
* Renders literals like `Types.newParameterizedType(List::class.java, String::class.java)`.
|
@@ -13,7 +13,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package com.squareup.moshi
|
package com.squareup.moshi.kotlin.codegen
|
||||||
|
|
||||||
import com.squareup.kotlinpoet.ClassName
|
import com.squareup.kotlinpoet.ClassName
|
||||||
import com.squareup.kotlinpoet.ParameterizedTypeName
|
import com.squareup.kotlinpoet.ParameterizedTypeName
|
@@ -13,7 +13,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package com.squareup.moshi
|
package com.squareup.moshi.kotlin.codegen
|
||||||
|
|
||||||
import com.squareup.kotlinpoet.ClassName
|
import com.squareup.kotlinpoet.ClassName
|
||||||
import com.squareup.kotlinpoet.ParameterizedTypeName
|
import com.squareup.kotlinpoet.ParameterizedTypeName
|
@@ -13,7 +13,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package com.squareup.moshi
|
package com.squareup.moshi.kotlin.codegen
|
||||||
|
|
||||||
import com.squareup.kotlinpoet.ANY
|
import com.squareup.kotlinpoet.ANY
|
||||||
import com.squareup.kotlinpoet.ClassName
|
import com.squareup.kotlinpoet.ClassName
|
@@ -13,9 +13,9 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package com.squareup.moshi;
|
package com.squareup.moshi.kotlin.codegen;
|
||||||
|
|
||||||
/** For {@link CompilerTest#extendJavaType}. */
|
/** For {@link JsonClassCodegenProcessorTest#extendJavaType}. */
|
||||||
public class JavaSuperclass {
|
public class JavaSuperclass {
|
||||||
public int a = 1;
|
public int a = 1;
|
||||||
}
|
}
|
@@ -13,7 +13,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package com.squareup.moshi
|
package com.squareup.moshi.kotlin.codegen
|
||||||
|
|
||||||
import org.assertj.core.api.Assertions.assertThat
|
import org.assertj.core.api.Assertions.assertThat
|
||||||
import org.jetbrains.kotlin.cli.common.ExitCode
|
import org.jetbrains.kotlin.cli.common.ExitCode
|
||||||
@@ -24,13 +24,13 @@ import org.junit.rules.TemporaryFolder
|
|||||||
import javax.annotation.processing.Processor
|
import javax.annotation.processing.Processor
|
||||||
|
|
||||||
/** Execute kotlinc to confirm that either files are generated or errors are printed. */
|
/** Execute kotlinc to confirm that either files are generated or errors are printed. */
|
||||||
class CompilerTest {
|
class JsonClassCodegenProcessorTest {
|
||||||
@Rule @JvmField var temporaryFolder: TemporaryFolder = TemporaryFolder()
|
@Rule @JvmField var temporaryFolder: TemporaryFolder = TemporaryFolder()
|
||||||
|
|
||||||
@Test fun privateConstructor() {
|
@Test fun privateConstructor() {
|
||||||
val call = KotlinCompilerCall(temporaryFolder.root)
|
val call = KotlinCompilerCall(temporaryFolder.root)
|
||||||
call.inheritClasspath = true
|
call.inheritClasspath = true
|
||||||
call.addService(Processor::class, JsonClassCodeGenProcessor::class)
|
call.addService(Processor::class, JsonClassCodegenProcessor::class)
|
||||||
call.addKt("source.kt", """
|
call.addKt("source.kt", """
|
||||||
|import com.squareup.moshi.JsonClass
|
|import com.squareup.moshi.JsonClass
|
||||||
|
|
|
|
||||||
@@ -52,7 +52,7 @@ class CompilerTest {
|
|||||||
@Test fun privateConstructorParameter() {
|
@Test fun privateConstructorParameter() {
|
||||||
val call = KotlinCompilerCall(temporaryFolder.root)
|
val call = KotlinCompilerCall(temporaryFolder.root)
|
||||||
call.inheritClasspath = true
|
call.inheritClasspath = true
|
||||||
call.addService(Processor::class, JsonClassCodeGenProcessor::class)
|
call.addService(Processor::class, JsonClassCodegenProcessor::class)
|
||||||
call.addKt("source.kt", """
|
call.addKt("source.kt", """
|
||||||
|import com.squareup.moshi.JsonClass
|
|import com.squareup.moshi.JsonClass
|
||||||
|
|
|
|
||||||
@@ -68,7 +68,7 @@ class CompilerTest {
|
|||||||
@Test fun privateProperties() {
|
@Test fun privateProperties() {
|
||||||
val call = KotlinCompilerCall(temporaryFolder.root)
|
val call = KotlinCompilerCall(temporaryFolder.root)
|
||||||
call.inheritClasspath = true
|
call.inheritClasspath = true
|
||||||
call.addService(Processor::class, JsonClassCodeGenProcessor::class)
|
call.addService(Processor::class, JsonClassCodegenProcessor::class)
|
||||||
call.addKt("source.kt", """
|
call.addKt("source.kt", """
|
||||||
|import com.squareup.moshi.JsonClass
|
|import com.squareup.moshi.JsonClass
|
||||||
|
|
|
|
||||||
@@ -87,7 +87,7 @@ class CompilerTest {
|
|||||||
@Test fun interfacesNotSupported() {
|
@Test fun interfacesNotSupported() {
|
||||||
val call = KotlinCompilerCall(temporaryFolder.root)
|
val call = KotlinCompilerCall(temporaryFolder.root)
|
||||||
call.inheritClasspath = true
|
call.inheritClasspath = true
|
||||||
call.addService(Processor::class, JsonClassCodeGenProcessor::class)
|
call.addService(Processor::class, JsonClassCodegenProcessor::class)
|
||||||
call.addKt("source.kt", """
|
call.addKt("source.kt", """
|
||||||
|import com.squareup.moshi.JsonClass
|
|import com.squareup.moshi.JsonClass
|
||||||
|
|
|
|
||||||
@@ -104,7 +104,7 @@ class CompilerTest {
|
|||||||
@Test fun abstractClassesNotSupported() {
|
@Test fun abstractClassesNotSupported() {
|
||||||
val call = KotlinCompilerCall(temporaryFolder.root)
|
val call = KotlinCompilerCall(temporaryFolder.root)
|
||||||
call.inheritClasspath = true
|
call.inheritClasspath = true
|
||||||
call.addService(Processor::class, JsonClassCodeGenProcessor::class)
|
call.addService(Processor::class, JsonClassCodegenProcessor::class)
|
||||||
call.addKt("source.kt", """
|
call.addKt("source.kt", """
|
||||||
|import com.squareup.moshi.JsonClass
|
|import com.squareup.moshi.JsonClass
|
||||||
|
|
|
|
||||||
@@ -121,7 +121,7 @@ class CompilerTest {
|
|||||||
@Test fun innerClassesNotSupported() {
|
@Test fun innerClassesNotSupported() {
|
||||||
val call = KotlinCompilerCall(temporaryFolder.root)
|
val call = KotlinCompilerCall(temporaryFolder.root)
|
||||||
call.inheritClasspath = true
|
call.inheritClasspath = true
|
||||||
call.addService(Processor::class, JsonClassCodeGenProcessor::class)
|
call.addService(Processor::class, JsonClassCodegenProcessor::class)
|
||||||
call.addKt("source.kt", """
|
call.addKt("source.kt", """
|
||||||
|import com.squareup.moshi.JsonClass
|
|import com.squareup.moshi.JsonClass
|
||||||
|
|
|
|
||||||
@@ -140,7 +140,7 @@ class CompilerTest {
|
|||||||
@Test fun enumClassesNotSupported() {
|
@Test fun enumClassesNotSupported() {
|
||||||
val call = KotlinCompilerCall(temporaryFolder.root)
|
val call = KotlinCompilerCall(temporaryFolder.root)
|
||||||
call.inheritClasspath = true
|
call.inheritClasspath = true
|
||||||
call.addService(Processor::class, JsonClassCodeGenProcessor::class)
|
call.addService(Processor::class, JsonClassCodegenProcessor::class)
|
||||||
call.addKt("source.kt", """
|
call.addKt("source.kt", """
|
||||||
|import com.squareup.moshi.JsonClass
|
|import com.squareup.moshi.JsonClass
|
||||||
|
|
|
|
||||||
@@ -162,7 +162,7 @@ class CompilerTest {
|
|||||||
@Test fun localClassesNotSupported() {
|
@Test fun localClassesNotSupported() {
|
||||||
val call = KotlinCompilerCall(temporaryFolder.root)
|
val call = KotlinCompilerCall(temporaryFolder.root)
|
||||||
call.inheritClasspath = true
|
call.inheritClasspath = true
|
||||||
call.addService(Processor::class, JsonClassCodeGenProcessor::class)
|
call.addService(Processor::class, JsonClassCodegenProcessor::class)
|
||||||
call.addKt("source.kt", """
|
call.addKt("source.kt", """
|
||||||
|import com.squareup.moshi.JsonClass
|
|import com.squareup.moshi.JsonClass
|
||||||
|
|
|
|
||||||
@@ -181,7 +181,7 @@ class CompilerTest {
|
|||||||
@Test fun objectDeclarationsNotSupported() {
|
@Test fun objectDeclarationsNotSupported() {
|
||||||
val call = KotlinCompilerCall(temporaryFolder.root)
|
val call = KotlinCompilerCall(temporaryFolder.root)
|
||||||
call.inheritClasspath = true
|
call.inheritClasspath = true
|
||||||
call.addService(Processor::class, JsonClassCodeGenProcessor::class)
|
call.addService(Processor::class, JsonClassCodegenProcessor::class)
|
||||||
call.addKt("source.kt", """
|
call.addKt("source.kt", """
|
||||||
|import com.squareup.moshi.JsonClass
|
|import com.squareup.moshi.JsonClass
|
||||||
|
|
|
|
||||||
@@ -199,7 +199,7 @@ class CompilerTest {
|
|||||||
@Test fun objectExpressionsNotSupported() {
|
@Test fun objectExpressionsNotSupported() {
|
||||||
val call = KotlinCompilerCall(temporaryFolder.root)
|
val call = KotlinCompilerCall(temporaryFolder.root)
|
||||||
call.inheritClasspath = true
|
call.inheritClasspath = true
|
||||||
call.addService(Processor::class, JsonClassCodeGenProcessor::class)
|
call.addService(Processor::class, JsonClassCodegenProcessor::class)
|
||||||
call.addKt("source.kt", """
|
call.addKt("source.kt", """
|
||||||
|import com.squareup.moshi.JsonClass
|
|import com.squareup.moshi.JsonClass
|
||||||
|
|
|
|
||||||
@@ -218,7 +218,7 @@ class CompilerTest {
|
|||||||
@Test fun requiredTransientConstructorParameterFails() {
|
@Test fun requiredTransientConstructorParameterFails() {
|
||||||
val call = KotlinCompilerCall(temporaryFolder.root)
|
val call = KotlinCompilerCall(temporaryFolder.root)
|
||||||
call.inheritClasspath = true
|
call.inheritClasspath = true
|
||||||
call.addService(Processor::class, JsonClassCodeGenProcessor::class)
|
call.addService(Processor::class, JsonClassCodegenProcessor::class)
|
||||||
call.addKt("source.kt", """
|
call.addKt("source.kt", """
|
||||||
|import com.squareup.moshi.JsonClass
|
|import com.squareup.moshi.JsonClass
|
||||||
|
|
|
|
||||||
@@ -235,7 +235,7 @@ class CompilerTest {
|
|||||||
@Test fun nonPropertyConstructorParameter() {
|
@Test fun nonPropertyConstructorParameter() {
|
||||||
val call = KotlinCompilerCall(temporaryFolder.root)
|
val call = KotlinCompilerCall(temporaryFolder.root)
|
||||||
call.inheritClasspath = true
|
call.inheritClasspath = true
|
||||||
call.addService(Processor::class, JsonClassCodeGenProcessor::class)
|
call.addService(Processor::class, JsonClassCodegenProcessor::class)
|
||||||
call.addKt("source.kt", """
|
call.addKt("source.kt", """
|
||||||
|import com.squareup.moshi.JsonClass
|
|import com.squareup.moshi.JsonClass
|
||||||
|
|
|
|
||||||
@@ -252,8 +252,8 @@ class CompilerTest {
|
|||||||
@Test fun badGeneratedAnnotation() {
|
@Test fun badGeneratedAnnotation() {
|
||||||
val call = KotlinCompilerCall(temporaryFolder.root)
|
val call = KotlinCompilerCall(temporaryFolder.root)
|
||||||
call.inheritClasspath = true
|
call.inheritClasspath = true
|
||||||
call.addService(Processor::class, JsonClassCodeGenProcessor::class)
|
call.addService(Processor::class, JsonClassCodegenProcessor::class)
|
||||||
call.kaptArgs[JsonClassCodeGenProcessor.OPTION_GENERATED] = "javax.annotation.GeneratedBlerg"
|
call.kaptArgs[JsonClassCodegenProcessor.OPTION_GENERATED] = "javax.annotation.GeneratedBlerg"
|
||||||
call.addKt("source.kt", """
|
call.addKt("source.kt", """
|
||||||
|import com.squareup.moshi.JsonClass
|
|import com.squareup.moshi.JsonClass
|
||||||
|
|
|
|
||||||
@@ -264,13 +264,13 @@ class CompilerTest {
|
|||||||
val result = call.execute()
|
val result = call.execute()
|
||||||
assertThat(result.exitCode).isEqualTo(ExitCode.COMPILATION_ERROR)
|
assertThat(result.exitCode).isEqualTo(ExitCode.COMPILATION_ERROR)
|
||||||
assertThat(result.systemErr).contains(
|
assertThat(result.systemErr).contains(
|
||||||
"Invalid option value for ${JsonClassCodeGenProcessor.OPTION_GENERATED}")
|
"Invalid option value for ${JsonClassCodegenProcessor.OPTION_GENERATED}")
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun multipleErrors() {
|
@Test fun multipleErrors() {
|
||||||
val call = KotlinCompilerCall(temporaryFolder.root)
|
val call = KotlinCompilerCall(temporaryFolder.root)
|
||||||
call.inheritClasspath = true
|
call.inheritClasspath = true
|
||||||
call.addService(Processor::class, JsonClassCodeGenProcessor::class)
|
call.addService(Processor::class, JsonClassCodegenProcessor::class)
|
||||||
call.addKt("source.kt", """
|
call.addKt("source.kt", """
|
||||||
|import com.squareup.moshi.JsonClass
|
|import com.squareup.moshi.JsonClass
|
||||||
|
|
|
|
||||||
@@ -291,7 +291,7 @@ class CompilerTest {
|
|||||||
@Test fun extendPlatformType() {
|
@Test fun extendPlatformType() {
|
||||||
val call = KotlinCompilerCall(temporaryFolder.root)
|
val call = KotlinCompilerCall(temporaryFolder.root)
|
||||||
call.inheritClasspath = true
|
call.inheritClasspath = true
|
||||||
call.addService(Processor::class, JsonClassCodeGenProcessor::class)
|
call.addService(Processor::class, JsonClassCodegenProcessor::class)
|
||||||
call.addKt("source.kt", """
|
call.addKt("source.kt", """
|
||||||
|import com.squareup.moshi.JsonClass
|
|import com.squareup.moshi.JsonClass
|
||||||
|import java.util.Date
|
|import java.util.Date
|
||||||
@@ -308,10 +308,10 @@ class CompilerTest {
|
|||||||
@Test fun extendJavaType() {
|
@Test fun extendJavaType() {
|
||||||
val call = KotlinCompilerCall(temporaryFolder.root)
|
val call = KotlinCompilerCall(temporaryFolder.root)
|
||||||
call.inheritClasspath = true
|
call.inheritClasspath = true
|
||||||
call.addService(Processor::class, JsonClassCodeGenProcessor::class)
|
call.addService(Processor::class, JsonClassCodegenProcessor::class)
|
||||||
call.addKt("source.kt", """
|
call.addKt("source.kt", """
|
||||||
|import com.squareup.moshi.JsonClass
|
|import com.squareup.moshi.JsonClass
|
||||||
|import com.squareup.moshi.JavaSuperclass
|
|import com.squareup.moshi.kotlin.codegen.JavaSuperclass
|
||||||
|
|
|
|
||||||
|@JsonClass(generateAdapter = true)
|
|@JsonClass(generateAdapter = true)
|
||||||
|class ExtendsJavaType(var b: Int) : JavaSuperclass()
|
|class ExtendsJavaType(var b: Int) : JavaSuperclass()
|
||||||
@@ -320,14 +320,14 @@ class CompilerTest {
|
|||||||
val result = call.execute()
|
val result = call.execute()
|
||||||
assertThat(result.exitCode).isEqualTo(ExitCode.COMPILATION_ERROR)
|
assertThat(result.exitCode).isEqualTo(ExitCode.COMPILATION_ERROR)
|
||||||
assertThat(result.systemErr)
|
assertThat(result.systemErr)
|
||||||
.contains("supertype com.squareup.moshi.JavaSuperclass is not a Kotlin type")
|
.contains("supertype com.squareup.moshi.kotlin.codegen.JavaSuperclass is not a Kotlin type")
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun nonFieldApplicableQualifier() {
|
fun nonFieldApplicableQualifier() {
|
||||||
val call = KotlinCompilerCall(temporaryFolder.root)
|
val call = KotlinCompilerCall(temporaryFolder.root)
|
||||||
call.inheritClasspath = true
|
call.inheritClasspath = true
|
||||||
call.addService(Processor::class, JsonClassCodeGenProcessor::class)
|
call.addService(Processor::class, JsonClassCodegenProcessor::class)
|
||||||
call.addKt("source.kt", """
|
call.addKt("source.kt", """
|
||||||
|import com.squareup.moshi.JsonClass
|
|import com.squareup.moshi.JsonClass
|
||||||
|import com.squareup.moshi.JsonQualifier
|
|import com.squareup.moshi.JsonQualifier
|
||||||
@@ -355,7 +355,7 @@ class CompilerTest {
|
|||||||
fun nonRuntimeQualifier() {
|
fun nonRuntimeQualifier() {
|
||||||
val call = KotlinCompilerCall(temporaryFolder.root)
|
val call = KotlinCompilerCall(temporaryFolder.root)
|
||||||
call.inheritClasspath = true
|
call.inheritClasspath = true
|
||||||
call.addService(Processor::class, JsonClassCodeGenProcessor::class)
|
call.addService(Processor::class, JsonClassCodegenProcessor::class)
|
||||||
call.addKt("source.kt", """
|
call.addKt("source.kt", """
|
||||||
|import com.squareup.moshi.JsonClass
|
|import com.squareup.moshi.JsonClass
|
||||||
|import com.squareup.moshi.JsonQualifier
|
|import com.squareup.moshi.JsonQualifier
|
@@ -13,7 +13,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package com.squareup.moshi
|
package com.squareup.moshi.kotlin.codegen
|
||||||
|
|
||||||
import com.google.common.collect.LinkedHashMultimap
|
import com.google.common.collect.LinkedHashMultimap
|
||||||
import okio.Buffer
|
import okio.Buffer
|
||||||
@@ -151,7 +151,7 @@ class KotlinCompilerCall(var scratchDir: File) {
|
|||||||
|
|
||||||
/** Returns the files on the host process' classpath. */
|
/** Returns the files on the host process' classpath. */
|
||||||
private fun classpathFiles(): List<File> {
|
private fun classpathFiles(): List<File> {
|
||||||
val classLoader = CompilerTest::class.java.classLoader
|
val classLoader = JsonClassCodegenProcessorTest::class.java.classLoader
|
||||||
if (classLoader !is URLClassLoader) {
|
if (classLoader !is URLClassLoader) {
|
||||||
throw UnsupportedOperationException("unable to extract classpath from $classLoader")
|
throw UnsupportedOperationException("unable to extract classpath from $classLoader")
|
||||||
}
|
}
|
@@ -13,7 +13,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package com.squareup.moshi
|
package com.squareup.moshi.kotlin.codegen
|
||||||
|
|
||||||
import org.jetbrains.kotlin.cli.common.ExitCode
|
import org.jetbrains.kotlin.cli.common.ExitCode
|
||||||
|
|
@@ -13,12 +13,13 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package com.squareup.moshi
|
package com.squareup.moshi.kotlin.codegen
|
||||||
|
|
||||||
import com.google.common.truth.Truth.assertThat
|
import com.google.common.truth.Truth.assertThat
|
||||||
import com.squareup.kotlinpoet.ParameterizedTypeName
|
import com.squareup.kotlinpoet.ParameterizedTypeName
|
||||||
import com.squareup.kotlinpoet.WildcardTypeName
|
import com.squareup.kotlinpoet.WildcardTypeName
|
||||||
import com.squareup.kotlinpoet.asClassName
|
import com.squareup.kotlinpoet.asClassName
|
||||||
|
import com.squareup.moshi.kotlin.codegen.TypeResolver
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
|
|
||||||
class TypeResolverTest {
|
class TypeResolverTest {
|
@@ -10,7 +10,7 @@
|
|||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>moshi-kotlin-codegen-integration</artifactId>
|
<artifactId>moshi-kotlin-tests</artifactId>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
@@ -52,7 +52,7 @@
|
|||||||
<annotationProcessorPaths>
|
<annotationProcessorPaths>
|
||||||
<annotationProcessorPath>
|
<annotationProcessorPath>
|
||||||
<groupId>com.squareup.moshi</groupId>
|
<groupId>com.squareup.moshi</groupId>
|
||||||
<artifactId>moshi-kotlin-codegen-compiler</artifactId>
|
<artifactId>moshi-kotlin-codegen</artifactId>
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
</annotationProcessorPath>
|
</annotationProcessorPath>
|
||||||
</annotationProcessorPaths>
|
</annotationProcessorPaths>
|
||||||
@@ -83,7 +83,7 @@
|
|||||||
<annotationProcessorPaths>
|
<annotationProcessorPaths>
|
||||||
<annotationProcessorPath>
|
<annotationProcessorPath>
|
||||||
<groupId>com.squareup.moshi</groupId>
|
<groupId>com.squareup.moshi</groupId>
|
||||||
<artifactId>moshi-kotlin-codegen-compiler</artifactId>
|
<artifactId>moshi-kotlin-codegen</artifactId>
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
</annotationProcessorPath>
|
</annotationProcessorPath>
|
||||||
</annotationProcessorPaths>
|
</annotationProcessorPaths>
|
@@ -13,8 +13,16 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package com.squareup.moshi
|
package com.squareup.moshi.kotlin.codgen
|
||||||
|
|
||||||
|
import com.squareup.moshi.FromJson
|
||||||
|
import com.squareup.moshi.Json
|
||||||
|
import com.squareup.moshi.JsonClass
|
||||||
|
import com.squareup.moshi.JsonDataException
|
||||||
|
import com.squareup.moshi.JsonQualifier
|
||||||
|
import com.squareup.moshi.Moshi
|
||||||
|
import com.squareup.moshi.ToJson
|
||||||
|
import com.squareup.moshi.Types
|
||||||
import org.assertj.core.api.Assertions.assertThat
|
import org.assertj.core.api.Assertions.assertThat
|
||||||
import org.intellij.lang.annotations.Language
|
import org.intellij.lang.annotations.Language
|
||||||
import org.junit.Assert.fail
|
import org.junit.Assert.fail
|
||||||
@@ -244,14 +252,11 @@ class GeneratedAdaptersTest {
|
|||||||
assertThat(nullSerializedNullableTypeParams).isEqualTo(nullableTypeParams)
|
assertThat(nullSerializedNullableTypeParams).isEqualTo(nullableTypeParams)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test fun doNotGenerateAdapter() {
|
||||||
fun doNotGenerateAdapter() {
|
|
||||||
try {
|
try {
|
||||||
StandardJsonAdapters.generatedAdapter(
|
Class.forName("${GeneratedAdaptersTest::class.java.name}_DoNotGenerateAdapterJsonAdapter")
|
||||||
moshi, DoNotGenerateAdapter::class.java, DoNotGenerateAdapter::class.java)
|
|
||||||
fail("found a generated adapter for a type that shouldn't have one")
|
fail("found a generated adapter for a type that shouldn't have one")
|
||||||
} catch (e: RuntimeException) {
|
} catch (expected: ClassNotFoundException) {
|
||||||
assertThat(e).hasCauseInstanceOf(ClassNotFoundException::class.java)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
4
pom.xml
4
pom.xml
@@ -22,8 +22,8 @@
|
|||||||
<module>examples</module>
|
<module>examples</module>
|
||||||
<module>adapters</module>
|
<module>adapters</module>
|
||||||
<module>kotlin</module>
|
<module>kotlin</module>
|
||||||
<module>kotlin-codegen/compiler</module>
|
<module>kotlin/codegen</module>
|
||||||
<module>kotlin-codegen/integration-test</module>
|
<module>kotlin/tests</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
|
Reference in New Issue
Block a user