IDEA-301689 [micronaut] Data: MongoDB: support 'ISODate', 'Date' in JSON queries

GitOrigin-RevId: acd3a80f9d28633819e4cc67cd83bf55106a01b5
This commit is contained in:
Daniil Tsaryov
2022-11-21 15:51:30 +01:00
committed by intellij-monorepo-bot
parent 1b69822110
commit 89d8e858ff
10 changed files with 57 additions and 117 deletions

View File

@@ -14,7 +14,6 @@ public interface JsonElementTypes {
IElementType NULL_LITERAL = new JsonElementType("NULL_LITERAL");
IElementType NUMBER_LITERAL = new JsonElementType("NUMBER_LITERAL");
IElementType OBJECT = new JsonElementType("OBJECT");
IElementType PARAMETER_LITERAL = new JsonElementType("PARAMETER_LITERAL");
IElementType PROPERTY = new JsonElementType("PROPERTY");
IElementType REFERENCE_EXPRESSION = new JsonElementType("REFERENCE_EXPRESSION");
IElementType STRING_LITERAL = new JsonElementType("STRING_LITERAL");
@@ -31,7 +30,6 @@ public interface JsonElementTypes {
IElementType L_CURLY = new JsonTokenType("{");
IElementType NULL = new JsonTokenType("null");
IElementType NUMBER = new JsonTokenType("NUMBER");
IElementType PARAMETER = new JsonTokenType("PARAMETER");
IElementType R_BRACKET = new JsonTokenType("]");
IElementType R_CURLY = new JsonTokenType("}");
IElementType SINGLE_QUOTED_STRING = new JsonTokenType("SINGLE_QUOTED_STRING");
@@ -55,9 +53,6 @@ public interface JsonElementTypes {
else if (type == OBJECT) {
return new JsonObjectImpl(node);
}
else if (type == PARAMETER_LITERAL) {
return new JsonParameterLiteralImpl(node);
}
else if (type == PROPERTY) {
return new JsonPropertyImpl(node);
}

View File

@@ -37,8 +37,8 @@ public class JsonParser implements PsiParser, LightPsiParser {
public static final TokenSet[] EXTENDS_SETS_ = new TokenSet[] {
create_token_set_(ARRAY, BOOLEAN_LITERAL, LITERAL, NULL_LITERAL,
NUMBER_LITERAL, OBJECT, PARAMETER_LITERAL, REFERENCE_EXPRESSION,
STRING_LITERAL, VALUE),
NUMBER_LITERAL, OBJECT, REFERENCE_EXPRESSION, STRING_LITERAL,
VALUE),
};
/* ********************************************************** */
@@ -127,7 +127,7 @@ public class JsonParser implements PsiParser, LightPsiParser {
}
/* ********************************************************** */
// string_literal | number_literal | boolean_literal | null_literal | parameter_literal
// string_literal | number_literal | boolean_literal | null_literal
public static boolean literal(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "literal")) return false;
boolean r;
@@ -136,7 +136,6 @@ public class JsonParser implements PsiParser, LightPsiParser {
if (!r) r = number_literal(b, l + 1);
if (!r) r = boolean_literal(b, l + 1);
if (!r) r = null_literal(b, l + 1);
if (!r) r = parameter_literal(b, l + 1);
exit_section_(b, l, m, r, false, null);
return r;
}
@@ -265,18 +264,6 @@ public class JsonParser implements PsiParser, LightPsiParser {
return r;
}
/* ********************************************************** */
// PARAMETER
public static boolean parameter_literal(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "parameter_literal")) return false;
if (!nextTokenIs(b, PARAMETER)) return false;
boolean r;
Marker m = enter_section_(b);
r = consumeToken(b, PARAMETER);
exit_section_(b, m, PARAMETER_LITERAL, r);
return r;
}
/* ********************************************************** */
// property_name (':' property_value)
public static boolean property(PsiBuilder b, int l) {

View File

@@ -36,10 +36,6 @@ public class JsonElementVisitor extends PsiElementVisitor {
visitContainer(o);
}
public void visitParameterLiteral(@NotNull JsonParameterLiteral o) {
visitLiteral(o);
}
public void visitProperty(@NotNull JsonProperty o) {
visitElement(o);
// visitPsiNamedElement(o);

View File

@@ -1,10 +0,0 @@
// This is a generated file. Not intended for manual editing.
package com.intellij.json.psi;
import java.util.List;
import org.jetbrains.annotations.*;
import com.intellij.psi.PsiElement;
public interface JsonParameterLiteral extends JsonLiteral {
}

View File

@@ -1,30 +0,0 @@
// This is a generated file. Not intended for manual editing.
package com.intellij.json.psi.impl;
import java.util.List;
import org.jetbrains.annotations.*;
import com.intellij.lang.ASTNode;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiElementVisitor;
import com.intellij.psi.util.PsiTreeUtil;
import static com.intellij.json.JsonElementTypes.*;
import com.intellij.json.psi.*;
public class JsonParameterLiteralImpl extends JsonLiteralImpl implements JsonParameterLiteral {
public JsonParameterLiteralImpl(@NotNull ASTNode node) {
super(node);
}
@Override
public void accept(@NotNull JsonElementVisitor visitor) {
visitor.visitParameterLiteral(this);
}
@Override
public void accept(@NotNull PsiElementVisitor visitor) {
if (visitor instanceof JsonElementVisitor) accept((JsonElementVisitor)visitor);
else super.accept(visitor);
}
}

View File

@@ -51,7 +51,7 @@
extends("container|literal|reference_expression")=value
extends("array|object")=container
extends("string_literal|number_literal|boolean_literal|null_literal|parameter_literal")=literal
extends("string_literal|number_literal|boolean_literal|null_literal")=literal
implements("property")=[
"com.intellij.json.psi.JsonElement"
"com.intellij.psi.PsiNamedElement"
@@ -130,11 +130,7 @@ boolean_literal ::= TRUE | FALSE {
}
null_literal ::= NULL
// 'PARAMETER' element is used by MongoDb-JSON-Query language to highlight params
// Can be used both as property name or/and value
parameter_literal ::= PARAMETER
literal ::= string_literal | number_literal | boolean_literal | null_literal | parameter_literal {
literal ::= string_literal | number_literal | boolean_literal | null_literal {
methods=[
isQuotedString
]

View File

@@ -53,9 +53,9 @@ formatter.objects.label=Objects
# Quickfixes and editor actions
quickfix.add.double.quotes.desc=Wrap with double quotes
surround.with.object.literal.desc=object literal
surround.with.array.literal.desc=array literal
surround.with.quotes.desc=quotes
surround.with.object.literal.desc=Object Literal
surround.with.array.literal.desc=Array Literal
surround.with.quotes.desc=Quotes
json.template.context.type=JSON
json.copy.to.clipboard=Copy {0} to clipboard
@@ -119,8 +119,8 @@ add.missing.0=Add missing {0}
add.missing.properties=Add missing properties
path.to.file.or.directory.relative.to.project.root.or.file.name=Path to file or directory relative to project root, or file name pattern like *.config.json
json.property.keys=JSON Property Keys
json.string.values=JSON String Values
json.property.keys=JSON property keys
json.string.values=JSON string values
property.0.is.deprecated.1=Property ''{0}'' is deprecated: {1}
add.mapping.for.a=Add mapping for a
no.schema.mappings.defined=No schema mappings defined

View File

@@ -33,7 +33,7 @@ import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
public final class JsonDuplicatePropertyKeysInspection extends LocalInspectionTool {
public class JsonDuplicatePropertyKeysInspection extends LocalInspectionTool {
private static final String COMMENT = "$comment";
@Override
@@ -46,20 +46,30 @@ public final class JsonDuplicatePropertyKeysInspection extends LocalInspectionTo
for (JsonProperty property : o.getPropertyList()) {
keys.putValue(property.getName(), property.getNameElement());
}
for (Map.Entry<String, Collection<PsiElement>> entry : keys.entrySet()) {
final Collection<PsiElement> sameNamedKeys = entry.getValue();
final String entryKey = entry.getKey();
if (sameNamedKeys.size() > 1 && (!isSchemaFile || !COMMENT.equalsIgnoreCase(entryKey))) {
for (PsiElement element : sameNamedKeys) {
holder.registerProblem(element, JsonBundle.message("inspection.duplicate.keys.msg.duplicate.keys", entryKey),
new NavigateToDuplicatesFix(sameNamedKeys, element, entryKey));
}
}
}
visitKeys(keys, isSchemaFile, holder);
}
};
}
protected static void visitKeys(MultiMap<String, PsiElement> keys, boolean isSchemaFile, @NotNull ProblemsHolder holder) {
for (Map.Entry<String, Collection<PsiElement>> entry : keys.entrySet()) {
final Collection<PsiElement> sameNamedKeys = entry.getValue();
final String entryKey = entry.getKey();
if (sameNamedKeys.size() > 1 && (!isSchemaFile || !COMMENT.equalsIgnoreCase(entryKey))) {
for (PsiElement element : sameNamedKeys) {
holder.registerProblem(element, JsonBundle.message("inspection.duplicate.keys.msg.duplicate.keys", entryKey),
getNavigateToDuplicatesFix(sameNamedKeys, element, entryKey));
}
}
}
}
protected static @NotNull NavigateToDuplicatesFix getNavigateToDuplicatesFix(Collection<PsiElement> sameNamedKeys,
PsiElement element,
String entryKey) {
return new NavigateToDuplicatesFix(sameNamedKeys, element, entryKey);
}
private static final class NavigateToDuplicatesFix extends LocalQuickFixAndIntentionActionOnPsiElement {
private final @NotNull Collection<SmartPsiElementPointer<PsiElement>> mySameNamedKeys;
private final @NotNull String myEntryKey;

View File

@@ -56,9 +56,7 @@ public class JsonStandardComplianceInspection extends LocalInspectionTool {
return new StandardJsonValidatingElementVisitor(holder);
}
@Nullable
private static PsiElement findTrailingComma(@NotNull JsonContainer container, @NotNull IElementType ending) {
final PsiElement lastChild = container.getLastChild();
protected static @Nullable PsiElement findTrailingComma(@NotNull PsiElement lastChild, @NotNull IElementType ending) {
if (lastChild.getNode().getElementType() != ending) {
return null;
}
@@ -69,7 +67,6 @@ public class JsonStandardComplianceInspection extends LocalInspectionTool {
return null;
}
@Override
public JComponent createOptionsPanel() {
final MultipleCheckboxOptionsPanel optionsPanel = new MultipleCheckboxOptionsPanel(this);
@@ -80,6 +77,28 @@ public class JsonStandardComplianceInspection extends LocalInspectionTool {
return optionsPanel;
}
protected static @NotNull String escapeSingleQuotedStringContent(@NotNull String content) {
final StringBuilder result = new StringBuilder();
boolean nextCharEscaped = false;
for (int i = 0; i < content.length(); i++) {
final char c = content.charAt(i);
if ((nextCharEscaped && c != '\'') || (!nextCharEscaped && c == '"')) {
result.append('\\');
}
if (c != '\\' || nextCharEscaped) {
result.append(c);
nextCharEscaped = false;
}
else {
nextCharEscaped = true;
}
}
if (nextCharEscaped) {
result.append('\\');
}
return result.toString();
}
private static class AddDoubleQuotesFix implements LocalQuickFix {
@NotNull
@Override
@@ -104,29 +123,6 @@ public class JsonStandardComplianceInspection extends LocalInspectionTool {
.error("Quick fix was applied to unexpected element", rawText, element.getParent().getText());
}
}
@NotNull
private static String escapeSingleQuotedStringContent(@NotNull String content) {
final StringBuilder result = new StringBuilder();
boolean nextCharEscaped = false;
for (int i = 0; i < content.length(); i++) {
final char c = content.charAt(i);
if ((nextCharEscaped && c != '\'') || (!nextCharEscaped && c == '"')) {
result.append('\\');
}
if (c != '\\' || nextCharEscaped) {
result.append(c);
nextCharEscaped = false;
}
else {
nextCharEscaped = true;
}
}
if (nextCharEscaped) {
result.append('\\');
}
return result.toString();
}
}
protected class StandardJsonValidatingElementVisitor extends JsonElementVisitor {
@@ -201,7 +197,7 @@ public class JsonStandardComplianceInspection extends LocalInspectionTool {
public void visitArray(@NotNull JsonArray array) {
if (myWarnAboutTrailingCommas && !allowTrailingCommas() &&
JsonStandardComplianceProvider.shouldWarnAboutTrailingComma(array)) {
final PsiElement trailingComma = findTrailingComma(array, JsonElementTypes.R_BRACKET);
final PsiElement trailingComma = findTrailingComma(array.getLastChild(), JsonElementTypes.R_BRACKET);
if (trailingComma != null) {
myHolder.registerProblem(trailingComma, JsonBundle.message("inspection.compliance.msg.trailing.comma"));
}
@@ -213,7 +209,7 @@ public class JsonStandardComplianceInspection extends LocalInspectionTool {
public void visitObject(@NotNull JsonObject object) {
if (myWarnAboutTrailingCommas && !allowTrailingCommas() &&
JsonStandardComplianceProvider.shouldWarnAboutTrailingComma(object)) {
final PsiElement trailingComma = findTrailingComma(object, JsonElementTypes.R_CURLY);
final PsiElement trailingComma = findTrailingComma(object.getLastChild(), JsonElementTypes.R_CURLY);
if (trailingComma != null) {
myHolder.registerProblem(trailingComma, JsonBundle.message("inspection.compliance.msg.trailing.comma"));
}

View File

@@ -19,7 +19,7 @@ import com.intellij.refactoring.util.CommonRefactoringUtil
import com.intellij.util.IncorrectOperationException
import org.jetbrains.annotations.Nls
class JsonSortPropertiesIntention : PsiElementBaseIntentionAction(), LowPriorityAction, LightEditCompatible, DumbAware {
open class JsonSortPropertiesIntention : PsiElementBaseIntentionAction(), LowPriorityAction, LightEditCompatible, DumbAware {
override fun getText(): @Nls(capitalization = Nls.Capitalization.Sentence) String = JsonBundle.message("json.intention.sort.properties")
override fun getFamilyName(): @Nls(capitalization = Nls.Capitalization.Sentence) String =