-
Notifications
You must be signed in to change notification settings - Fork 209
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HQL and JPQL syntax validation reconciling
- Loading branch information
Showing
16 changed files
with
839 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
...rc/main/java/org/springframework/ide/vscode/boot/java/data/jpa/queries/HqlReconciler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 Broadcom, Inc. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Broadcom, Inc. - initial API and implementation | ||
*******************************************************************************/ | ||
package org.springframework.ide.vscode.boot.java.data.jpa.queries; | ||
|
||
import java.util.BitSet; | ||
|
||
import org.antlr.v4.runtime.ANTLRErrorListener; | ||
import org.antlr.v4.runtime.CharStreams; | ||
import org.antlr.v4.runtime.CommonTokenStream; | ||
import org.antlr.v4.runtime.ConsoleErrorListener; | ||
import org.antlr.v4.runtime.Parser; | ||
import org.antlr.v4.runtime.RecognitionException; | ||
import org.antlr.v4.runtime.Recognizer; | ||
import org.antlr.v4.runtime.Token; | ||
import org.antlr.v4.runtime.atn.ATNConfigSet; | ||
import org.antlr.v4.runtime.dfa.DFA; | ||
import org.springframework.ide.vscode.boot.java.handlers.Reconciler; | ||
import org.springframework.ide.vscode.commons.languageserver.reconcile.IProblemCollector; | ||
import org.springframework.ide.vscode.commons.languageserver.reconcile.ReconcileProblemImpl; | ||
import org.springframework.ide.vscode.parser.hql.HqlLexer; | ||
import org.springframework.ide.vscode.parser.hql.HqlParser; | ||
|
||
public class HqlReconciler implements Reconciler { | ||
|
||
@Override | ||
public void reconcile(String text, int startPosition, IProblemCollector problemCollector) { | ||
HqlLexer lexer = new HqlLexer(CharStreams.fromString(text)); | ||
CommonTokenStream antlrTokens = new CommonTokenStream(lexer); | ||
HqlParser parser = new HqlParser(antlrTokens); | ||
|
||
parser.removeErrorListener(ConsoleErrorListener.INSTANCE); | ||
|
||
parser.addErrorListener(new ANTLRErrorListener() { | ||
|
||
@Override | ||
public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine, | ||
String msg, RecognitionException e) { | ||
Token token = (Token) offendingSymbol; | ||
int offset = token.getStartIndex(); | ||
int length = token.getStopIndex() - token.getStartIndex() + 1; | ||
if (token.getStartIndex() >= token.getStopIndex()) { | ||
offset = token.getStartIndex() - token.getCharPositionInLine(); | ||
length = token.getCharPositionInLine() + 1; | ||
} | ||
problemCollector.accept(new ReconcileProblemImpl(QueryProblemType.EXPRESSION_SYNTAX, msg, startPosition + offset, length)); | ||
} | ||
|
||
@Override | ||
public void reportContextSensitivity(Parser recognizer, DFA dfa, int startIndex, int stopIndex, int prediction, | ||
ATNConfigSet configs) { | ||
} | ||
|
||
@Override | ||
public void reportAttemptingFullContext(Parser recognizer, DFA dfa, int startIndex, int stopIndex, | ||
BitSet conflictingAlts, ATNConfigSet configs) { | ||
} | ||
|
||
@Override | ||
public void reportAmbiguity(Parser recognizer, DFA dfa, int startIndex, int stopIndex, boolean exact, | ||
BitSet ambigAlts, ATNConfigSet configs) { | ||
} | ||
}); | ||
|
||
parser.ql_statement(); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
...c/main/java/org/springframework/ide/vscode/boot/java/data/jpa/queries/JpqlReconciler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 Broadcom, Inc. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Broadcom, Inc. - initial API and implementation | ||
*******************************************************************************/ | ||
package org.springframework.ide.vscode.boot.java.data.jpa.queries; | ||
|
||
import java.util.BitSet; | ||
|
||
import org.antlr.v4.runtime.ANTLRErrorListener; | ||
import org.antlr.v4.runtime.CharStreams; | ||
import org.antlr.v4.runtime.CommonTokenStream; | ||
import org.antlr.v4.runtime.ConsoleErrorListener; | ||
import org.antlr.v4.runtime.Parser; | ||
import org.antlr.v4.runtime.RecognitionException; | ||
import org.antlr.v4.runtime.Recognizer; | ||
import org.antlr.v4.runtime.Token; | ||
import org.antlr.v4.runtime.atn.ATNConfigSet; | ||
import org.antlr.v4.runtime.dfa.DFA; | ||
import org.springframework.ide.vscode.boot.java.handlers.Reconciler; | ||
import org.springframework.ide.vscode.commons.languageserver.reconcile.IProblemCollector; | ||
import org.springframework.ide.vscode.commons.languageserver.reconcile.ReconcileProblemImpl; | ||
import org.springframework.ide.vscode.parser.jpql.JpqlLexer; | ||
import org.springframework.ide.vscode.parser.jpql.JpqlParser; | ||
|
||
public class JpqlReconciler implements Reconciler { | ||
|
||
@Override | ||
public void reconcile(String text, int startPosition, IProblemCollector problemCollector) { | ||
JpqlLexer lexer = new JpqlLexer(CharStreams.fromString(text)); | ||
CommonTokenStream antlrTokens = new CommonTokenStream(lexer); | ||
JpqlParser parser = new JpqlParser(antlrTokens); | ||
|
||
parser.removeErrorListener(ConsoleErrorListener.INSTANCE); | ||
|
||
parser.addErrorListener(new ANTLRErrorListener() { | ||
|
||
@Override | ||
public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine, | ||
String msg, RecognitionException e) { | ||
Token token = (Token) offendingSymbol; | ||
int offset = token.getStartIndex(); | ||
int length = token.getStopIndex() - token.getStartIndex() + 1; | ||
if (token.getStartIndex() >= token.getStopIndex()) { | ||
offset = token.getStartIndex() - token.getCharPositionInLine(); | ||
length = token.getCharPositionInLine() + 1; | ||
} | ||
problemCollector.accept(new ReconcileProblemImpl(QueryProblemType.EXPRESSION_SYNTAX, msg, startPosition + offset, length)); | ||
} | ||
|
||
@Override | ||
public void reportContextSensitivity(Parser recognizer, DFA dfa, int startIndex, int stopIndex, int prediction, | ||
ATNConfigSet configs) { | ||
} | ||
|
||
@Override | ||
public void reportAttemptingFullContext(Parser recognizer, DFA dfa, int startIndex, int stopIndex, | ||
BitSet conflictingAlts, ATNConfigSet configs) { | ||
} | ||
|
||
@Override | ||
public void reportAmbiguity(Parser recognizer, DFA dfa, int startIndex, int stopIndex, boolean exact, | ||
BitSet ambigAlts, ATNConfigSet configs) { | ||
} | ||
}); | ||
|
||
parser.ql_statement(); | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.