diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/DeclarationBuilder.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/DeclarationBuilder.kt index 4e86647fdd..29a119aa2f 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/DeclarationBuilder.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/DeclarationBuilder.kt @@ -154,7 +154,7 @@ fun MetadataProvider.newParameterDeclaration( rawNode: Any? = null, ): ParameterDeclaration { val node = ParameterDeclaration() - node.applyMetadata(this, name, rawNode, localNameOnly = true) + node.applyMetadata(this, name, rawNode, doNotPrependNamespace = true) node.type = type node.isVariadic = variadic diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/NodeBuilder.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/NodeBuilder.kt index c6efdb4623..c13efe1c3a 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/NodeBuilder.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/NodeBuilder.kt @@ -104,7 +104,7 @@ fun Node.applyMetadata( provider: MetadataProvider?, name: CharSequence? = EMPTY_NAME, rawNode: Any? = null, - localNameOnly: Boolean = false, + doNotPrependNamespace: Boolean = false, defaultNamespace: Name? = null, ) { // We definitely need a context provider, because otherwise we cannot set the context and the @@ -154,17 +154,17 @@ fun Node.applyMetadata( } else { defaultNamespace } - this.name = this.newName(name, localNameOnly, namespace) + this.name = this.newName(name, doNotPrependNamespace, namespace) } } /** - * Generates a [Name] object from the given [name]. If [localNameOnly] is set, only the localName is - * used, otherwise the [namespace] is added to generate a fqn if the [name] is not a fqn anyway. + * Generates a [Name] object from the given [name]. If [doNotPrependNamespace] is set, only the supplied name is + * used, otherwise the [namespace] is prepended to the name. */ fun LanguageProvider.newName( name: CharSequence, - localNameOnly: Boolean = false, + doNotPrependNamespace: Boolean = false, namespace: Name? = null, ): Name { val language = this.language @@ -174,7 +174,7 @@ fun LanguageProvider.newName( // CharSequence/String. return if (name is Name && name.isQualified()) { name - } else if (language != null && name.contains(language.namespaceDelimiter)) { + } else if (name.contains(language.namespaceDelimiter)) { // Let's check, if this is an FQN as string / char sequence by any chance. Then we need // to parse the name. In the future, we might drop compatibility for this language.parseName(name) @@ -182,13 +182,13 @@ fun LanguageProvider.newName( // Otherwise, a local name is supplied. Some nodes only want a local name. In this case, // we create a new name with the supplied (local) name and set the parent to null. val parent = - if (localNameOnly) { + if (doNotPrependNamespace) { null } else { namespace } - Name(name.toString(), parent, language?.namespaceDelimiter ?: ".") + Name(name.toString(), parent, language.namespaceDelimiter) } } @@ -201,7 +201,7 @@ fun LanguageProvider.newName( @JvmOverloads fun MetadataProvider.newAnnotation(name: CharSequence?, rawNode: Any? = null): Annotation { val node = Annotation() - node.applyMetadata(this, name, rawNode, localNameOnly = true) + node.applyMetadata(this, name, rawNode, doNotPrependNamespace = true) log(node) return node diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/TypeBuilder.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/TypeBuilder.kt index 32cf25f431..3a4e343b7e 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/TypeBuilder.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/TypeBuilder.kt @@ -119,7 +119,7 @@ fun LanguageProvider.objectType( // Apply our usual metadata, such as scope, code, location, if we have any. Make sure only // to refer by the local name because we will treat types as sort of references when // creating them and resolve them later. - type.applyMetadata(this, name, rawNode = rawNode, localNameOnly = true) + type.applyMetadata(this, name, rawNode = rawNode, doNotPrependNamespace = true) // Piping it through register type will ensure that we know the type and can resolve it later return c.typeManager.registerType(type)