File tree Expand file tree Collapse file tree 3 files changed +19
-4
lines changed Expand file tree Collapse file tree 3 files changed +19
-4
lines changed Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ class CppExtractor : ExtractorInterface {
18
18
ExtractorInterface .getMultipleImportsToLibraryMap(LANGUAGE_NAME )
19
19
val importRegex = Regex (""" ^([^\n]*#include)\s[^\n]*""" )
20
20
val commentRegex = Regex (""" ^([^\n]*//)[^\n]*""" )
21
- val extractImportRegex = Regex (""" #include\s+["<](\w+)[/\w+]*\.\w+[">]""" )
21
+ val extractImportRegex = Regex (""" #include\s+["<](\w+)[/\w+]*( \.\w+)? [">]""" )
22
22
}
23
23
24
24
override fun extract (files : List <DiffFile >): List <CommitStats > {
@@ -32,12 +32,19 @@ class CppExtractor : ExtractorInterface {
32
32
fileContent.forEach {
33
33
val res = extractImportRegex.find(it)
34
34
if (res != null ) {
35
- val lineLib = res.groupValues.last()
35
+ val lineLib = res.groupValues
36
+ .last { ! it.startsWith(" ." ) && it != " " }
36
37
imports.add(lineLib)
37
38
}
38
39
}
39
-
40
40
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()
41
48
return libraries
42
49
}
43
50
Original file line number Diff line number Diff line change @@ -45,7 +45,7 @@ com.airbnb.android.react.lottie
45
45
zipkin
46
46
com.facebook.presto
47
47
dagger
48
- junit
48
+ org. junit
49
49
com.lmax.disruptor
50
50
com.jakewharton.rxbinding2
51
51
org.physical_web
Original file line number Diff line number Diff line change @@ -259,4 +259,12 @@ class ExtractorTest : Spek({
259
259
}
260
260
}
261
261
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
+
262
270
})
You can’t perform that action at this time.
0 commit comments