Skip to content

Commit

Permalink
Remove unsafe casts
Browse files Browse the repository at this point in the history
  • Loading branch information
matfax committed Oct 14, 2018
1 parent 593075a commit bf4a399
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 13 deletions.
6 changes: 5 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ allprojects {
}

group = "com.github.matfax"
version = (extensions.extraProperties.get("gitVersion") as Closure<*>).call() ?: "dirty"
version = (extensions.extraProperties.get("gitVersion") as? Closure<*>)?.call() ?: "dirty"

tasks.create("printVersionName") {
doLast { println(version) }
}

tasks {
getByName<Upload>("uploadArchives") {
Expand Down
10 changes: 10 additions & 0 deletions library/src/main/kotlin/com/github/matfax/klassindex/Index.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,21 @@ package com.github.matfax.klassindex

import kotlin.reflect.KClass

/**
* The interface to generated index classes.
*/
interface Index {

/**
* Access the compiled index map.
*/
fun index(): Map<KClass<*>, Set<KClass<*>>>

companion object {

/**
* Load an index class with the given [className] from the class loader.
*/
fun load(className: String): Index {
return Class.forName(
"${this::class.java.`package`.name}.$className"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,19 +177,22 @@ open class KlassIndexProcessor : AbstractProcessor() {
.forEach { mirror ->

val superType = mirror as DeclaredType
val superTypeElement = superType.asElement() as TypeElement
storeSubclass(superTypeElement, rootElement)

superTypeElement.annotationMirrors
.asSequence()
.map {
it.annotationType
.asElement() as TypeElement
}
.filter { hasAnnotation(it, Inherited::class.java) }
.forEach { storeAnnotation(it, rootElement) }
val superTypeElement = superType.asElement() as? TypeElement
superTypeElement?.let { element ->

storeSubclass(element, rootElement)

indexSupertypes(rootElement, superTypeElement)
element.annotationMirrors
.asSequence()
.map {
it.annotationType
.asElement() as TypeElement
}
.filter { hasAnnotation(it, Inherited::class.java) }
.forEach { storeAnnotation(it, rootElement) }

indexSupertypes(rootElement, element)
}
}
}

Expand Down

0 comments on commit bf4a399

Please sign in to comment.