Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Intellij Community
Commits
68fe7006
Commit
68fe7006
authored
7 years ago
by
Anton Lobov
Browse files
Options
Download
Email Patches
Plain Diff
WEB-31909 Allow to suppress warning for NaN in json
parent
959a0b17
Changes
7
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
json/gen/com/intellij/json/_JsonLexer.java
+154
-140
json/gen/com/intellij/json/_JsonLexer.java
json/gen/com/intellij/json/json5/_Json5Lexer.java
+65
-58
json/gen/com/intellij/json/json5/_Json5Lexer.java
json/src/com/intellij/json/JsonBundle.properties
+1
-0
json/src/com/intellij/json/JsonBundle.properties
json/src/com/intellij/json/_JsonLexer.flex
+1
-1
json/src/com/intellij/json/_JsonLexer.flex
json/src/com/intellij/json/codeinsight/JsonStandardComplianceInspection.java
+16
-0
...ij/json/codeinsight/JsonStandardComplianceInspection.java
json/src/com/intellij/json/codeinsight/StandardJsonLiteralChecker.java
+7
-1
...intellij/json/codeinsight/StandardJsonLiteralChecker.java
json/src/com/intellij/json/json5/codeinsight/Json5StandardComplianceInspection.java
+5
-0
.../json5/codeinsight/Json5StandardComplianceInspection.java
with
249 additions
and
200 deletions
+249
-200
json/gen/com/intellij/json/_JsonLexer.java
+
154
-
140
View file @
68fe7006
This diff is collapsed.
Click to expand it.
json/gen/com/intellij/json/json5/_Json5Lexer.java
+
65
-
58
View file @
68fe7006
...
...
@@ -151,13 +151,14 @@ public class _Json5Lexer implements FlexLexer {
private
static
final
String
ZZ_ACTION_PACKED_0
=
"\1\1\1\2\1\3\2\4\1\3\1\5\1\6\6\1"
+
"\5\4\1\7\1\10\1\11\1\12\1\13\1\14\1\15"
+
"\1\16\1\5\2\0\1\6\5\1\1\4\2\1\5\4"
+
"\1\15\1\16\1\4\2\5\2\6\1\1\4\4\1\1"
+
"\1\0\1\16\1\4\1\17\1\4\1\20\1\16\1\4"
+
"\1\21\2\4"
;
"\1\16\1\5\2\0\1\6\4\1\2\0\1\1\1\4"
+
"\2\1\5\4\1\15\1\16\1\4\2\5\2\6\2\0"
+
"\1\1\4\4\1\1\1\0\1\16\1\0\1\1\1\4"
+
"\1\17\1\4\1\20\1\16\1\0\1\4\1\21\1\0"
+
"\1\4\1\0\1\4\1\0"
;
private
static
int
[]
zzUnpackAction
()
{
int
[]
result
=
new
int
[
6
8
];
int
[]
result
=
new
int
[
7
8
];
int
offset
=
0
;
offset
=
zzUnpackAction
(
ZZ_ACTION_PACKED_0
,
offset
,
result
);
return
result
;
...
...
@@ -188,12 +189,13 @@ public class _Json5Lexer implements FlexLexer {
"\0\51\0\u030b\0\u0334\0\51\0\u035d\0\u0386\0\51\0\u03af"
+
"\0\u03d8\0\u0401\0\u042a\0\u0453\0\u047c\0\u04a5\0\u04ce\0\u04f7"
+
"\0\u0520\0\u0549\0\u0572\0\u059b\0\u05c4\0\u05ed\0\u0616\0\u063f"
+
"\0\u0668\0\u0691\0\u06ba\0\u047c\0\u06e3\0\u070c\0\u0735\0\u075e"
+
"\0\173\0\u0787\0\173\0\u07b0\0\173\0\u07d9\0\173\0\51"
+
"\0\u0802\0\173\0\u082b\0\u0854"
;
"\0\u0668\0\u0691\0\u06ba\0\u06e3\0\u070c\0\u0735\0\u075e\0\u04ce"
+
"\0\u0787\0\u07b0\0\u07d9\0\u0802\0\173\0\u082b\0\173\0\u0854"
+
"\0\51\0\u087d\0\173\0\u08a6\0\173\0\51\0\u08cf\0\u08f8"
+
"\0\173\0\u0921\0\u094a\0\u0973\0\u099c\0\u09c5"
;
private
static
int
[]
zzUnpackRowMap
()
{
int
[]
result
=
new
int
[
6
8
];
int
[]
result
=
new
int
[
7
8
];
int
offset
=
0
;
offset
=
zzUnpackRowMap
(
ZZ_ROWMAP_PACKED_0
,
offset
,
result
);
return
result
;
...
...
@@ -226,61 +228,64 @@ public class _Json5Lexer implements FlexLexer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\4\5\0\17\4"
+
"\6\0\1\4\1\51\3\4\5\0\2\4\1\0\2\4"
+
"\5\0\15\4\1\52\1\4\6\0\5\4\5\0\2\4"
+
"\1\0\2\4\5\0\17\4\6\0\1\53\4\4\5\0"
+
"\2\4\1\0\2\4\5\0\15\4\1\54\1\4\6\0"
+
"\5\4\1\55\3\0\1\55\2\32\1\0\1\4\1\32"
+
"\5\55\17\32\6\55\5\32\5\56\2\33\1\56\1\33"
+
"\1\57\5\56\17\33\6\56\5\33\3\7\1\60\3\7"
+
"\1\61\2\7\1\61\36\7\3\10\1\62\3\10\1\63"
+
"\2\10\1\63\36\10\20\0\3\42\1\43\22\0\1\43"
+
"\22\0\2\41\1\42\1\43\22\0\1\43\22\0\2\42"
+
"\1\0\1\43\22\0\1\43\20\0\4\46\34\0\2\4"
+
"\6\0\1\55\4\4\5\0\2\4\1\0\2\4\5\0"
+
"\15\4\1\56\1\4\6\0\5\4\1\57\3\0\1\57"
+
"\2\32\1\0\1\4\1\32\5\57\17\32\6\57\5\32"
+
"\5\60\2\33\1\60\1\33\1\61\5\60\17\33\6\60"
+
"\5\33\3\7\1\62\3\7\1\63\2\7\1\63\36\7"
+
"\3\10\1\64\3\10\1\65\2\10\1\65\36\10\20\0"
+
"\3\42\1\43\22\0\1\43\22\0\2\41\1\42\1\43"
+
"\22\0\1\43\22\0\2\42\1\0\1\43\22\0\1\43"
+
"\20\0\4\50\55\0\1\66\56\0\1\67\21\0\2\4"
+
"\1\0\2\4\5\0\1\4\3\15\1\16\12\4\6\0"
+
"\2\4\1\16\2\4\5\0\1\
64
\1\4\1\0\2\4"
+
"\5\0\1\4\2\
64
\1\4\1\
64
\3\4\1\
64
\4\4"
+
"\1\
64
\1\4\6\0\2\4\1\
64
\2\4\20\0\2\
46
"
+
"\34\0\2\4\1\0\2\4\5\0\1\4\2\
47
\14\4"
+
"\2\4\1\16\2\4\5\0\1\
70
\1\4\1\0\2\4"
+
"\5\0\1\4\2\
70
\1\4\1\
70
\3\4\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\4\6\0\3\4\1\75\1\4\5\0\2\4"
+
"\1\0\2\4\5\0\17\4\6\0\4\4\1\76\5\0"
+
"\2\4\1\0\2\4\5\0\17\4\6\0\2\4\1\77"
+
"\2\4\6\56\1\100\2\56\1\72\37\56\5\0\2\4"
+
"\1\0\2\4\5\0\7\4\1\101\7\4\6\0\5\4"
+
"\5\0\2\4\1\0\2\4\5\0\17\4\6\0\2\4"
+
"\1\102\2\4\5\0\2\4\1\0\2\4\5\0\11\4"
+
"\1\103\5\4\6\0\5\4\5\0\2\4\1\0\2\4"
+
"\5\0\12\4\1\104\4\4\6\0\5\4\5\0\2\4"
+
"\1\0\2\4\5\0\13\4\1\71\3\4\6\0\5\4"
;
"\36\10\1\64\3\10\1\65\2\10\1\65\1\10\1\36"
+
"\1\37\33\10\27\0\1\100\54\0\1\101\22\0\2\4"
+
"\1\0\2\4\5\0\11\4\1\102\5\4\6\0\5\4"
+
"\5\0\2\4\1\0\2\4\5\0\17\4\6\0\3\4"
+
"\1\103\1\4\5\0\2\4\1\0\2\4\5\0\17\4"
+
"\6\0\4\4\1\104\5\0\2\4\1\0\2\4\5\0"
+
"\17\4\6\0\2\4\1\105\2\4\6\60\1\106\2\60"
+
"\1\76\37\60\30\0\1\107\25\0\2\4\1\0\2\4"
+
"\5\0\7\4\1\110\7\4\6\0\5\4\5\0\2\4"
+
"\1\0\2\4\5\0\17\4\6\0\2\4\1\111\2\4"
+
"\26\0\1\112\27\0\2\4\1\0\2\4\5\0\11\4"
+
"\1\113\5\4\6\0\5\4\30\0\1\114\25\0\2\4"
+
"\1\0\2\4\5\0\12\4\1\115\4\4\6\0\5\4"
+
"\31\0\1\116\24\0\2\4\1\0\2\4\5\0\13\4"
+
"\1\75\3\4\6\0\5\4\32\0\1\101\16\0"
;
private
static
int
[]
zzUnpackTrans
()
{
int
[]
result
=
new
int
[
2
173
];
int
[]
result
=
new
int
[
2
542
];
int
offset
=
0
;
offset
=
zzUnpackTrans
(
ZZ_TRANS_PACKED_0
,
offset
,
result
);
return
result
;
...
...
@@ -319,10 +324,12 @@ public class _Json5Lexer implements FlexLexer {
private
static
final
String
ZZ_ATTRIBUTE_PACKED_0
=
"\1\1\1\11\21\1\6\11\2\1\1\11\2\0\1\11"
+
"\32\1\1\0\5\1\1\11\4\1"
;
"\4\1\2\0\20\1\2\0\6\1\1\0\1\1\1\0"
+
"\1\11\4\1\1\11\1\0\2\1\1\0\1\1\1\0"
+
"\1\1\1\0"
;
private
static
int
[]
zzUnpackAttribute
()
{
int
[]
result
=
new
int
[
6
8
];
int
[]
result
=
new
int
[
7
8
];
int
offset
=
0
;
offset
=
zzUnpackAttribute
(
ZZ_ATTRIBUTE_PACKED_0
,
offset
,
result
);
return
result
;
...
...
This diff is collapsed.
Click to expand it.
json/src/com/intellij/json/JsonBundle.properties
+
1
-
0
View file @
68fe7006
...
...
@@ -22,6 +22,7 @@ inspection.compliance.msg.multiple.top.level.values=JSON standard allows only on
inspection.compliance.option.comments
=
Warn about comments
inspection.compliance.option.multiple.top.level.values
=
Warn about multiple top-level values
inspection.compliance.option.nan.infinity
=
Warn about NaN and Infinity/-Infinity numeric values
inspection.duplicate.keys.name
=
Duplicate keys in object literals
inspection.duplicate.keys.msg.duplicate.keys
=
Object contains duplicate keys "{0}"
...
...
This diff is collapsed.
Click to expand it.
json/src/com/intellij/json/_JsonLexer.flex
+
1
-
1
View file @
68fe7006
...
...
@@ -29,7 +29,7 @@ LINE_COMMENT="//".*
BLOCK_COMMENT
=
"/"
\*([^*]|\*+[^*/])*(\*+
"/"
)?
DOUBLE_QUOTED_STRING
=\
"([^
\\\"\r\n
]|
\\
[^
\r\n
])*
\"
?
SINGLE_QUOTED_STRING='([^
\\
'
\r\n
]|
\\
[^
\r\n
])*'?
NUMBER=-?(0|[1-9][0-9]*)(\.[0-9]+)?([eE][+-]?[0-9]*)?
NUMBER=
(
-?(0|[1-9][0-9]*)(\.[0-9]+)?([eE][+-]?[0-9]*)?
)|Infinity|-Infinity|NaN
IDENTIFIER=[[:jletterdigit:]~!()*\-."
/
"@\^<>=]+
%%
...
...
This diff is collapsed.
Click to expand it.
json/src/com/intellij/json/codeinsight/JsonStandardComplianceInspection.java
+
16
-
0
View file @
68fe7006
...
...
@@ -51,6 +51,7 @@ public class JsonStandardComplianceInspection extends LocalInspectionTool {
private
static
final
Logger
LOG
=
Logger
.
getInstance
(
JsonStandardComplianceInspection
.
class
);
public
boolean
myWarnAboutComments
=
true
;
public
boolean
myWarnAboutNanInfinity
=
true
;
public
boolean
myWarnAboutMultipleTopLevelValues
=
true
;
@NotNull
...
...
@@ -90,6 +91,7 @@ public class JsonStandardComplianceInspection extends LocalInspectionTool {
final
MultipleCheckboxOptionsPanel
optionsPanel
=
new
MultipleCheckboxOptionsPanel
(
this
);
optionsPanel
.
addCheckbox
(
JsonBundle
.
message
(
"inspection.compliance.option.comments"
),
"myWarnAboutComments"
);
optionsPanel
.
addCheckbox
(
JsonBundle
.
message
(
"inspection.compliance.option.multiple.top.level.values"
),
"myWarnAboutMultipleTopLevelValues"
);
optionsPanel
.
addCheckbox
(
JsonBundle
.
message
(
"inspection.compliance.option.nan.infinity"
),
"myWarnAboutNanInfinity"
);
return
optionsPanel
;
}
...
...
@@ -179,9 +181,23 @@ public class JsonStandardComplianceInspection extends LocalInspectionTool {
if
(
JsonPsiUtil
.
isPropertyKey
(
literal
)
&&
!
isValidPropertyName
(
literal
))
{
myHolder
.
registerProblem
(
literal
,
JsonBundle
.
message
(
"inspection.compliance.msg.illegal.property.key"
),
new
AddDoubleQuotesFix
());
}
// for standard JSON, the inspection for NaN, Infinity and -Infinity is now configurable
if
(!
allowNanInfinity
()
&&
literal
instanceof
JsonNumberLiteral
&&
myWarnAboutNanInfinity
)
{
final
String
text
=
JsonPsiUtil
.
getElementTextWithoutHostEscaping
(
literal
);
if
(
StandardJsonLiteralChecker
.
INF
.
equals
(
text
)
||
StandardJsonLiteralChecker
.
MINUS_INF
.
equals
(
text
)
||
StandardJsonLiteralChecker
.
NAN
.
equals
(
text
))
{
myHolder
.
registerProblem
(
literal
,
JsonBundle
.
message
(
"syntax.error.illegal.floating.point.literal"
));
}
}
super
.
visitLiteral
(
literal
);
}
protected
boolean
allowNanInfinity
()
{
return
false
;
}
@Override
public
void
visitReferenceExpression
(
@NotNull
JsonReferenceExpression
reference
)
{
if
(!
allowIdentifierPropertyNames
()
||
!
JsonPsiUtil
.
isPropertyKey
(
reference
)
||
!
isValidPropertyName
(
reference
))
{
...
...
This diff is collapsed.
Click to expand it.
json/src/com/intellij/json/codeinsight/StandardJsonLiteralChecker.java
+
7
-
1
View file @
68fe7006
...
...
@@ -11,11 +11,17 @@ import java.util.regex.Pattern;
public
class
StandardJsonLiteralChecker
implements
JsonLiteralChecker
{
private
static
final
Pattern
VALID_ESCAPE
=
Pattern
.
compile
(
"\\\\([\"\\\\/bfnrt]|u[0-9a-fA-F]{4})"
);
private
static
final
Pattern
VALID_NUMBER_LITERAL
=
Pattern
.
compile
(
"-?(0|[1-9][0-9]*)(\\.[0-9]+)?([eE][+-]?[0-9]+)?"
);
public
static
final
String
INF
=
"Infinity"
;
public
static
final
String
MINUS_INF
=
"-Infinity"
;
public
static
final
String
NAN
=
"NaN"
;
@Nullable
@Override
public
String
getErrorForNumericLiteral
(
String
literalText
)
{
if
(!
VALID_NUMBER_LITERAL
.
matcher
(
literalText
).
matches
())
{
if
(!
INF
.
equals
(
literalText
)
&&
!
MINUS_INF
.
equals
(
literalText
)
&&
!
NAN
.
equals
(
literalText
)
&&
!
VALID_NUMBER_LITERAL
.
matcher
(
literalText
).
matches
())
{
return
JsonBundle
.
message
(
"syntax.error.illegal.floating.point.literal"
);
}
return
null
;
...
...
This diff is collapsed.
Click to expand it.
json/src/com/intellij/json/json5/codeinsight/Json5StandardComplianceInspection.java
+
5
-
0
View file @
68fe7006
...
...
@@ -52,6 +52,11 @@ public class Json5StandardComplianceInspection extends JsonStandardComplianceIns
return
true
;
}
@Override
protected
boolean
allowNanInfinity
()
{
return
true
;
}
protected
boolean
isValidPropertyName
(
@NotNull
PsiElement
literal
)
{
if
(
literal
instanceof
JsonLiteral
)
{
String
textWithoutHostEscaping
=
JsonPsiUtil
.
getElementTextWithoutHostEscaping
(
literal
);
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help