Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix - inheritsFrom in kotlin, when generics are used #164

Merged
merged 1 commit into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ class AstCreator(fileWithMeta: KtFileWithMeta, bindingContext: BindingContext, g
protected def fullNameByImportPath(typeRef: KtTypeReference, file: KtFile): Option[String] = {
if (typeRef == null) { None }
else {
val typeRefText = typeRef.getText.stripSuffix("?")
val typeRefText = typeRef.getText.split("<").headOption.getOrElse(typeRef.getText).stripSuffix("?")
file.getImportList.getImports.asScala.collectFirst {
case directive if directive.getImportedName != null && directive.getImportedName.toString == typeRefText =>
directive.getImportPath.getPathStr
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -451,4 +451,21 @@ class TypeDeclTests extends KotlinCode2CpgFixture(withOssDataflow = false) {
firstCallOfSecondaryCtor.methodFullName shouldBe "mypkg.QClass.<init>:void()"
}
}

"CPG for inheritance having generics" should {
val cpg = code("""
|import org.apache.flink.streaming.api.functions.sink.RichSinkFunction
|
|class ApiSink<T>(private val apiUrl: String) : RichSinkFunction<T>() {
| private var httpClient: CloseableHttpClient? = null
|
|}
|""".stripMargin)

"resolve base types" in {
cpg.typeDecl.name("ApiSink").inheritsFromTypeFullName.l shouldBe List(
"org.apache.flink.streaming.api.functions.sink.RichSinkFunction"
)
}
}
}
Loading