Is it possible to distinguish zero value and value absence for integer property?

As far as I understand, integer property is compiled to an int field. But when I set "allow empty" to true in its editor, there are two different valid cases in editor: 0 and <no value>. In both cases property value is 0. Is there any way to differ these cases? Or the only solution is to wrap property in the separate concept?
Comment actions Permalink

I would love to follow-up on this question: we want to check whether an integer property is set. To do that, we use the SModel-API:

SProperty property = property/Concept : intProperty/;

This works fine, when the property was never set. However, if the property was once set and was afterwards deleted, I will get the original value (even if the editor does state <no intProperty>). I also checked the code generation and actually the code generation gets also the original value returned. Is this a bug?



Comment actions Permalink

I'd like to know the official response from JetBrains here as well. When the editor shows a red block for the property, the value is empty. Once it has been set, the old value 'remains' in the AST somehow, so the generator picks it up.

I would assume that it is possible to distinguish between optional properties and required properties, and also give the user feedback in these cases.

Comment actions Permalink

By default, a property cell is set to disallow empty values. So when you delete the value the cell becomes invalid and will not store ("commit") this invalid value to the AST.

If you set the property cell to allow empty values you will be able to delete the value, the cell will become grey and the empty value will be stored in the AST.

Comment actions Permalink

Yeah, I guess that's where the 'disconnect' between expectations and feedback is really at:

1. When no value has ever been set, the property does return null, and the cell is typically shown as red background

2. When some value has been set, but removed, the old value is not overwritten in the AST until a new value is written

IMHO in case 1, the model checker should catch it, and provide a warning in the model checking action. It does not currently do that. For integers, the value returns 0 if never set (but you can check whether it was ever set using the getProperty API as above), and for strings, it returns null (not empty string). This is confusing behaviour.

IMHO in case 2, the feedback to the user is not ideal; it is only a temporary error (i.e., while editing)

However, when you close and reopen the editor after removing the values (for a string as well as for an int), the values are still set in the AST (, but they still show up as empty!

All in all, I believe that the model checker should catch these unset, but not allowed empty, kind of properties. I do understand that this is editor behaviour currently, but it would make more sense to me if 'allow empty' was part of the structure of the concept and not of an editor of the concept... Especially the way it is implemented now makes me wonder whether this behavior was intentional, or evolved over time.


Please sign in to leave a comment.