• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 Square, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * https://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.squareup.kotlinpoet.ksp.test.processor
17 
18 import com.google.common.truth.Truth.assertThat
19 import com.google.devtools.ksp.symbol.KSAnnotation
20 import com.google.devtools.ksp.symbol.KSDeclaration
21 import com.google.devtools.ksp.symbol.KSType
22 import com.google.devtools.ksp.symbol.KSTypeArgument
23 import com.google.devtools.ksp.symbol.Nullability
24 import com.squareup.kotlinpoet.ksp.toTypeName
25 import kotlin.test.assertFailsWith
26 import org.junit.Test
27 
28 class KsTypesTest {
29   // Regression test for https://github.com/square/kotlinpoet/issues/1178
30   @Test
errorTypesShouldFailnull31   fun errorTypesShouldFail() {
32     val type = object : KSType {
33       override val isError: Boolean = true
34 
35       // Boilerplate
36       override val annotations: Sequence<KSAnnotation>
37         get() = throw NotImplementedError()
38       override val arguments: List<KSTypeArgument>
39         get() = throw NotImplementedError()
40       override val declaration: KSDeclaration
41         get() = throw NotImplementedError()
42       override val isFunctionType: Boolean
43         get() = throw NotImplementedError()
44       override val isMarkedNullable: Boolean
45         get() = throw NotImplementedError()
46       override val isSuspendFunctionType: Boolean
47         get() = throw NotImplementedError()
48       override val nullability: Nullability
49         get() = throw NotImplementedError()
50 
51       override fun isAssignableFrom(that: KSType): Boolean {
52         throw NotImplementedError()
53       }
54 
55       override fun isCovarianceFlexible(): Boolean {
56         throw NotImplementedError()
57       }
58 
59       override fun isMutabilityFlexible(): Boolean {
60         throw NotImplementedError()
61       }
62 
63       override fun makeNotNullable(): KSType {
64         throw NotImplementedError()
65       }
66 
67       override fun makeNullable(): KSType {
68         throw NotImplementedError()
69       }
70 
71       override fun replace(arguments: List<KSTypeArgument>): KSType {
72         throw NotImplementedError()
73       }
74 
75       override fun starProjection(): KSType {
76         throw NotImplementedError()
77       }
78     }
79 
80     val exception = assertFailsWith<IllegalArgumentException> {
81       type.toTypeName()
82     }
83     assertThat(exception).hasMessageThat()
84       .contains("is not resolvable in the current round of processing")
85   }
86 }
87