use of com.github.javaparser.printer.concretesyntaxmodel.CsmIndent in project javaparser by javaparser.
the class DifferenceTest method addingStatementToEmptyMethodBody.
@Test
public void addingStatementToEmptyMethodBody() {
String code = "class A { void foo(char p1, int p2) {} }";
considerCode(code);
Statement s = new ExpressionStmt(new BinaryExpr(new IntegerLiteralExpr("10"), new IntegerLiteralExpr("2"), BinaryExpr.Operator.PLUS));
MethodDeclaration m = cu.getClassByName("A").get().getMethodsByName("foo").get(0);
LexicalDifferenceCalculator.CalculatedSyntaxModel csmOriginal = new LexicalDifferenceCalculator().calculatedSyntaxModelForNode(m.getBody().get());
LexicalDifferenceCalculator.CalculatedSyntaxModel csmChanged = new LexicalDifferenceCalculator().calculatedSyntaxModelAfterListAddition(m.getBody().get(), ObservableProperty.STATEMENTS, 0, s);
Difference diff = Difference.calculate(csmOriginal, csmChanged);
int i = 0;
assertEquals(Difference.DifferenceElement.kept(new CsmToken(GeneratedJavaParserConstants.LBRACE)), diff.getElements().get(i++));
assertEquals(Difference.DifferenceElement.kept(new CsmToken(eolTokenKind())), diff.getElements().get(i++));
assertEquals(Difference.DifferenceElement.added(new CsmIndent()), diff.getElements().get(i++));
assertEquals(Difference.DifferenceElement.added(new CsmChild(s)), diff.getElements().get(i++));
assertEquals(Difference.DifferenceElement.added(new CsmToken(eolTokenKind())), diff.getElements().get(i++));
assertEquals(Difference.DifferenceElement.added(new CsmUnindent()), diff.getElements().get(i++));
assertEquals(Difference.DifferenceElement.kept(new CsmToken(GeneratedJavaParserConstants.RBRACE)), diff.getElements().get(i++));
assertEquals(i, diff.getElements().size());
}
Aggregations