Skip to content

Commit

Permalink
properties: Automatically generate getters/setters if prop.version < …
Browse files Browse the repository at this point in the history
…getter.version
  • Loading branch information
bilelmoussaoui committed Jun 3, 2024
1 parent 0d4f288 commit ffa4012
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions src/analysis/properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,8 @@ fn analyze_property(
let has_setter =
setter_func.is_some_and(|s| matches!(s.status, GStatus::Generate | GStatus::Manual));

let getter = if readable && !has_getter {
let getter = if readable && (!has_getter || prop.version < getter_func.and_then(|g| g.version))
{
if let Ok(rust_type) = RustType::builder(env, prop.typ)
.direction(library::ParameterDirection::Out)
.try_build()
Expand All @@ -245,6 +246,17 @@ fn analyze_property(
imports.add("glib::prelude::*");
}

let mut getter_version = prop_version;
if has_getter {
let getter = getter_func.unwrap();
get_func_name = getter.new_name.as_ref().unwrap_or(&getter.name).to_string();
get_prop_name = Some(getter.name.clone());
getter_version = getter.version.map(|mut g| {
g.as_opposite();
g
});
}

Some(Property {
name: name.clone(),
var_name: nameutil::mangle_keywords(&*name_for_func).into_owned(),
Expand All @@ -257,14 +269,15 @@ fn analyze_property(
set_in_ref_mode,
set_bound: None,
bounds: Bounds::default(),
version: prop_version,
version: getter_version,
deprecated_version: prop.deprecated_version,
})
} else {
None
};

let setter = if writable && !has_setter {
let setter = if writable && (!has_setter || prop.version < setter_func.and_then(|s| s.version))
{
if let Ok(rust_type) = RustType::builder(env, prop.typ)
.direction(library::ParameterDirection::In)
.try_build()
Expand All @@ -286,6 +299,17 @@ fn analyze_property(
}
}

let mut setter_version = prop_version;
if has_setter {
let setter = setter_func.unwrap();
set_func_name = setter.new_name.as_ref().unwrap_or(&setter.name).to_string();
set_prop_name = Some(setter.name.clone());
setter_version = setter.version.map(|mut s| {
s.as_opposite();
s
});
}

Some(Property {
name: name.clone(),
var_name: nameutil::mangle_keywords(&*name_for_func).into_owned(),
Expand All @@ -298,7 +322,7 @@ fn analyze_property(
set_in_ref_mode,
set_bound,
bounds: Bounds::default(),
version: prop_version,
version: setter_version,
deprecated_version: prop.deprecated_version,
})
} else {
Expand Down

0 comments on commit ffa4012

Please sign in to comment.