Use qualified_name terminology in more structs for consistency (#4873)

This commit is contained in:
Charlie Marsh 2023-06-05 15:06:48 -04:00 committed by GitHub
parent 33434fcb9c
commit 8938b2d555
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 116 additions and 105 deletions

View file

@ -48,36 +48,36 @@ impl<'a> Binding<'a> {
/// Return `true` if this binding redefines the given binding.
pub fn redefines(&self, existing: &'a Binding) -> bool {
match &self.kind {
BindingKind::Importation(Importation { full_name }) => {
BindingKind::Importation(Importation { qualified_name }) => {
if let BindingKind::SubmoduleImportation(SubmoduleImportation {
full_name: existing,
qualified_name: existing,
}) = &existing.kind
{
return full_name == existing;
return qualified_name == existing;
}
}
BindingKind::FromImportation(FromImportation { full_name }) => {
BindingKind::FromImportation(FromImportation { qualified_name }) => {
if let BindingKind::SubmoduleImportation(SubmoduleImportation {
full_name: existing,
qualified_name: existing,
}) = &existing.kind
{
return full_name == existing;
return qualified_name == existing;
}
}
BindingKind::SubmoduleImportation(SubmoduleImportation { full_name }) => {
BindingKind::SubmoduleImportation(SubmoduleImportation { qualified_name }) => {
match &existing.kind {
BindingKind::Importation(Importation {
full_name: existing,
qualified_name: existing,
})
| BindingKind::SubmoduleImportation(SubmoduleImportation {
full_name: existing,
qualified_name: existing,
}) => {
return full_name == existing;
return qualified_name == existing;
}
BindingKind::FromImportation(FromImportation {
full_name: existing,
qualified_name: existing,
}) => {
return full_name == existing;
return qualified_name == existing;
}
_ => {}
}
@ -104,10 +104,12 @@ impl<'a> Binding<'a> {
/// Returns the fully-qualified symbol name, if this symbol was imported from another module.
pub fn qualified_name(&self) -> Option<&str> {
match &self.kind {
BindingKind::Importation(Importation { full_name }) => Some(full_name),
BindingKind::FromImportation(FromImportation { full_name }) => Some(full_name),
BindingKind::SubmoduleImportation(SubmoduleImportation { full_name }) => {
Some(full_name)
BindingKind::Importation(Importation { qualified_name }) => Some(qualified_name),
BindingKind::FromImportation(FromImportation { qualified_name }) => {
Some(qualified_name)
}
BindingKind::SubmoduleImportation(SubmoduleImportation { qualified_name }) => {
Some(qualified_name)
}
_ => None,
}
@ -117,14 +119,14 @@ impl<'a> Binding<'a> {
/// symbol was imported from another module.
pub fn module_name(&self) -> Option<&str> {
match &self.kind {
BindingKind::Importation(Importation { full_name })
| BindingKind::SubmoduleImportation(SubmoduleImportation { full_name }) => {
Some(full_name.split('.').next().unwrap_or(full_name))
BindingKind::Importation(Importation { qualified_name })
| BindingKind::SubmoduleImportation(SubmoduleImportation { qualified_name }) => {
Some(qualified_name.split('.').next().unwrap_or(qualified_name))
}
BindingKind::FromImportation(FromImportation { full_name }) => Some(
full_name
BindingKind::FromImportation(FromImportation { qualified_name }) => Some(
qualified_name
.rsplit_once('.')
.map_or(full_name, |(module, _)| module),
.map_or(qualified_name, |(module, _)| module),
),
_ => None,
}
@ -241,9 +243,9 @@ pub struct Export<'a> {
#[derive(Clone, Debug)]
pub struct Importation<'a> {
/// The full name of the module being imported.
/// Ex) Given `import foo`, `full_name` would be "foo".
/// Ex) Given `import foo as bar`, `full_name` would be "foo".
pub full_name: &'a str,
/// Ex) Given `import foo`, `qualified_name` would be "foo".
/// Ex) Given `import foo as bar`, `qualified_name` would be "foo".
pub qualified_name: &'a str,
}
/// A binding for a member imported from a module, keyed on the name to which the member is bound.
@ -252,9 +254,9 @@ pub struct Importation<'a> {
#[derive(Clone, Debug)]
pub struct FromImportation {
/// The full name of the member being imported.
/// Ex) Given `from foo import bar`, `full_name` would be "foo.bar".
/// Ex) Given `from foo import bar as baz`, `full_name` would be "foo.bar".
pub full_name: String,
/// Ex) Given `from foo import bar`, `qualified_name` would be "foo.bar".
/// Ex) Given `from foo import bar as baz`, `qualified_name` would be "foo.bar".
pub qualified_name: String,
}
/// A binding for a submodule imported from a module, keyed on the name of the parent module.
@ -262,8 +264,8 @@ pub struct FromImportation {
#[derive(Clone, Debug)]
pub struct SubmoduleImportation<'a> {
/// The full name of the submodule being imported.
/// Ex) Given `import foo.bar`, `full_name` would be "foo.bar".
pub full_name: &'a str,
/// Ex) Given `import foo.bar`, `qualified_name` would be "foo.bar".
pub qualified_name: &'a str,
}
#[derive(Clone, Debug, is_macro::Is)]