Skip to content

DSL type conversion documentation is difficult to understand #2732

Description

@Nadahar

I'm trying to work on #2728 to document some of the new possibilities that have recently been added to DSL rules/scripts. I have to try to figure out where to put the new information in the existing documentation, and I'm having some trouble in that department too. But, this is about one particular section:

The different syntax for the generic and the objective-specific differs and is given in the table below:

Generic (Action) Specific (Method)
postUpdate(MyItem, new_state) MyItem.postUpdate(new_state)
sendCommand(MyItem, new_state) MyItem.sendCommand(new_state)

The benefit of using Objects over primitives is apparent through the following type conversions that are automatically invoked by Object as the context requires.
Using the method MyItems.sendCommand() that is owned by MyItem will use the sendCommand method that is suitable to make the necessary type conversions.
For example, the NumberItem class would have a sendCommand(int), sendCommand(long), sendCommand(float), sendCommand(double), sendCommand(Number), sendCommand(DecimalType), and sendCommand(String) method.
Each of these separate methods is individually written to handle all of these different types of Objects.
MyItem will automatically apply the method that corresponds to the argument type.

I've read it over and over, and I can't get it to make sense. I would think that, when I'm in a position that I can add to the documentation, I should be able to understand what's there. I also question what I think it suggests, that only the extension form supports autoboxing of Number primitives (if that's what it's actually trying to say). I find methods like this in BusEventImpl, which should be able to signature match either "form":

    @Override
    public void sendCommand(Item item, Number command) {
        sendCommand(item, command, null);
    }

Unless Xtext is doing something really weird here, standard Java logic would be that e.g. an int can be autoboxed into Integer, which is a Number, so it will do the autoboxing and then invoke that method.

The explanation seems to come from #483 and be (at least partially) based on this forum thread. I can't however find what I consider "the confusing part" in the forum post.

I don't "have to" understand this section to do what I'm trying to do, I can just leave it be and pretend that everybody else understand it, but I know from experience that if I can't understand something, I'm usually not alone.

@rkoshak Do you have anything to add here, being the author of the "source forum post"?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions