CRON reconciling with EOF fixed

This commit is contained in:
aboyko
2024-08-21 14:11:45 -04:00
parent 790d50f910
commit ae76991822
5 changed files with 36 additions and 7 deletions

View File

@@ -149,11 +149,13 @@ public class CronReconciler implements Reconciler {
public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine,
String msg, RecognitionException e) {
int offset = 0;
int length = 1;
int length = 0;
if (offendingSymbol instanceof Token) {
Token token = (Token) offendingSymbol;
offset = token.getStartIndex();
length = token.getText().length();
if (token.getStartIndex() <= token.getStopIndex()) {
length = token.getText() == null ? token.getStopIndex() + 1 - token.getStartIndex() : token.getText().length();
}
} else {
DefaultLineTracker lt = lineTrackerRef.get();
if (lt == null) {

View File

@@ -73,11 +73,13 @@ public class AntlrReconciler implements Reconciler {
public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine,
String msg, RecognitionException e) {
int offset = 0;
int length = 1;
int length = 0;
if (offendingSymbol instanceof Token) {
Token token = (Token) offendingSymbol;
offset = token.getStartIndex();
length = token.getText().length();
if (token.getStartIndex() <= token.getStopIndex()) {
length = token.getText() == null ? token.getStopIndex() + 1 - token.getStartIndex() : token.getText().length();
}
} else {
DefaultLineTracker lt = lineTrackerRef.get();
if (lt == null) {

View File

@@ -64,7 +64,7 @@ public class CronReconcilerTest {
void syntax_problems_3() {
reconciler.reconcile("10/2. * * ? * MON-5", 0, collector);
assertEquals(1, problems.size());
assertReconcileProblem(problems.get(0), CronProblemType.SYNTAX, 4, 1);
assertReconcileProblem(problems.get(0), CronProblemType.SYNTAX, 4, 0);
}
static void assertReconcileProblem(ReconcileProblem p, ProblemType type, int offset, int length) {

View File

@@ -132,4 +132,29 @@ public class JdtCronReconcilerTest {
"?|CRON: Number expected"
);
}
@Test
void errorsReported_3() throws Exception {
String source = """
package example.demo;
import org.springframework.scheduling.annotation.Scheduled;
public class A {
@Scheduled(cron = "*/ * * ? * MON-5")
void foo() {}
}
""";
String docUri = directory.toPath().resolve("src/main/java/example/demo/A.java").toUri()
.toString();
Editor editor = harness.newEditor(LanguageId.JAVA, source, docUri);
editor.assertProblems(
" |CRON: extraneous input ' '",
"?|CRON: Number expected",
"MON-5|CRON: Error at index 0",
"\"|CRON: mismatched input '<EOF>'"
);
}
}

View File

@@ -1304,12 +1304,12 @@
},
"devDependencies": {
"@types/node": "^18.8.0",
"@types/vscode": "1.92.0",
"@types/semver": "^7.5.8",
"@types/vscode": "1.92.0",
"@vscode/vsce": "^2.22.0",
"typescript": "^4.8.0"
},
"extensionDependencies": [
"redhat.java"
]
}
}