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: fix: Fix the insertion order for CtCaseImpl.insertBegin #4063

Merged
merged 15 commits into from
Aug 9, 2021
Merged

review: fix: Fix the insertion order for CtCaseImpl.insertBegin #4063

merged 15 commits into from
Aug 9, 2021

Conversation

Rohitesh-Kumar-Jain
Copy link
Contributor

@Rohitesh-Kumar-Jain Rohitesh-Kumar-Jain commented Jul 26, 2021

WIP

Fix #4060

Also, this test is killing this mutation

Screenshot 2021-07-26 at 11 32 58 AM

link to #3967

@Rohitesh-Kumar-Jain Rohitesh-Kumar-Jain changed the title WIP: fix: Fix the insertion order for CtCaseImpl.insertBegin review: fix: Fix the insertion order for CtCaseImpl.insertBegin Jul 26, 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.

Implementation LGTM. The test can be improved.

First of all, like I mentioned in another review, we don't typically test the specific implementations directly, and in fact you're not testing CtCaseImpl directly here. We rely on the factories to create the implementations for us. There is already a test class for cases (called SwitchCaseTest for some reason instead of CtCaseTest, we should rename that). Put the test in there.

Second, the indentation in the test class is incorrect (should be tabs). Make sure that the test case, when moved, has tabs as indentation.

See also the comments on the code.

src/test/java/spoon/test/ctCase/CtCaseImplTest.java Outdated Show resolved Hide resolved
src/test/java/spoon/test/ctCase/CtCaseImplTest.java Outdated Show resolved Hide resolved
src/test/java/spoon/test/ctCase/CtCaseImplTest.java Outdated Show resolved Hide resolved
src/test/java/spoon/test/ctCase/CtCaseImplTest.java Outdated Show resolved Hide resolved
src/test/java/spoon/test/ctCase/CtCaseImplTest.java Outdated Show resolved Hide resolved
Rohitesh-Kumar-Jain and others added 4 commits July 26, 2021 17:44
Co-authored-by: Simon Larsén <slarse@kth.se>
Co-authored-by: Simon Larsén <slarse@kth.se>
Co-authored-by: Simon Larsén <slarse@kth.se>
Co-authored-by: Simon Larsén <slarse@kth.se>
@Rohitesh-Kumar-Jain
Copy link
Contributor Author

There is already a test class for cases (called SwitchCaseTest for some reason instead of CtCaseTest, we should rename that). Put the test in there.

Yeah it should be there, also I will migrate it along with the other test I am working parallel

Second, the indentation in the test class is incorrect (should be tabs). Make sure that the test case, when moved, has tabs as indentation.

Yeah, sure IDEs have an auto refactoring feature for I will use that to get the best tab spacing

}
List<CtStatement> copy = new ArrayList<>(statements.getStatements());
statements.setStatements(null);
this.statements.addAll(0, copy);
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 how important this is, but the addStatement(int, CtStatement) method does a little bit more:
a) it calls statement.setParent(this); for each CtStatement
b) it calls onListAdd

I think it is necessary to loop over all statements to add at some point to keep that behavior. I'm not sure if List#addAll(int, Collection) is still prefered then.
@slarse WDYT?

Copy link
Collaborator

Choose a reason for hiding this comment

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

You're absolutely right. I just had it in my mind that the statement list here was a model list (as it is in CtBlockImpl), but it's not. It's just an ArrayList.

It seems to me like the statement and expression lists in CtCaseImpl should be model lists as well, but I'm not sure about the design decision for them not being so currently. It could simply be that model lists were introduced at a later time, and were never added to CtCaseImpl. I think I'll want to wait for @monperrus or @nharrand to weigh in there before we proceed.

@Rohitesh-Kumar-Jain Can you add assertions to check that the parents of the inserted statements are set correctly? Something like so:

        assertThat(firstStatementToBeInserted.getParent(), is(testCase));
        assertThat(secondStatementToBeInserted.getParent(), is(testCase));

Note the use of identity (is) as opposed to equality.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes I have added these tests as well

@Rohitesh-Kumar-Jain
Copy link
Contributor Author

Second, the indentation in the test class is incorrect (should be tabs). Make sure that the test case, when moved, has tabs as indentation.

I don't get this one, also I ran IntelliJ's auto code reformat, but it failed to detect what are you pointing at ig

@Rohitesh-Kumar-Jain
Copy link
Contributor Author

@slarse I have implemented all the suggested changes except for this

Second, the indentation in the test class is incorrect (should be tabs).

I am not able to understand this one

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.

@Rohitesh-Kumar-Jain Nice fix, looks good to me.

Second, the indentation in the test class is incorrect (should be tabs).

I am not able to understand this one

When you create a new file with IntelliJ, the default is to create it with spaces as indentation. If you look at your first commit, the test class has spaces as indentation. If you just run auto-formatting on that, it will still format with spaces.

When you pasted the test case into the existing test class, IntelliJ detected the use of tabs and changed the indentation automatically.

@slarse slarse merged commit e4bb8d4 into INRIA:master Aug 9, 2021
@Rohitesh-Kumar-Jain Rohitesh-Kumar-Jain deleted the fix-bug-4060 branch August 9, 2021 08:54
@Rohitesh-Kumar-Jain
Copy link
Contributor Author

When you pasted the test case into the existing test class, IntelliJ detected the use of tabs and changed the indentation automatically.

Thanks for letting me, and I hope you enjoyed your vacations and the Olympics matches : )

@slarse
Copy link
Collaborator

slarse commented Aug 9, 2021

When you pasted the test case into the existing test class, IntelliJ detected the use of tabs and changed the indentation automatically.

Thanks for letting me, and I hope you enjoyed your vacations and the Olympics matches : )

Vacations: yes. Olympics: I'm just about vaguely aware they exist :)

@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.

bug: insertBegin method is inserting list in reverse order than it should be
4 participants
  NODES
COMMUNITY 2
Note 1
Project 3
USERS 1