Skip to content

Commit ae76991

Browse files
committed
CRON reconciling with EOF fixed
1 parent 790d50f commit ae76991

File tree

5 files changed

+36
-7
lines changed

5 files changed

+36
-7
lines changed

headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/cron/CronReconciler.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,13 @@ private void markProblemsForNumberFormatException(ParserRuleContext ctx, String
149149
public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine,
150150
String msg, RecognitionException e) {
151151
int offset = 0;
152-
int length = 1;
152+
int length = 0;
153153
if (offendingSymbol instanceof Token) {
154154
Token token = (Token) offendingSymbol;
155155
offset = token.getStartIndex();
156-
length = token.getText().length();
156+
if (token.getStartIndex() <= token.getStopIndex()) {
157+
length = token.getText() == null ? token.getStopIndex() + 1 - token.getStartIndex() : token.getText().length();
158+
}
157159
} else {
158160
DefaultLineTracker lt = lineTrackerRef.get();
159161
if (lt == null) {

headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/data/jpa/queries/AntlrReconciler.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,13 @@ protected Parser createParser(String text, int startPosition, IProblemCollector
7373
public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine,
7474
String msg, RecognitionException e) {
7575
int offset = 0;
76-
int length = 1;
76+
int length = 0;
7777
if (offendingSymbol instanceof Token) {
7878
Token token = (Token) offendingSymbol;
7979
offset = token.getStartIndex();
80-
length = token.getText().length();
80+
if (token.getStartIndex() <= token.getStopIndex()) {
81+
length = token.getText() == null ? token.getStopIndex() + 1 - token.getStartIndex() : token.getText().length();
82+
}
8183
} else {
8284
DefaultLineTracker lt = lineTrackerRef.get();
8385
if (lt == null) {

headless-services/spring-boot-language-server/src/test/java/org/springframework/ide/vscode/boot/java/cron/CronReconcilerTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ void syntax_problems_2() {
6464
void syntax_problems_3() {
6565
reconciler.reconcile("10/2. * * ? * MON-5", 0, collector);
6666
assertEquals(1, problems.size());
67-
assertReconcileProblem(problems.get(0), CronProblemType.SYNTAX, 4, 1);
67+
assertReconcileProblem(problems.get(0), CronProblemType.SYNTAX, 4, 0);
6868
}
6969

7070
static void assertReconcileProblem(ReconcileProblem p, ProblemType type, int offset, int length) {

headless-services/spring-boot-language-server/src/test/java/org/springframework/ide/vscode/boot/java/cron/JdtCronReconcilerTest.java

+25
Original file line numberDiff line numberDiff line change
@@ -132,4 +132,29 @@ void foo() {}
132132
"?|CRON: Number expected"
133133
);
134134
}
135+
136+
@Test
137+
void errorsReported_3() throws Exception {
138+
String source = """
139+
package example.demo;
140+
141+
import org.springframework.scheduling.annotation.Scheduled;
142+
143+
public class A {
144+
145+
@Scheduled(cron = "*/ * * ? * MON-5")
146+
void foo() {}
147+
148+
}
149+
""";
150+
String docUri = directory.toPath().resolve("src/main/java/example/demo/A.java").toUri()
151+
.toString();
152+
Editor editor = harness.newEditor(LanguageId.JAVA, source, docUri);
153+
editor.assertProblems(
154+
" |CRON: extraneous input ' '",
155+
"?|CRON: Number expected",
156+
"MON-5|CRON: Error at index 0",
157+
"\"|CRON: mismatched input '<EOF>'"
158+
);
159+
}
135160
}

vscode-extensions/vscode-spring-boot/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1304,12 +1304,12 @@
13041304
},
13051305
"devDependencies": {
13061306
"@types/node": "^18.8.0",
1307-
"@types/vscode": "1.92.0",
13081307
"@types/semver": "^7.5.8",
1308+
"@types/vscode": "1.92.0",
13091309
"@vscode/vsce": "^2.22.0",
13101310
"typescript": "^4.8.0"
13111311
},
13121312
"extensionDependencies": [
13131313
"redhat.java"
13141314
]
1315-
}
1315+
}

0 commit comments

Comments
 (0)