Skip to content

Commit

Permalink
Handle properties from companion objects
Browse files Browse the repository at this point in the history
  • Loading branch information
jongerrish committed Jan 29, 2021
1 parent e2f81c4 commit eed4d81
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import org.jetbrains.kotlin.platform.TargetPlatform
import org.jetbrains.kotlin.psi.KtDeclaration
import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.resolve.BindingTrace
import org.jetbrains.kotlin.resolve.PropertyImportedFromObject
import org.jetbrains.kotlin.resolve.calls.checkers.CallChecker
import org.jetbrains.kotlin.resolve.calls.checkers.CallCheckerContext
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
Expand Down Expand Up @@ -126,6 +127,9 @@ class JdepsGenExtension(
is JavaPropertyDescriptor -> {
getClassCanonicalPath(resultingDescriptor)?.let { explicitClassesCanonicalPaths.add(it) }
}
is PropertyImportedFromObject -> {
collectTypeReferences((resolvedCall.resultingDescriptor as PropertyImportedFromObject).containingObject.defaultType)
}
else -> return
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,45 @@ class KotlinBuilderJvmJdepsTest {
assertIncomplete(jdeps).isEmpty()
}

@Test
fun `companion object inlined constant dependency recorded`() {
val dependentTarget = ctx.runCompileTask(Consumer { c: KotlinJvmTestBuilder.TaskBuilder ->
c.addSource("ContainsConstant.kt",
"""
package dependency
class HasCompanion {
companion object {
const val CONSTANT_VAL = 42
}
}
""")
c.outputJar()
c.outputJdeps()
c.compileKotlin()
})

val dependingTarget = ctx.runCompileTask(Consumer { c: KotlinJvmTestBuilder.TaskBuilder ->
c.addSource("HasPropertyDependency.kt",
"""
package something
import dependency.HasCompanion.Companion.CONSTANT_VAL
val property2 = CONSTANT_VAL
""")
c.outputJar()
c.compileKotlin()
c.addDirectDependencies(dependentTarget)
c.outputJdeps()
})
val jdeps = depsProto(dependingTarget)

assertThat(jdeps.ruleLabel).isEqualTo(dependingTarget.label())

assertExplicit(jdeps).containsExactly(dependentTarget.singleCompileJar())
assertImplicit(jdeps).isEmpty()
assertUnused(jdeps).isEmpty()
assertIncomplete(jdeps).isEmpty()
}

@Test
fun `constructor param inner class recorded`() {
val dependentTarget = ctx.runCompileTask(Consumer { c: KotlinJvmTestBuilder.TaskBuilder ->
Expand Down

0 comments on commit eed4d81

Please sign in to comment.