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

Reduce duplicated code in ContractsUtils #2985

Merged
merged 13 commits into from Dec 22, 2019

Conversation

mernst
Copy link
Member

@mernst mernst commented Dec 16, 2019

The main change here is to change getPreconditions and getPostconditions and getConditionalPostconditions, 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 keep ContractsUtils from being too long and unweildy, and I added some fields to Contract.

@smillst smillst added the Breaking change Breaks some clients. Requires minor version number increase (middle number in the version number). label Dec 16, 2019
@mernst
Copy link
Member Author

mernst commented Dec 16, 2019

Although this is a breaking refactor, I would like to merge it when it passes review because it simplifies fixing #1307.

@smillst smillst removed their assignment Dec 17, 2019
@@ -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());
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member Author

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!

@wmdietl wmdietl assigned mernst and unassigned wmdietl Dec 22, 2019
@mernst mernst assigned wmdietl and unassigned mernst Dec 22, 2019
@mernst
Copy link
Member Author

mernst commented Dec 22, 2019

I'm merging this because it has been open over a week.

@mernst mernst merged commit 0617923 into typetools:master Dec 22, 2019
@mernst mernst deleted the contractsutils-refactor-2 branch December 22, 2019 20:54
wmdietl added a commit to wmdietl/checker-framework that referenced this pull request Jan 2, 2020
smillst pushed a commit that referenced this pull request Jan 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Breaking change Breaks some clients. Requires minor version number increase (middle number in the version number).
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants