CRON reconciling with EOF fixed
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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>'"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user