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
Reduce duplicated code in ContractsUtils #2985
Conversation
Although this is a breaking refactor, I would like to merge it when it passes review because it simplifies fixing #1307. |
@@ -3244,8 +3245,8 @@ private void checkPreAndPostConditions() { | |||
|
|||
// Check postconditions | |||
ContractsUtils contracts = ContractsUtils.getInstance(atypeFactory); | |||
Set<Postcondition> superPost = contracts.getPostconditions(overridden.getElement()); | |||
Set<Postcondition> subPost = contracts.getPostconditions(overrider.getElement()); | |||
Set<Contract> superPost = contracts.getPostconditions(overridden.getElement()); |
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.
@mernst Did you get to try to improve the return types of these methods? It would be nicer if these methods and the code above didn't use the general Contract
and casts and instead used the more precise types.
You can probably achieve this by having helper methods that have a generic return type and then the existing methods are simple wrappers around the generic method, with the precise return type.
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.
@wmdietl I did not do so.
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.
Feel free to make that change in a subsequent pull request. Thanks!
I'm merging this because it has been open over a week. |
The main change here is to change
getPreconditions
andgetPostconditions
andgetConditionalPostconditions
, which had a lot of duplicated code, into one-line calls to a single generalized method.Also,
Contract
is moved to its own file just to keepContractsUtils
from being too long and unweildy, and I added some fields toContract
.