Skip to content

Commit e426c11

Browse files
yaronskayaanatolystansler
authored andcommitted
feat: more imports processing (#225)
* feat: add process qt lib, fix json lib * feat: more imports * chore: syntax
1 parent d13c7ad commit e426c11

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

src/main/kotlin/app/extractors/CppExtractor.kt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class CppExtractor : ExtractorInterface {
1818
ExtractorInterface.getMultipleImportsToLibraryMap(LANGUAGE_NAME)
1919
val importRegex = Regex("""^([^\n]*#include)\s[^\n]*""")
2020
val commentRegex = Regex("""^([^\n]*//)[^\n]*""")
21-
val extractImportRegex = Regex("""#include\s+["<](\w+)[/\w+]*\.\w+[">]""")
21+
val extractImportRegex = Regex("""#include\s+["<](\w+)[/\w+]*(\.\w+)?[">]""")
2222
}
2323

2424
override fun extract(files: List<DiffFile>): List<CommitStats> {
@@ -32,12 +32,19 @@ class CppExtractor : ExtractorInterface {
3232
fileContent.forEach {
3333
val res = extractImportRegex.find(it)
3434
if (res != null) {
35-
val lineLib = res.groupValues.last()
35+
val lineLib = res.groupValues
36+
.last { !it.startsWith(".") && it != ""}
3637
imports.add(lineLib)
3738
}
3839
}
39-
4040
val libraries = imports.map { MULTI_IMPORT_TO_LIB.getOrDefault(it, it) }
41+
.map { import -> when {
42+
import.startsWith("Q") -> "Qt"
43+
import.startsWith("Lzma") -> "Lzma"
44+
import.startsWith("Ogre") -> "Ogre"
45+
else -> import
46+
}}
47+
.toSet().toList()
4148
return libraries
4249
}
4350

src/main/resources/data/libraries/java_libraries.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ com.airbnb.android.react.lottie
4545
zipkin
4646
com.facebook.presto
4747
dagger
48-
junit
48+
org.junit
4949
com.lmax.disruptor
5050
com.jakewharton.rxbinding2
5151
org.physical_web

src/test/kotlin/test/tests/extractors/ExtractorTest.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,4 +259,12 @@ class ExtractorTest : Spek({
259259
}
260260
}
261261

262+
given("Qt import in cpp file") {
263+
it("extracts library name") {
264+
val lib = "Qt"
265+
val line = "#include <QFileDialog>"
266+
assertExtractsImport(lib, line, CppExtractor())
267+
}
268+
}
269+
262270
})

0 commit comments

Comments
 (0)