Skip to content

Commit

Permalink
fix: EOL were not fully taken into account in Spoon (#2122)
Browse files Browse the repository at this point in the history
  • Loading branch information
surli authored and pvojtechovsky committed Jun 27, 2018
1 parent 45c65b5 commit 34346a6
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/main/java/spoon/pattern/internal/PatternPrinter.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public String printNode(RootNode node) {
List<Object> generated = generateTargets(node, (ImmutableMap) null, null);
StringBuilder sb = new StringBuilder();
for (Object ele : generated) {
sb.append(ele.toString()).append('\n');
sb.append(ele.toString()).append(System.getProperty("line.separator"));
}
return sb.toString();
}
Expand Down
5 changes: 3 additions & 2 deletions src/test/java/spoon/test/api/MetamodelTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ public void testRoleOnField() {
implementations.addInputResource("src/main/java/spoon/support/reflect");
implementations.buildModel();

String nl = System.getProperty("line.separator");
Factory factory = implementations.getFactory();

CtTypeReference metamodelPropertyField = factory.Type().get(MetamodelPropertyField.class).getReference();
Expand Down Expand Up @@ -179,8 +180,8 @@ public boolean matches(CtField candidate) {
}
}).stream().map(x -> {result.add(x.toString()); return x;}).filter(f -> f.getAnnotation(metamodelPropertyField) == null).collect(Collectors.toList());

assertTrue(result.contains("@spoon.reflect.annotations.MetamodelPropertyField(role = spoon.reflect.path.CtRole.IS_SHADOW)\nboolean isShadow;"));
assertTrue(result.contains("@spoon.reflect.annotations.MetamodelPropertyField(role = spoon.reflect.path.CtRole.TYPE)\nspoon.reflect.reference.CtTypeReference<T> type;"));
assertTrue(result.contains("@spoon.reflect.annotations.MetamodelPropertyField(role = spoon.reflect.path.CtRole.IS_SHADOW)"+nl+"boolean isShadow;"));
assertTrue(result.contains("@spoon.reflect.annotations.MetamodelPropertyField(role = spoon.reflect.path.CtRole.TYPE)"+nl+"spoon.reflect.reference.CtTypeReference<T> type;"));
assertTrue(result.size()>100);
Assert.assertEquals(Collections.emptyList(), fieldWithoutAnnotation);

Expand Down
2 changes: 1 addition & 1 deletion src/test/java/spoon/test/comment/CommentTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ public void testInLineComment() {
assertEquals("// Comment Field" + newLine
+ "// comment field 2" + newLine
+ "// comment in field" + newLine
+ "private int field = 10;// after field\n", field.toString());
+ "private int field = 10;// after field" + newLine, field.toString());

CtAnonymousExecutable ctAnonymousExecutable = type.getAnonymousExecutables().get(0);
assertEquals(1, ctAnonymousExecutable.getComments().size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
*/
public class ImportBuilderTest {

private final static String nl = System.getProperty("line.separator");

@Test
public void testWithNoImport() {
// contract: when the source code has no import, none is created when building model
Expand Down Expand Up @@ -54,7 +56,7 @@ public void testWithSimpleImport() {
assertEquals(1, imports.size());

CtImport ref = imports.iterator().next();
assertEquals("import spoon.test.annotation.testclasses.GlobalAnnotation;\n", ref.toString());
assertEquals("import spoon.test.annotation.testclasses.GlobalAnnotation;"+nl, ref.toString());
assertTrue(ref.getReference() instanceof CtTypeReference);

CtTypeReference refType = (CtTypeReference)ref.getReference();
Expand Down Expand Up @@ -152,7 +154,7 @@ public void testWithStaticInheritedImport() {
assertEquals(1, imports.size());
CtImport ctImport = imports.iterator().next();
assertEquals(CtImportKind.ALL_STATIC_MEMBERS, ctImport.getImportKind());
assertEquals("import static spoon.test.jdtimportbuilder.testclasses.staticimport.DependencySubClass.*;\n", ctImport.toString());
assertEquals("import static spoon.test.jdtimportbuilder.testclasses.staticimport.DependencySubClass.*;"+nl, ctImport.toString());
}

@Test
Expand All @@ -173,7 +175,7 @@ public void testWithImportFromItf() {
CtImport ctImport = imports.iterator().next();

assertEquals(CtImportKind.ALL_STATIC_MEMBERS, ctImport.getImportKind());
assertEquals("import static jdtimportbuilder.itf.DumbItf.*;\n", ctImport.toString());
assertEquals("import static jdtimportbuilder.itf.DumbItf.*;"+nl, ctImport.toString());
}

}
2 changes: 1 addition & 1 deletion src/test/java/spoon/test/template/PatternTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1228,7 +1228,7 @@ public void testPatternToString() {
" */"+nl+"" +
" statements();"+nl+"" +
" }"+nl+"" +
"}"+nl+"", p.toString());
"}"+nl, p.toString());
}

@Test
Expand Down

0 comments on commit 34346a6

Please sign in to comment.