mirror of
https://gitlab.gnome.org/jwestman/blueprint-compiler.git
synced 2025-05-04 15:59:08 -04:00
validation: Writable/construct-only properties
Add two new errors, one for non-writable properties and another for binding construct-only properties.
This commit is contained in:
parent
3b39e0d541
commit
f78478bea1
5 changed files with 31 additions and 1 deletions
|
@ -184,6 +184,14 @@ class Property(GirNode):
|
||||||
def signature(self):
|
def signature(self):
|
||||||
return f"{self.type_name} {self.container.name}.{self.name}"
|
return f"{self.type_name} {self.container.name}.{self.name}"
|
||||||
|
|
||||||
|
@property
|
||||||
|
def writable(self):
|
||||||
|
return self.xml["writable"] == "1"
|
||||||
|
|
||||||
|
@property
|
||||||
|
def construct_only(self):
|
||||||
|
return self.xml["construct-only"] == "1"
|
||||||
|
|
||||||
|
|
||||||
class Parameter(GirNode):
|
class Parameter(GirNode):
|
||||||
def __init__(self, container: GirNode, xml: xml_reader.Element):
|
def __init__(self, container: GirNode, xml: xml_reader.Element):
|
||||||
|
|
|
@ -29,7 +29,7 @@ class Property(AstNode):
|
||||||
Statement(
|
Statement(
|
||||||
UseIdent("name"),
|
UseIdent("name"),
|
||||||
":",
|
":",
|
||||||
"bind",
|
Keyword("bind"),
|
||||||
UseIdent("bind_source").expected("the ID of a source object to bind from"),
|
UseIdent("bind_source").expected("the ID of a source object to bind from"),
|
||||||
".",
|
".",
|
||||||
UseIdent("bind_property").expected("a property name to bind from"),
|
UseIdent("bind_property").expected("a property name to bind from"),
|
||||||
|
@ -85,6 +85,19 @@ class Property(AstNode):
|
||||||
did_you_mean=(self.tokens["name"], self.gir_class.properties.keys())
|
did_you_mean=(self.tokens["name"], self.gir_class.properties.keys())
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@validate("bind")
|
||||||
|
def property_bindable(self):
|
||||||
|
if self.tokens["bind"] and self.gir_property is not None and self.gir_property.construct_only:
|
||||||
|
raise CompileError(
|
||||||
|
f"{self.gir_property.full_name} can't be bound because it is construct-only",
|
||||||
|
hints=["construct-only properties may only be set to a static value"]
|
||||||
|
)
|
||||||
|
|
||||||
|
@validate("name")
|
||||||
|
def property_writable(self):
|
||||||
|
if self.gir_property is not None and not self.gir_property.writable:
|
||||||
|
raise CompileError(f"{self.gir_property.full_name} is not writable")
|
||||||
|
|
||||||
|
|
||||||
@validate()
|
@validate()
|
||||||
def obj_property_type(self):
|
def obj_property_type(self):
|
||||||
|
|
6
tests/sample_errors/read_only_properties.blp
Normal file
6
tests/sample_errors/read_only_properties.blp
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
using Gtk 4.0;
|
||||||
|
|
||||||
|
ComboBox combo_box {
|
||||||
|
has-entry: bind combo_box.visible;
|
||||||
|
scale-factor: 2;
|
||||||
|
}
|
2
tests/sample_errors/read_only_properties.err
Normal file
2
tests/sample_errors/read_only_properties.err
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
4,14,4,ComboBox.has-entry can't be bound because it is construct-only
|
||||||
|
5,3,12,Widget.scale-factor is not writable
|
|
@ -190,6 +190,7 @@ class TestSamples(unittest.TestCase):
|
||||||
self.assert_sample_error("obj_in_string_list")
|
self.assert_sample_error("obj_in_string_list")
|
||||||
self.assert_sample_error("obj_prop_type")
|
self.assert_sample_error("obj_prop_type")
|
||||||
self.assert_sample_error("property_dne")
|
self.assert_sample_error("property_dne")
|
||||||
|
self.assert_sample_error("read_only_properties")
|
||||||
self.assert_sample_error("signal_dne")
|
self.assert_sample_error("signal_dne")
|
||||||
self.assert_sample_error("signal_object_dne")
|
self.assert_sample_error("signal_object_dne")
|
||||||
self.assert_sample_error("size_group_non_widget")
|
self.assert_sample_error("size_group_non_widget")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue