Skip to content

Commit ae5c57a

Browse files
committed
#1168: Add camel-jq language validation
1 parent d182712 commit ae5c57a

File tree

3 files changed

+20
-22
lines changed

3 files changed

+20
-22
lines changed

src/main/java/com/github/cameltooling/idea/annotator/CamelJSonPathAnnotator.java renamed to src/main/java/com/github/cameltooling/idea/annotator/CamelLanguageAnnotator.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@
3333
import org.jetbrains.annotations.NotNull;
3434

3535
/**
36-
* Validate JSonPath expression and annotated the specific jsonpath expression to highlight the error in the editor
36+
* Validate language expression such as JSonPath/JQ to highlight the error in the editor
3737
*/
38-
public class CamelJSonPathAnnotator extends AbstractCamelAnnotator {
38+
public class CamelLanguageAnnotator extends AbstractCamelAnnotator {
3939

4040
private static final Logger LOG = Logger.getInstance(CamelEndpointAnnotator.class);
4141

@@ -45,29 +45,27 @@ boolean isEnabled() {
4545
}
4646

4747
/**
48-
* Validate jsonpath expression. eg jsonpath("$.store.book[?(@.price < 10)]")
48+
* Validate language expression, such as jsonpath("$.store.book[?(@.price < 10)]")
4949
* if the expression is not valid an error annotation is created and highlight the invalid value.
5050
*/
5151
void validateText(@NotNull PsiElement element, @NotNull AnnotationHolder holder, @NotNull String text) {
52-
5352
final CamelIdeaUtils camelIdeaUtils = CamelIdeaUtils.getService();
54-
// only validate if the element is jsonpath element
53+
5554
boolean json = CamelPreferenceService.getService().isRealTimeJSonPathValidation() && camelIdeaUtils.isCamelExpression(element, "jsonpath");
5655
boolean jq = CamelPreferenceService.getService().isRealTimeJQValidation() && camelIdeaUtils.isCamelExpression(element, "jq");
5756
if (json || jq) {
5857
Project project = element.getProject();
5958
CamelCatalog catalogService = project.getService(CamelCatalogService.class).get();
6059
CamelService camelService = project.getService(CamelService.class);
6160

62-
// must have camel-json library
61+
// must have the supporting library
6362
String lib = json ? "camel-jsonpath" : "camel-jq";
64-
String lan = json ? "jsonpath" : "jq";
65-
boolean jsonLib = camelService.containsLibrary(lib, false);
66-
if (!jsonLib) {
67-
camelService.showMissingJSonPathJarNotification(lib);
63+
if (!camelService.containsLibrary(lib, false)) {
64+
camelService.showMissingLanguageJarNotification(lib);
6865
return;
6966
}
7067

68+
String lan = json ? "jsonpath" : "jq";
7169
try {
7270
// need to use the classloader that can load classes from the project
7371
ClassLoader loader = camelService.getProjectClassloader();

src/main/java/com/github/cameltooling/idea/service/CamelService.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public class CamelService implements Disposable {
8787
private volatile boolean camelPresent;
8888
private volatile Notification camelVersionNotification;
8989
private volatile Notification camelMissingJSonSchemaNotification;
90-
private volatile Notification camelMissingJSonPathJarNotification;
90+
private volatile Notification camelMissingLanguageJarNotification;
9191

9292
/**
9393
* The project in which the service is registered.
@@ -118,9 +118,9 @@ public synchronized void dispose() {
118118
camelMissingJSonSchemaNotification.expire();
119119
camelMissingJSonSchemaNotification = null;
120120
}
121-
if (camelMissingJSonPathJarNotification != null) {
122-
camelMissingJSonPathJarNotification.expire();
123-
camelMissingJSonPathJarNotification = null;
121+
if (camelMissingLanguageJarNotification != null) {
122+
camelMissingLanguageJarNotification.expire();
123+
camelMissingLanguageJarNotification = null;
124124
}
125125
if (camelCoreClassloader != null) {
126126
try {
@@ -345,12 +345,12 @@ synchronized ClassLoader getProjectCompleteClassloader() {
345345
return projectCompleteClassloader;
346346
}
347347

348-
public void showMissingJSonPathJarNotification(String lib) {
349-
if (camelMissingJSonPathJarNotification == null) {
348+
public void showMissingLanguageJarNotification(String lib) {
349+
if (camelMissingLanguageJarNotification == null) {
350350
Icon icon = CamelPreferenceService.getService().getCamelIcon();
351-
camelMissingJSonPathJarNotification = CAMEL_NOTIFICATION_GROUP.createNotification(lib + " is not on classpath. Cannot perform real time validation.",
351+
camelMissingLanguageJarNotification = CAMEL_NOTIFICATION_GROUP.createNotification(lib + " is not on classpath. Cannot perform real time validation.",
352352
NotificationType.WARNING).setImportant(true).setIcon(icon);
353-
camelMissingJSonPathJarNotification.notify(project);
353+
camelMissingLanguageJarNotification.notify(project);
354354
}
355355
}
356356

src/main/resources/META-INF/plugin.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,10 @@
124124
<annotator language="JAVA" implementationClass="com.github.cameltooling.idea.annotator.CamelSimpleAnnotator"/>
125125
<annotator language="XML" implementationClass="com.github.cameltooling.idea.annotator.CamelSimpleAnnotator"/>
126126
<annotator language="yaml" implementationClass="com.github.cameltooling.idea.annotator.CamelSimpleAnnotator"/>
127-
<!-- annotator to validate jsonpath language -->
128-
<annotator language="JAVA" implementationClass="com.github.cameltooling.idea.annotator.CamelJSonPathAnnotator"/>
129-
<annotator language="XML" implementationClass="com.github.cameltooling.idea.annotator.CamelJSonPathAnnotator"/>
130-
<annotator language="yaml" implementationClass="com.github.cameltooling.idea.annotator.CamelJSonPathAnnotator"/>
127+
<!-- annotator to validate json/jq language(s) -->
128+
<annotator language="JAVA" implementationClass="com.github.cameltooling.idea.annotator.CamelLanguageAnnotator"/>
129+
<annotator language="XML" implementationClass="com.github.cameltooling.idea.annotator.CamelLanguageAnnotator"/>
130+
<annotator language="yaml" implementationClass="com.github.cameltooling.idea.annotator.CamelLanguageAnnotator"/>
131131
<!-- annotator to validate bean references by type -->
132132
<annotator language="JAVA" implementationClass="com.github.cameltooling.idea.annotator.BeanReferenceTypeAnnotator"/>
133133
<annotator language="XML" implementationClass="com.github.cameltooling.idea.annotator.BeanReferenceTypeAnnotator"/>

0 commit comments

Comments
 (0)