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

Enhanced EOL support #2685

Merged
merged 36 commits into from
May 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
1687acc
added enum to represent different styles of line endings, and marked …
MysterAitch May 18, 2020
463d704
Added test case, comments, and fixed a few bugs...
MysterAitch May 18, 2020
7ae8157
fixes #2647 -- nodes now have a data item with detail about which lin…
MysterAitch May 18, 2020
a383ff4
added helper method and checks where used to default to system's line…
MysterAitch May 19, 2020
1575ce4
extracted out method which gets a string from a provider
MysterAitch May 19, 2020
6094e5a
added method that allows passing a default line ending if there eithe…
MysterAitch May 19, 2020
0303145
bug fix where the node has no EOL chars already -- default to using s…
MysterAitch May 19, 2020
b64e895
fixed the CsmToken based only on a given token type int -- the conten…
MysterAitch May 19, 2020
fa48fe4
added comments to the variety of whitespace characters treated as a s…
MysterAitch May 19, 2020
117cc6e
Revert change to CsmTextBlock and added documentation
MysterAitch May 20, 2020
aeebc4d
Merge branch 'master' into issue_2647_eol
MysterAitch May 22, 2020
0c07766
tweak test to give better failure messages
MysterAitch May 22, 2020
c792876
Merge branch 'issue_2647_eol' of https://github.com/MysterAitch/javap…
MysterAitch May 22, 2020
c60d03e
Added more descriptive assertion message, and javadoc
MysterAitch May 22, 2020
7c85e2a
.. now the output actually prints the output in human-readable form..…
MysterAitch May 22, 2020
9e1199e
attempt two at human-readable output
MysterAitch May 22, 2020
d1ddcc4
include the system's EOL in the test output
MysterAitch May 22, 2020
3fd78bb
edited TestUtils#readResource to read the file "as-is" (i.e. characte…
MysterAitch May 22, 2020
b0e88e1
editing another test case which presumes system EOL -- this commit pr…
MysterAitch May 22, 2020
339d45a
Introduced TestUtils.assertEqualsString and TestUtils.assertEqualsStr…
MysterAitch May 22, 2020
1c69a61
converted usages of `assertEqualsNoEol` to `assertEqualsStringIgnorin…
MysterAitch May 22, 2020
e3e59af
updated appveyor.yml to set autocrlf to true -- appveyor defaults to …
MysterAitch May 23, 2020
0b3b64c
Merge branch 'master' into issue_2647_eol
MysterAitch May 23, 2020
0f70d09
Merge branch 'master' into issue_2647_eol
MysterAitch May 24, 2020
2027ca2
Merge branch 'master' into issue_2647_eol
MysterAitch May 26, 2020
ede3a21
initial switch to using line ending detection as a preprocessor
MysterAitch May 26, 2020
df5605c
renamed uses of `toString()` to `toRawString()` to emphasise that the…
MysterAitch May 26, 2020
7540f1d
renamed LineEnding to LineSeparator
MysterAitch May 26, 2020
65b58c4
renamed assertEqualsNoEol to assertEqualsStringIgnoringEol
MysterAitch May 26, 2020
8a1dd7d
renamed EOL to SYSTEM_EOL to make it explicit that it refers to the h…
MysterAitch May 26, 2020
6c52c73
renamed variable/config option re: detecting line endings as opposed …
MysterAitch May 26, 2020
c0a4305
renamed variable/config option re: detecting line endings as opposed …
MysterAitch May 26, 2020
62c8570
renamed toRawString and toEscapedString to asRawString and asEscapedS…
MysterAitch May 26, 2020
2062690
renamed variable/config option re: detecting line endings as opposed …
MysterAitch May 26, 2020
4144743
typo fix in tests -- accidentally comparing string to enum LineSeparator
MysterAitch May 26, 2020
a7fd3c9
updated changelog.md
MysterAitch May 26, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 19 additions & 3 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
version: '{build}'
os: Windows Server 2012

environment:
appveyor_build_worker_cloud: gce

init:
# Setup autocrlf -- by default, appveyor uses autocrlf input
# ... This affects tests which expect resource files to have the systems's line separator.
- git config --global core.autocrlf true

install:
# Download maven
- ps: |
Add-Type -AssemblyName System.IO.Compression.FileSystem
if (!(Test-Path -Path "C:\maven" )) {
Expand All @@ -12,15 +20,23 @@ install:
)
[System.IO.Compression.ZipFile]::ExtractToDirectory("C:\maven-bin.zip", "C:\maven")
}
- cmd: SET PATH=C:\maven\apache-maven-3.6.3\bin;%JAVA_HOME%\bin;%PATH%
# Setup environment variables for Maven and Java
- cmd: SET JAVA_HOME=C:\Program Files\Java\jdk10
- cmd: SET M2_HOME=C:\maven\apache-maven-3.6.3
- cmd: SET MAVEN_OPTS=-Xmx1g
- cmd: SET JAVA_OPTS=-Xmx1g
- cmd: SET M2_HOME=C:\maven\apache-maven-3.6.3
- cmd: SET JAVA_HOME=C:\Program Files\Java\jdk10
- cmd: SET PATH=C:\maven\apache-maven-3.6.3\bin;%JAVA_HOME%\bin;%PATH%
# Output the git config re: autocrlf to verify the "current" setting
- cmd: git config core.autocrlf

# Appveyor is used for testing only -- the build script is not required.
build_script:
- echo ignore this

test_script:
- mvn -B clean install --batch-mode

# Use of the cache speeds up future tests, meaning that dependencies do not need to be re-downloaded on every run.
cache:
- C:\maven\
- C:\Users\appveyor\.m2
10 changes: 8 additions & 2 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
Next Release (Version 3.16.1)
Next Release (Version 3.16.2)
------------------
[issues resolved](https://github.com/javaparser/javaparser/milestone/176?closed=1)
* FIXED: Enhanced the handling of line separator, introducing an enum `LineSeparator` that can be used.
(PR [#2685](https://github.com/javaparser/javaparser/pull/2685), by [@MysterAitch](https://github.com/MysterAitch))

Version 3.16.1
------------------
[issues resolved](https://github.com/javaparser/javaparser/milestone/175?closed=1)
* FIXED: Fixed type
* FIXED: Fixed typo
(PR [#2697](https://github.com/javaparser/javaparser/pull/2697), by [@hfreeb](https://github.com/hfreeb))

Version 3.16.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.github.javaparser.javadoc.JavadocBlockTag;
import com.github.javaparser.resolution.SymbolResolver;
import com.github.javaparser.resolution.types.ResolvedType;
import com.github.javaparser.utils.LineSeparator;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Test;

Expand All @@ -40,7 +41,6 @@

import static com.github.javaparser.StaticJavaParser.*;
import static com.github.javaparser.serialization.JavaParserJsonSerializerTest.serialize;
import static com.github.javaparser.utils.Utils.EOL;
import static com.github.javaparser.utils.Utils.normalizeEolInTextBlock;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
Expand All @@ -55,7 +55,7 @@ void simpleTest() {

Node deserialized = deserializer.deserializeObject(Json.createReader(new StringReader(serialized)));

assertEqualsNoEol("public class X {\n}\n\nclass Z {\n}\n", deserialized.toString());
assertEqualsStringIgnoringEol("public class X {\n}\n\nclass Z {\n}\n", deserialized.toString());
assertEquals(cu.hashCode(), deserialized.hashCode());
}

Expand All @@ -66,7 +66,7 @@ void testRawType() {

Node deserialized = deserializer.deserializeObject(Json.createReader(new StringReader(serialized)));

assertEqualsNoEol("Blub", deserialized.toString());
assertEqualsStringIgnoringEol("Blub", deserialized.toString());
assertEquals(type.hashCode(), deserialized.hashCode());
}

Expand All @@ -77,7 +77,7 @@ void testDiamondType() {

Node deserialized = deserializer.deserializeObject(Json.createReader(new StringReader(serialized)));

assertEqualsNoEol("Blub<>", deserialized.toString());
assertEqualsStringIgnoringEol("Blub<>", deserialized.toString());
assertEquals(type.hashCode(), deserialized.hashCode());
}

Expand All @@ -88,7 +88,7 @@ void testGenerics() {

Node deserialized = deserializer.deserializeObject(Json.createReader(new StringReader(serialized)));

assertEqualsNoEol("Blub<Blab, Bleb>", deserialized.toString());
assertEqualsStringIgnoringEol("Blub<Blab, Bleb>", deserialized.toString());
assertEquals(type.hashCode(), deserialized.hashCode());
}

Expand All @@ -99,7 +99,7 @@ void testOperator() {

Node deserialized = deserializer.deserializeObject(Json.createReader(new StringReader(serialized)));

assertEqualsNoEol("1 + 1", deserialized.toString());
assertEqualsStringIgnoringEol("1 + 1", deserialized.toString());
assertEquals(expr.hashCode(), deserialized.hashCode());
}

Expand All @@ -110,7 +110,7 @@ void testPrimitiveType() {

Node deserialized = deserializer.deserializeObject(Json.createReader(new StringReader(serialized)));

assertEqualsNoEol("int", deserialized.toString());
assertEqualsStringIgnoringEol("int", deserialized.toString());
assertEquals(type.hashCode(), deserialized.hashCode());
}

Expand Down Expand Up @@ -214,8 +214,11 @@ static void clearConfiguration() {
/**
* Assert that "actual" equals "expected", and that any EOL characters in "actual" are correct for the platform.
*/
private static void assertEqualsNoEol(String expected, String actual) {
assertEquals(normalizeEolInTextBlock(expected, EOL), actual);
private static void assertEqualsStringIgnoringEol(String expected, String actual) {
assertEquals(
normalizeEolInTextBlock(expected, LineSeparator.ARBITRARY),
normalizeEolInTextBlock(actual, LineSeparator.ARBITRARY)
);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
import static com.github.javaparser.StaticJavaParser.parse;
import static com.github.javaparser.StaticJavaParser.parseResource;
import static com.github.javaparser.utils.TestUtils.assertEqualToTextResource;
import static com.github.javaparser.utils.TestUtils.assertEqualsNoEol;
import static com.github.javaparser.utils.Utils.EOL;
import static com.github.javaparser.utils.TestUtils.assertEqualsStringIgnoringEol;
import static com.github.javaparser.utils.Utils.SYSTEM_EOL;
import static org.junit.jupiter.api.Assertions.assertEquals;

class CommentsInserterTest {
Expand Down Expand Up @@ -69,13 +69,13 @@ void issue624() throws IOException {

@Test
void issue200EnumConstantsWithCommentsForceVerticalAlignment() {
CompilationUnit cu = TestParser.parseCompilationUnit("public enum X {" + EOL +
" /** const1 javadoc */" + EOL +
" BORDER_CONSTANT," + EOL +
" /** const2 javadoc */" + EOL +
" ANOTHER_CONSTANT" + EOL +
CompilationUnit cu = TestParser.parseCompilationUnit("public enum X {" + SYSTEM_EOL +
" /** const1 javadoc */" + SYSTEM_EOL +
" BORDER_CONSTANT," + SYSTEM_EOL +
" /** const2 javadoc */" + SYSTEM_EOL +
" ANOTHER_CONSTANT" + SYSTEM_EOL +
"}");
assertEqualsNoEol("public enum X {\n" +
assertEqualsStringIgnoringEol("public enum X {\n" +
"\n" +
" /**\n" +
" * const1 javadoc\n" +
Expand All @@ -90,16 +90,16 @@ void issue200EnumConstantsWithCommentsForceVerticalAlignment() {

@Test
void issue234LosingCommentsInArrayInitializerExpr() {
CompilationUnit cu = TestParser.parseCompilationUnit("@Anno(stuff={" + EOL +
" // Just," + EOL +
" // an," + EOL +
" // example" + EOL +
"})" + EOL +
"class ABC {" + EOL +
"" + EOL +
CompilationUnit cu = TestParser.parseCompilationUnit("@Anno(stuff={" + SYSTEM_EOL +
" // Just," + SYSTEM_EOL +
" // an," + SYSTEM_EOL +
" // example" + SYSTEM_EOL +
"})" + SYSTEM_EOL +
"class ABC {" + SYSTEM_EOL +
"" + SYSTEM_EOL +
"}");

assertEqualsNoEol("@Anno(stuff = {// Just,\n" +
assertEqualsStringIgnoringEol("@Anno(stuff = {// Just,\n" +
"// an,\n" +
"// example\n" +
"})\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
import static com.github.javaparser.Range.range;
import static com.github.javaparser.StaticJavaParser.*;
import static com.github.javaparser.utils.TestUtils.assertInstanceOf;
import static com.github.javaparser.utils.Utils.EOL;
import static com.github.javaparser.utils.Utils.SYSTEM_EOL;
import static org.junit.jupiter.api.Assertions.*;

class JavaParserTest {
Expand Down Expand Up @@ -163,9 +163,9 @@ void parseIntersectionType() {

@Test
void rangeOfIntersectionType() {
String code = "class A {" + EOL
+ " Object f() {" + EOL
+ " return (Comparator<Map.Entry<K, V>> & Serializable)(c1, c2) -> c1.getKey().compareTo(c2.getKey()); " + EOL
String code = "class A {" + SYSTEM_EOL
+ " Object f() {" + SYSTEM_EOL
+ " return (Comparator<Map.Entry<K, V>> & Serializable)(c1, c2) -> c1.getKey().compareTo(c2.getKey()); " + SYSTEM_EOL
+ "}}";
CompilationUnit cu = parse(code);
MethodDeclaration methodDeclaration = cu.getClassByName("A").get().getMember(0).asMethodDeclaration();
Expand All @@ -177,9 +177,9 @@ void rangeOfIntersectionType() {

@Test
void rangeOfCast() {
String code = "class A {" + EOL
+ " Object f() {" + EOL
+ " return (Comparator<Map.Entry<K, V>> & Serializable)(c1, c2) -> c1.getKey().compareTo(c2.getKey()); " + EOL
String code = "class A {" + SYSTEM_EOL
+ " Object f() {" + SYSTEM_EOL
+ " return (Comparator<Map.Entry<K, V>> & Serializable)(c1, c2) -> c1.getKey().compareTo(c2.getKey()); " + SYSTEM_EOL
+ "}}";
CompilationUnit cu = parse(code);
MethodDeclaration methodDeclaration = cu.getClassByName("A").get().getMember(0).asMethodDeclaration();
Expand All @@ -190,9 +190,9 @@ void rangeOfCast() {

@Test
void rangeOfCastNonIntersection() {
String code = "class A {" + EOL
+ " Object f() {" + EOL
+ " return (Comparator<Map.Entry<K, V>> )(c1, c2) -> c1.getKey().compareTo(c2.getKey()); " + EOL
String code = "class A {" + SYSTEM_EOL
+ " Object f() {" + SYSTEM_EOL
+ " return (Comparator<Map.Entry<K, V>> )(c1, c2) -> c1.getKey().compareTo(c2.getKey()); " + SYSTEM_EOL
+ "}}";
CompilationUnit cu = parse(code);
MethodDeclaration methodDeclaration = cu.getClassByName("A").get().getMember(0).asMethodDeclaration();
Expand All @@ -203,9 +203,9 @@ void rangeOfCastNonIntersection() {

@Test
void rangeOfLambda() {
String code = "class A {" + EOL
+ " Object f() {" + EOL
+ " return (Comparator<Map.Entry<K, V>> & Serializable)(c1, c2) -> c1.getKey().compareTo(c2.getKey()); " + EOL
String code = "class A {" + SYSTEM_EOL
+ " Object f() {" + SYSTEM_EOL
+ " return (Comparator<Map.Entry<K, V>> & Serializable)(c1, c2) -> c1.getKey().compareTo(c2.getKey()); " + SYSTEM_EOL
+ "}}";
CompilationUnit cu = parse(code);
MethodDeclaration methodDeclaration = cu.getClassByName("A").get().getMember(0).asMethodDeclaration();
Expand All @@ -219,9 +219,9 @@ void rangeOfLambda() {

@Test
void rangeOfLambdaBody() {
String code = "class A {" + EOL
+ " Object f() {" + EOL
+ " return (Comparator<Map.Entry<K, V>> & Serializable)(c1, c2) -> c1.getKey().compareTo(c2.getKey()); " + EOL
String code = "class A {" + SYSTEM_EOL
+ " Object f() {" + SYSTEM_EOL
+ " return (Comparator<Map.Entry<K, V>> & Serializable)(c1, c2) -> c1.getKey().compareTo(c2.getKey()); " + SYSTEM_EOL
+ "}}";
CompilationUnit cu = parse(code);
MethodDeclaration methodDeclaration = cu.getClassByName("A").get().getMember(0).asMethodDeclaration();
Expand Down