Skip to content

Commit

Permalink
Rename localNameOnly to doNotPrependNamespace
Browse files Browse the repository at this point in the history
This PR fixes #1963
  • Loading branch information
oxisto committed Jan 28, 2025
1 parent d031b38 commit cbe7d60
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -174,21 +174,21 @@ 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)
} else {
// 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)
}
}

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit cbe7d60

Please sign in to comment.