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
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 13 additions & 14 deletions src/test/java/spoon/test/ctCase/CtCaseImplTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,16 @@ void testInsertBeginWithListOfStatements() {
// exiting statements, and the order of statements in the list remains the same

// arrange
CtClass classWithSwitchExample = getClassWithSwitchExample();
CtStatement firstStatementToBeInserted = createStatement(classWithSwitchExample, "firstStatement");
CtStatement secondStatementToBeInserted = createStatement(classWithSwitchExample, "secondStatement");
CtCase testCase = classWithSwitchExample.getElements(new TypeFilter<>(CtCase.class)).get(0);

CtStatementList ctStatementList = new CtStatementListImpl<CtStatement>() {
{
addStatement(firstStatementToBeInserted);
addStatement(secondStatementToBeInserted);
}
};
Factory factory = new Launcher().getFactory();
CtCase<?> testCase = factory.createCase();
testCase.addStatement(factory.createCodeSnippetStatement("int preexisting = 42;").compile());

CtStatement firstStatementToBeInserted = factory.createCodeSnippetStatement("int first = 1;").compile();
CtStatement secondStatementToBeInserted = factory.createCodeSnippetStatement("int second = 2;").compile();

CtStatementList statementList = factory.createStatementList();
statementList.addStatement(firstStatementToBeInserted);
statementList.addStatement(secondStatementToBeInserted);

// act
testCase.insertBegin(ctStatementList);
Expand All @@ -52,7 +51,7 @@ private static CtClass getClassWithSwitchExample() {
return spoon.getFactory().Class().get(ClassWithSwitchExample.class);
}

public static CtStatement createStatement(CtClass ctClass, String Statement) {
return ctClass.getFactory().Code().createCodeSnippetStatement(Statement);
public static CtStatement createStatement(CtClass ctClass, String statement) {
return ctClass.getFactory().Code().createCodeSnippetStatement(Statement).compile();
}
}
}
  NODES
COMMUNITY 2
Note 1
Project 2
USERS 1