Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename localNameOnly to doNotPrependNamespace #1993

Merged
merged 2 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading