-
-
Notifications
You must be signed in to change notification settings - Fork 352
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 bug related to "insertBefore()" and "getSignature()" #450
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -230,6 +230,9 @@ public void visitCtBreak(CtBreak breakStatement) { | |
public <E> void visitCtCase(CtCase<E> caseStatement) { | ||
write("case ("); | ||
scan(caseStatement.getCaseExpression()); | ||
for (CtStatement statement : caseStatement.getStatements()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no scan method for List There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
scan(statement); | ||
} | ||
write(")"); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,11 +3,14 @@ | |
import org.junit.Test; | ||
import spoon.Launcher; | ||
import spoon.SpoonException; | ||
import spoon.reflect.code.CtSwitch; | ||
import spoon.reflect.declaration.CtClass; | ||
import spoon.reflect.declaration.CtConstructor; | ||
import spoon.reflect.declaration.CtMethod; | ||
import spoon.reflect.visitor.filter.TypeFilter; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.fail; | ||
import static spoon.test.TestUtils.build; | ||
|
||
|
@@ -41,6 +44,20 @@ public void testInsertBegin() throws Exception { | |
+ constructor.getSimpleName(), "int i = 0;", | ||
constructor.getBody().getStatement(1).toString()); | ||
} | ||
|
||
CtConstructor<?> constructor = type.getConstructor(type.getFactory().Type().INTEGER_PRIMITIVE); | ||
String myBeforeStatementAsString = "int before"; | ||
for (CtSwitch<?> ctSwitch : constructor.getElements(new TypeFilter<CtSwitch<?>>(CtSwitch.class))) { | ||
ctSwitch.insertBefore(type.getFactory().Code() | ||
.createCodeSnippetStatement(myBeforeStatementAsString)); | ||
} | ||
assertEquals("insert has not been done at the right position", myBeforeStatementAsString, constructor.getBody().getStatement(3).toString()); | ||
assertEquals("insert has not been done at the right position", myBeforeStatementAsString, constructor.getBody().getStatement(5).toString()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is not the switch, it is the statement I add in the ForLoop above. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If a copy paste the constructor here: public SampleForInsertBefore(int j) {
this(j, 0);
new Thread() {
};
switch (j) {
default:
break;
}
switch (j) {
default:
break;
}
switch (j) {
default: {
break;
}
} We can see that the position 5 is a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, the statement 5 is not a break, because getStatements only returns the statements which have the method block as parent. |
||
assertEquals("insert has not been done at the right position", myBeforeStatementAsString, constructor.getBody().getStatement(7).toString()); | ||
|
||
assertFalse("switch should not be the same", constructor.getBody().getStatement(6).equals(constructor.getBody().getStatement(8))); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This assertion was red before your fix? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes |
||
assertFalse("switch should not be the same", constructor.getBody().getStatement(6).toString().equals(constructor.getBody().getStatement(8).toString())); | ||
|
||
} | ||
|
||
@Test | ||
|
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.
oops? indentation with tabs? (this is the cause of travis' failure)
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.
Hi,
I just tried to use the formatter included with the spoon' repository ( SpoonFormatterPrefs.xml ), however when I apply it to the project, 458 files are modified. Do you really use this formatter ?
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.
Nope: #393