Skip to content

Commit

Permalink
Cleanup bunch of small issues in JdepsGetExtension.kt (#819)
Browse files Browse the repository at this point in the history
- Remove explicit casts unneeded because of smart casts.
- Remove `collectSuperTypes` parameter as it is always `true`.
- Remove the mention of Remapper from the comment - its use was removed in 71246c9
- Typo fixes.
  • Loading branch information
aeremin authored Aug 15, 2022
1 parent 7ba80e7 commit c83b8a8
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions src/main/kotlin/io/bazel/kotlin/plugin/jdeps/JdepsGenExtension.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,15 @@ import java.nio.file.Paths
/**
* Kotlin compiler extension that tracks classes (and corresponding classpath jars) needed to
* compile current kotlin target. Tracked data should include all classes whose changes could
* affect target's compilation out : direct class dependencies (i.e external classes directly
* affect target's compilation out : direct class dependencies (i.e. external classes directly
* used), but also their superclass, interfaces, etc.
* The primary use of this extension is to improve Kotlin module compilation avoidance in build
* systems (like Buck).
*
* Tracking of classes is done with a Remapper, which exposes all object types used by the class
* bytecode being generated. Tracking of the ancestor classes is done via modules and class
* Tracking of classes and their ancestors is done via modules and class
* descriptors that got generated during analysis/resolve phase of Kotlin compilation.
*
* Note: annotation processors dependencies may need to be tracked separatly (and may not need
* Note: annotation processors dependencies may need to be tracked separately (and may not need
* per-class ABI change tracking)
*
* @param project the current compilation project
Expand Down Expand Up @@ -130,10 +129,10 @@ class JdepsGenExtension(
) {
when (val resultingDescriptor = resolvedCall.resultingDescriptor) {
is FunctionImportedFromObject -> {
collectTypeReferences((resolvedCall.resultingDescriptor as FunctionImportedFromObject).containingObject.defaultType)
collectTypeReferences(resultingDescriptor.containingObject.defaultType)
}
is PropertyImportedFromObject -> {
collectTypeReferences((resolvedCall.resultingDescriptor as PropertyImportedFromObject).containingObject.defaultType)
collectTypeReferences(resultingDescriptor.containingObject.defaultType)
}
is JavaMethodDescriptor -> {
getClassCanonicalPath((resultingDescriptor.containingDeclaration as ClassDescriptor).typeConstructor)?.let { explicitClassesCanonicalPaths.add(it) }
Expand Down Expand Up @@ -223,26 +222,23 @@ class JdepsGenExtension(
* types.
*/
private fun collectTypeReferences(kotlinType: KotlinType,
isExplicit: Boolean = true,
collectSuperTypes: Boolean = true) {
isExplicit: Boolean = true) {
if (isExplicit) {
addExplicitDep(kotlinType)
} else {
addImplicitDep(kotlinType)
}

if (collectSuperTypes) {
kotlinType.supertypes().forEach {
addImplicitDep(it)
}
kotlinType.supertypes().forEach {
addImplicitDep(it)
}

collectTypeArguments(kotlinType, isExplicit)
}

fun collectTypeArguments(kotlinType: KotlinType,
isExplicit: Boolean,
visitedKotlinTypes: MutableSet<KotlinType> = mutableSetOf()) {
private fun collectTypeArguments(kotlinType: KotlinType,
isExplicit: Boolean,
visitedKotlinTypes: MutableSet<KotlinType> = mutableSetOf()) {
visitedKotlinTypes.add(kotlinType)
kotlinType.arguments.map { it.type }.forEach { typeArgument ->
if (isExplicit) {
Expand Down

0 comments on commit c83b8a8

Please sign in to comment.