Skip to content

Commit

Permalink
fix namespace null problems
Browse files Browse the repository at this point in the history
  • Loading branch information
maximiliankaul committed Nov 29, 2024
1 parent 2eece6b commit 4bc31b5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,16 @@ class IniFileFrontend(language: Language<IniFileFrontend>, ctx: TranslationConte
* [de.fraunhofer.aisec.cpg.TranslationConfiguration.topLevel] using
* [Language.namespaceDelimiter] as a separator
*/
val topLevel = (config.topLevel?.let { file.relativeToOrNull(it) } ?: file).parent
val topLevel = config.topLevel?.let { file.relativeToOrNull(it) } ?: file
val parentDir = topLevel.parent

val namespace =
(topLevel.toString().split("/") + file.nameWithoutExtension).joinToString(
language.namespaceDelimiter
) // TODO: Windows?
if (parentDir != null) {
val pathSegments = parentDir.toString().split(File.separator)
(pathSegments + file.nameWithoutExtension).joinToString(language.namespaceDelimiter)

Check warning on line 98 in cpg-language-ini/src/main/kotlin/de/fraunhofer/aisec/cpg/frontend/configfiles/IniFileFrontend.kt

View check run for this annotation

Codecov / codecov/patch

cpg-language-ini/src/main/kotlin/de/fraunhofer/aisec/cpg/frontend/configfiles/IniFileFrontend.kt#L97-L98

Added lines #L97 - L98 were not covered by tests
} else {
file.nameWithoutExtension
}

val tud = newTranslationUnitDeclaration(name = file.name, rawNode = ini)
scopeManager.resetToGlobal(tud)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,10 @@ class IniFileTest : BaseTest() {
val namespace = tu.namespaces.firstOrNull()
assertNotNull(namespace)
assertFullName(
listOf("src", "test", "resources", "config")
.joinToString(tu.language?.namespaceDelimiter ?: "."),
"config",
namespace,
"Namespace name mismatch."
)
) // analyzeAndGetFirstTU does not provide the full path

assertEquals(2, tu.records.size, "Expected two records")

Expand Down

0 comments on commit 4bc31b5

Please sign in to comment.