Skip to content

Commit 8ff86a5

Browse files
authored
KON-675 Add Number Type Basic Kotlin Types (#1490)
* Add Number Type to Kotlin basic types * Use simple name
1 parent 131efa0 commit 8ff86a5

File tree

1 file changed

+60
-57
lines changed
  • lib/src/main/kotlin/com/lemonappdev/konsist/core/util

1 file changed

+60
-57
lines changed

lib/src/main/kotlin/com/lemonappdev/konsist/core/util/TypeUtil.kt

+60-57
Original file line numberDiff line numberDiff line change
@@ -226,12 +226,12 @@ object TypeUtil {
226226

227227
internal fun isKotlinBasicType(typeName: String): Boolean {
228228
val bareTypeName = getBareType(typeName)
229-
return kotlinBasicTypes.any { it == bareTypeName }
229+
return kotlinBasicTypeNames.any { it == bareTypeName }
230230
}
231231

232232
internal fun isKotlinCollectionTypes(typeName: String): Boolean {
233233
val bareTypeName = getBareType(typeName)
234-
return kotlinCollectionTypes.any { it == bareTypeName }
234+
return kotlinCollectionTypeNames.any { it == bareTypeName }
235235
}
236236

237237
internal fun getBareType(name: String): String =
@@ -271,60 +271,63 @@ object TypeUtil {
271271
this
272272
}
273273

274-
// Basic types in Kotlin are described here: https://kotlinlang.org/docs/basic-types.html
275-
private val kotlinBasicTypes: Set<String>
276-
get() =
277-
setOf(
278-
"Byte",
279-
"Short",
280-
"Int",
281-
"Long",
282-
"Float",
283-
"Double",
284-
"UByte",
285-
"UShort",
286-
"UInt",
287-
"ULong",
288-
"UByteArray",
289-
"UShortArray",
290-
"UIntArray",
291-
"ULongArray",
292-
"Boolean",
293-
"Char",
294-
"String",
295-
"Unit",
296-
"Any",
297-
"Nothing",
298-
)
274+
// Kotlin basic types: https://kotlinlang.org/docs/basic-types.html
275+
@OptIn(ExperimentalUnsignedTypes::class)
276+
private val kotlinBasicTypeNames: Set<String> =
277+
setOf(
278+
Any::class,
279+
Boolean::class,
280+
Byte::class,
281+
Char::class,
282+
Double::class,
283+
Float::class,
284+
Int::class,
285+
Long::class,
286+
Nothing::class,
287+
Number::class,
288+
Short::class,
289+
String::class,
290+
UByte::class,
291+
UByteArray::class,
292+
UInt::class,
293+
UIntArray::class,
294+
ULong::class,
295+
ULongArray::class,
296+
UShort::class,
297+
UShortArray::class,
298+
Unit::class,
299+
).mapNotNull { it.simpleName }
300+
.toSet()
299301

300-
// Collections in Kotlin are described here: https://kotlinlang.org/docs/collections-overview.html#collection
301-
// and here https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections
302-
private val kotlinCollectionTypes: Set<String>
303-
get() =
304-
setOf(
305-
"AbstractCollection",
306-
"AbstractIterator",
307-
"AbstractList",
308-
"AbstractMap",
309-
"AbstractMutableCollection",
310-
"AbstractMutableList",
311-
"AbstractMutableMap",
312-
"AbstractMutableSet",
313-
"AbstractSet",
314-
"ArrayDeque",
315-
"ArrayList",
316-
"Array",
317-
"Collection",
318-
"HashMap",
319-
"HashSet",
320-
"LinkedHashMap",
321-
"LinkedHashSet",
322-
"List",
323-
"Map",
324-
"MutableCollection",
325-
"MutableList",
326-
"MutableMap",
327-
"MutableSet",
328-
"Set",
329-
)
302+
// Kotlin collections types:
303+
// https://kotlinlang.org/docs/collections-overview.html#collection
304+
// https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections
305+
private val kotlinCollectionTypeNames: Set<String> =
306+
setOf(
307+
AbstractCollection::class,
308+
AbstractIterator::class,
309+
AbstractList::class,
310+
AbstractMap::class,
311+
AbstractMutableCollection::class,
312+
AbstractMutableList::class,
313+
AbstractMutableMap::class,
314+
AbstractMutableSet::class,
315+
AbstractSet::class,
316+
ArrayDeque::class,
317+
ArrayList::class,
318+
Array::class,
319+
Collection::class,
320+
HashMap::class,
321+
HashSet::class,
322+
LinkedHashMap::class,
323+
LinkedHashSet::class,
324+
List::class,
325+
Map::class,
326+
MutableCollection::class,
327+
MutableList::class,
328+
MutableMap::class,
329+
MutableSet::class,
330+
Set::class,
331+
).mapNotNull { it.simpleName }
332+
.toSet()
330333
}

0 commit comments

Comments
 (0)