Index: TODO =================================================================== diff -u -rcc9032518f095207cd1832ae5b4202e0ace96c71 -r7257200f41c3bd0d0309db6932e5788d860fa119 --- TODO (.../TODO) (revision cc9032518f095207cd1832ae5b4202e0ace96c71) +++ TODO (.../TODO) (revision 7257200f41c3bd0d0309db6932e5788d860fa119) @@ -3057,17 +3057,26 @@ - set only fresh variables via per-object method "variable" and "attribute" - added flag -concomplain to per-object method "variable" and "attribute" - extended regression test +- added support for "class variable" +- added tests for "variable" + multiplicity and "class variable" - TODO: - provide warning, when method variable is a noop (e.g. no value provided and no accessor is wanted) - - add test for class-level variable - should we change interface for default value in attribute? probably not, same interface is used in methodparameters as well - - we could rename "attribute" to "property" to make distinction between - "variable" and "attribute/property" as well ("a property is a - variable with accessors") + - Should we leave "variable" and "attribute" as it ist? + options: + (a) leave it as it is + (b) use "property" instead of "attribute" + ("a property is a variable with accessors"), + some tribute to beans terminology + (c) use "parameter" instead of "attribute", + since providing accessors means make the + variable an object parameter + (d) use "attribute" instead of "variable" + Variable is the tcl term, attribute is the UML term + (e) others? - call user defined setter in object parameters? - maybe use (position == -1) instead of (objectparameter == false) to save common vars Index: library/nx/nx.tcl =================================================================== diff -u -rcc9032518f095207cd1832ae5b4202e0ace96c71 -r7257200f41c3bd0d0309db6932e5788d860fa119 --- library/nx/nx.tcl (.../nx.tcl) (revision cc9032518f095207cd1832ae5b4202e0ace96c71) +++ library/nx/nx.tcl (.../nx.tcl) (revision 7257200f41c3bd0d0309db6932e5788d860fa119) @@ -219,7 +219,7 @@ # method-modifier for object specific methos :method class {what args} { - if {$what in [list "alias" "attribute" "forward" "method"]} { + if {$what in [list "alias" "attribute" "forward" "method" "variable"]} { return [::nsf::object::dispatch [::nsf::self] ::nsf::classes::nx::Object::$what {*}$args] } if {$what in [list "info"]} { @@ -1673,13 +1673,13 @@ } nx::Class method variable { - {-class ""} - {-initblock ""} - {-objectparameter false} - {-accessor false} - spec - default:optional - } { + {-class ""} + {-initblock ""} + {-objectparameter false} + {-accessor false} + spec + default:optional + } { #puts stderr "Class variable $spec" set slot [::nx::MetaSlot createFromParameterSpec [::nsf::self] \ -class $class \ Index: tests/parameters.test =================================================================== diff -u -rcc9032518f095207cd1832ae5b4202e0ace96c71 -r7257200f41c3bd0d0309db6932e5788d860fa119 --- tests/parameters.test (.../parameters.test) (revision cc9032518f095207cd1832ae5b4202e0ace96c71) +++ tests/parameters.test (.../parameters.test) (revision 7257200f41c3bd0d0309db6932e5788d860fa119) @@ -1847,8 +1847,36 @@ ? [list [self] variable x1:int 1] {Object ::enterprise has already an instance variable named 'x1'} ? [list [self] attribute [list x2:int 2]] {Object ::enterprise has already an instance variable named 'x2'} + # set variable with a value checker, multiple + ? [list [self] variable -nocomplain xm1:int,1..n {1 2 3}] "" + ? [list [self] attribute -nocomplain [list xm2:int,1..n {1 2 3}]] "::enterprise::xm2" + + # in both cases, we expect instance variables + ? [list [self] eval {set :xm1}] "1 2 3" + ? [list [self] eval {set :xm2}] "1 2 3" + + # set variable with a value checker, multiple with invalid value + ? [list [self] variable -nocomplain xm1:int,1..n {1 2a 3}] \ + {invalid value in "1 2a 3": expected integer but got "2a"} + ? [list [self] attribute -nocomplain [list xm2:int,1..n {1 2a 3}]] \ + {invalid value in "1 2a 3": expected integer but got "2a"} + # more tests, e.g. multiplicity and user-defined type # incremental, } + nx::Class create C { + # set 2 variables, one via variable, one via attribute + ? [list [self] class variable -nocomplain v "v0"] "" + ? [list [self] class attribute -nocomplain [list a "a0"]] "::C::a" + + # in both cases, we expect instance variables + ? [list [self] eval {set :v}] "v0" + ? [list [self] eval {set :a}] "a0" + + # check variable with value constraint + ? [list [self] class variable -nocomplain x:int "0"] "" + ? [list [self] class variable -nocomplain y:int "a0"] {expected integer but got "a0"} + } + } \ No newline at end of file