Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

review: doc: add documentation for CtCase #4039

Merged
merged 6 commits into from
Jul 18, 2021
Merged

Conversation

andrewbwogi
Copy link
Contributor

No description provided.

@@ -52,7 +52,7 @@
List<CtExpression<S>> getCaseExpressions();

/**
* Sets the case expressions.
* Sets the case expressions. If set with null, the 'default' construct will be used instead of 'case'.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand what's meant by this. What is 'default' construct, and what is 'case'?

Do you mean that one can empty the case expressions by setting with null?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

switch (var) {
            case 1:
                a = 1;
            default:
                a = 2;
}

There are two statements in this switch block using two different kinds of labels. If setCaseExpressions is set with null, the default label is used for the CtCase, otherwise the case label is used. Maybe the last sentence is the one that should be in the doc, using the word 'label' instead of 'construct'. Is it clearer?

We could add a setDefault(boolean b) method to CtCase but I'm not sure if isDefault() == false && getCaseExpressions() == null is an acceptable state.

Copy link
Collaborator

@slarse slarse Jul 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, now I understand what you mean. Yes, using the word "label" is clearer.

I would however not say "is used", because that raises the question "is used for what?". I think the intent here is that, if set with null or an empty list, the CtCase represents the default label. Otherwise, it represents a case label.

This is design is not intuitive IMO, the default label is syntactically distinct from the case label and so should be its own metamodel element. But I don't think there's a good enough reason to change this, and as you noted, adding a setDefault(boolean) may cause the invalid state where a default label has case expressions (well you said the opposite but I think that's what you meant!).

Arguably, we could add a parameterless setDefault() which simply delegates to setCaseExpression(null) and thus wouldn't be breaking. But the docs need to be updated regardless.

Note also that setCaseExpression(null) has the same effect, so it should also be documented.

Copy link
Contributor Author

@andrewbwogi andrewbwogi Jul 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm skeptical about setDefault() because it has an unexpected side-effect of removing the case expression(s). It would add confusion to an already confusing interface.

Copy link
Collaborator

@slarse slarse Jul 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I don't think we want to make this any more convoluted than it already is. It was just an idea for a non-breaking change.

If we were to go ahead with a breaking change however, I think that the way to go would be to have a distinct CtDefault as a subtype of CtCase.

Copy link
Collaborator

@slarse slarse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment.

src/main/java/spoon/reflect/code/CtCase.java Outdated Show resolved Hide resolved
@andrewbwogi andrewbwogi changed the title review: doc: add documentation for CtCase doc: add documentation for CtCase Jul 18, 2021
@andrewbwogi andrewbwogi changed the title doc: add documentation for CtCase review: doc: add documentation for CtCase Jul 18, 2021
Copy link
Collaborator

@slarse slarse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks @andrewbwogi!

@slarse slarse merged commit f85ebe5 into INRIA:master Jul 18, 2021
@monperrus monperrus mentioned this pull request Aug 19, 2021
woutersmeenk pushed a commit to woutersmeenk/spoon that referenced this pull request Aug 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants