Skip to content

Commit 30531c8

Browse files
committed
Refine contribution #1168
- Remove unnecessary empty line parsing - Rename utility method
1 parent 25f02d5 commit 30531c8

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

spring-shell-core/src/main/java/org/springframework/shell/jline/FileInputProvider.java

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017 the original author or authors.
2+
* Copyright 2017-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -63,17 +63,11 @@ public Input readInput() {
6363
} catch (IOException e) {
6464
throw new RuntimeException(e);
6565
}
66-
if (line == null) {
66+
if (line == null || isComment(line)) {
6767
return null;
6868
} else {
69-
// gh-277: if it's a commented line then skip as it is equal to NO_INPUT
70-
ParsedLine parsedLine;
71-
if (isCommentedLine(line)) {
72-
parsedLine = parser.parse("", -1, Parser.ParseContext.COMPLETE);
73-
} else {
74-
parsedLine = parser.parse(sb.toString(), sb.toString().length());
75-
}
76-
return new ParsedLineInput(parsedLine);
69+
ParsedLine parsedLine = parser.parse(sb.toString(), sb.toString().length());
70+
return new ParsedLineInput(parsedLine);
7771
}
7872
}
7973

@@ -82,7 +76,7 @@ public void close() throws IOException {
8276
reader.close();
8377
}
8478

85-
private boolean isCommentedLine(String line) {
79+
private boolean isComment(String line) {
8680
return line.matches("\\s*//.*");
8781
}
8882
}

0 commit comments

Comments
 (0)