-
-
Notifications
You must be signed in to change notification settings - Fork 354
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
fix: removed annotation should not appear in sniper mode #4284
Conversation
@slarse Any idea what certificate are the workflows talking about? |
@algomaster99 Looks like someone forgot to renew a domain name, restarting the workflow. |
You mean this domain - spoon.gforge.inria.fr ? |
@monperrus ping for reviews. |
return (E) this; | ||
} | ||
getFactory().getEnvironment().getModelChangeListener().onListDeleteAll(this, CtRole.ANNOTATION, this.annotations, new ArrayList<>(this.annotations)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't seem right to me. The list is cleared on the next line, but the listener is not called now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested this. If you delete any number of annotations, it registers what annotations need to be added (the ones which are left after deletion) in the for-loop which follows.
So while pretty-printing it, only those are printed which are registered in the model. And they are exactly the ones we need.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested this. If you delete any number of annotations, it registers what annotations need to be added (the ones which are left after deletion) in the for-loop which follows.
Well, the problem I see is that if you set a non-empty list of annotations, then the change listener is only informed of additions. I'm not certain of precisely how this plays with the sniper printer, but this is strictly incorrect. Don't think of this in terms of the sniper printer alone (the change listener interface knows nothing of the sniper printer), but in a general sense: If the list is cleared, onListDeleteAll
must be called, because all elements were deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't think of this in terms of the sniper printer alone (the change listener interface knows nothing of the sniper printer),
Okay, I get what you are trying to say, and this makes sense. The listener could be used for something else in future, and "If the list is cleared, onListDeleteAll must be called" might be necessary there. I think this was just a fortuitous event in the case of sniper printer.
I will revert the deletion.
@monperrus @slarse I think this is ready for merge. Just as a note - changes like 1bdf92b would also be needed in methods like setTypeMembers. |
@monperrus The order of registering an event listener and performing the action doesn't matter for getFactory().getEnvironment().getModelChangeListener().onListDeleteAll(this, CtRole.ANNOTATION, this.annotations, new ArrayList<>(this.annotations));
this.annotations.clear(); and this.annotations.clear();
getFactory().getEnvironment().getModelChangeListener().onListDeleteAll(this, CtRole.ANNOTATION, this.annotations, new ArrayList<>(this.annotations)); are the same thing for registering a change in a Therefore, it is hard to assert the difference in change collector before and after the transformation because both of the above cases will have the same effect. Maybe, we could try writing a test case which invokes ActionBasedChangeListener.onListDeleteAll instead of |
* The order doesn't matter because the `oldValue` is just ignored.
@monperrus
I say, that we skip writing test for now because it will only improve the robustness of For this PR, let's move forward with merging it. I have followed the contract of the listener and made changes in accordance with that. |
Thanks a lot @algomaster99 for the fix and @slarse for spotting the unspecified behavior. Per our discussion today, @algomaster99 will open an issue and a PR later on properly specifying and testing onDelete methods |
Duplicate of #4282
Fixes #4218
Opening this PR again in the hope that the tests will pass. Some weird issue came in the linked PR.