3030 * Represents the line endings which should be written by the tool.
3131 */
3232public enum LineEnding {
33- // @formatter:off
3433 /** Uses the same line endings as Git, using {@code .gitattributes} and the {@code core.eol} property. */
3534 GIT_ATTRIBUTES {
3635 /** .gitattributes is path-specific, so you must use {@link LineEnding#createPolicy(File, Supplier)}. */
@@ -57,7 +56,6 @@ public Policy createPolicy() {
5756 MAC_CLASSIC ,
5857 /** preserve the line ending of the first line (no matter which format) */
5958 PRESERVE ;
60- // @formatter:on
6159
6260 /** Returns a {@link Policy} appropriate for files which are contained within the given rootFolder. */
6361 public Policy createPolicy (File projectDir , Supplier <Iterable <File >> toFormat ) {
@@ -80,17 +78,16 @@ public Policy createPolicy(File projectDir, Supplier<Iterable<File>> toFormat) {
8078 }
8179 }
8280
83- // @formatter:off
8481 /** Should use {@link #createPolicy(File, Supplier)} instead, but this will work iff its a path-independent LineEnding policy. */
8582 public Policy createPolicy () {
86- switch (this ) {
87- case PLATFORM_NATIVE : return _PLATFORM_NATIVE_POLICY ;
88- case WINDOWS : return WINDOWS_POLICY ;
89- case UNIX : return UNIX_POLICY ;
90- case MAC_CLASSIC : return MAC_CLASSIC_POLICY ;
91- case PRESERVE : return PRESERVE_POLICY ;
92- default : throw new UnsupportedOperationException (this + " is a path-specific line ending." );
93- }
83+ return switch (this ) {
84+ case PLATFORM_NATIVE -> _PLATFORM_NATIVE_POLICY ;
85+ case WINDOWS -> WINDOWS_POLICY ;
86+ case UNIX -> UNIX_POLICY ;
87+ case MAC_CLASSIC -> MAC_CLASSIC_POLICY ;
88+ case PRESERVE -> PRESERVE_POLICY ;
89+ default -> throw new UnsupportedOperationException (this + " is a path-specific line ending." );
90+ };
9491 }
9592
9693 static class ConstantLineEndingPolicy extends NoLambda .EqualityBasedOnSerialization implements Policy {
@@ -123,7 +120,7 @@ public String getEndingFor(File file) {
123120
124121 static String getEndingFor (Reader reader ) throws IOException {
125122 char previousCharacter = 0 ;
126- char currentCharacter = 0 ;
123+ char currentCharacter ;
127124 int readResult ;
128125 while ((readResult = reader .read ()) != -1 ) {
129126 currentCharacter = (char ) readResult ;
@@ -169,15 +166,14 @@ public static boolean nativeIsWin() {
169166
170167 /** Returns the standard line ending for this policy. */
171168 public String str () {
172- switch (this ) {
173- case PLATFORM_NATIVE : return _PLATFORM_NATIVE ;
174- case WINDOWS : return "\r \n " ;
175- case UNIX : return "\n " ;
176- case MAC_CLASSIC : return "\r " ;
177- default : throw new UnsupportedOperationException (this + " is a path-specific line ending." );
178- }
169+ return switch (this ) {
170+ case PLATFORM_NATIVE -> _PLATFORM_NATIVE ;
171+ case WINDOWS -> "\r \n " ;
172+ case UNIX -> "\n " ;
173+ case MAC_CLASSIC -> "\r " ;
174+ default -> throw new UnsupportedOperationException (this + " is a path-specific line ending." );
175+ };
179176 }
180- // @formatter:on
181177
182178 /** A policy for line endings which can vary based on the specific file being requested. */
183179 public interface Policy extends Serializable , NoLambda {
0 commit comments