summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGeorge Fraser <george@fivetran.com>2018-12-20 21:58:47 -0800
committerGeorge Fraser <george@fivetran.com>2018-12-20 21:58:47 -0800
commitfe1838b24cda17d2fc3363e0ead6d9b35c609ab5 (patch)
tree715c907a81a47e03935ae19ab949f174f585bd42 /lib
parentfef7549aeb1772a31ae3b5044353893e2714ecc8 (diff)
downloadjava-language-server-fe1838b24cda17d2fc3363e0ead6d9b35c609ab5.zip
Robustly identify anonymous classes
Diffstat (limited to 'lib')
-rw-r--r--lib/java.tmLanguage.json153
1 files changed, 107 insertions, 46 deletions
diff --git a/lib/java.tmLanguage.json b/lib/java.tmLanguage.json
index ccbf770..5689b90 100644
--- a/lib/java.tmLanguage.json
+++ b/lib/java.tmLanguage.json
@@ -4,7 +4,7 @@
"scopeName": "source.java",
"patterns": [
{
- "begin": "\\b(package)\\b\\s*",
+ "begin": "\\b(package)\\b *",
"beginCaptures": {
"1": {
"name": "keyword.other.package.java"
@@ -22,7 +22,7 @@
]
},
{
- "begin": "\\b(import)\\b\\s*\\b(static)?\\b\\s",
+ "begin": "\\b(import)\\b *\\b(static)?\\b ",
"beginCaptures": {
"1": {
"name": "keyword.other.import.java"
@@ -60,7 +60,7 @@
"annotation": {
"patterns": [
{
- "begin": "(@[^\\s(]+)(\\()",
+ "begin": "(@[^ (]+)(\\()",
"beginCaptures": {
"1": {
"name": "punctuation.definition.tag"
@@ -86,7 +86,7 @@
"name": "punctuation.definition.tag.assign"
}
},
- "match": "(\\w*)\\s*(=)"
+ "match": "(\\w*) *(=)"
},
{
"include": "#code"
@@ -257,41 +257,115 @@
}
]
},
- "code": {
+ "block-code": {
"patterns": [
{
- "include": "#class-declaration"
+ "COMMENT": "prevent `) {` at the end of `if (...) {` from being interpreted as anonymous class",
+ "begin": "\\b(if) *(?=\\()",
+ "end": "(?={)",
+ "beginCaptures": {
+ "1": {
+ "name": "keyword.control.if.java"
+ }
+ },
+ "name": "meta.if.java",
+ "patterns": [
+ {
+ "include": "#code"
+ }
+ ]
},
{
- "include": "#anonymous-class"
+ "COMMENT": "prevent `) {` at the end of `try (...) {` from being interpreted as anonymous class",
+ "begin": "\\b(try) *(?=\\()",
+ "end": "(?={)",
+ "beginCaptures": {
+ "1": {
+ "name": "keyword.control.try.java"
+ }
+ },
+ "name": "meta.try-with-resources.java",
+ "patterns": [
+ {
+ "include": "#code"
+ }
+ ]
},
{
- "include": "#keywords"
+ "COMMENT": "prevent `) {` at the end of `catch (...) {` from being interpreted as anonymous class",
+ "begin": "\\b(catch) *(?=\\()",
+ "end": "(?={)",
+ "beginCaptures": {
+ "1": {
+ "name": "keyword.control.catch.java"
+ }
+ },
+ "name": "meta.catch.java",
+ "patterns": [
+ {
+ "match": "(\\w+\\.)*[A-Z]\\w*",
+ "name": "entity.name.type.exception.java"
+ },
+ {
+ "match": "[a-z]\\w*",
+ "name": "variable.other.declaration.java"
+ },
+ {
+ "include": "#comments"
+ }
+ ]
},
{
- "include": "#comments"
+ "COMMENT": "otherwise, interpret `) {` as beginning of anonymous class",
+ "begin": "(?<=\\)) *({)",
+ "end": "}",
+ "beginCaptures": {
+ "1": {
+ "name": "markup.underline"
+ }
+ },
+ "endCaptures": {
+ "0": {
+ "name": "markup.underline"
+ }
+ },
+ "name": "meta.anonymous.class.java",
+ "patterns": [
+ {
+ "include": "#class-body"
+ }
+ ]
},
{
- "include": "#constants"
+ "include": "#code"
+ }
+ ]
+ },
+ "code": {
+ "patterns": [
+ {
+ "include": "#class-declaration"
},
{
- "include": "#annotation"
+ "include": "#block"
},
{
- "include": "#catch"
+ "include": "#paren"
},
{
"include": "#throws"
},
{
- "include": "#block"
- }
- ]
- },
- "anonymous-class": {
- "patterns": [
+ "include": "#annotation"
+ },
{
- "TODO": "use begin/end to gain context?"
+ "include": "#keywords"
+ },
+ {
+ "include": "#comments"
+ },
+ {
+ "include": "#constants"
}
]
},
@@ -425,62 +499,49 @@
}
]
},
- "catch": {
+ "throws": {
"patterns": [
{
- "begin": "\\b(catch)\\s*(?=\\()",
+ "begin": "\\b(throws)\\b",
+ "end": "(?=[{;])",
"beginCaptures": {
"1": {
- "name": "keyword.control.catch.java"
+ "name": "keyword.other.throws.java"
}
},
- "end": "(?={)",
- "name": "meta.catch.java",
+ "name": "meta.throws.java",
"patterns": [
{
"match": "(\\w+\\.)*[A-Z]\\w*",
"name": "entity.name.type.exception.java"
},
{
- "match": "[a-z]\\w*",
- "name": "variable.other.declaration.java"
- },
- {
"include": "#comments"
}
]
}
]
},
- "throws": {
+ "block": {
"patterns": [
{
- "begin": "\\b(throws)\\b",
- "beginCaptures": {
- "1": {
- "name": "keyword.other.throws.java"
- }
- },
- "end": "(?=[{;])",
- "name": "meta.throws.java",
+ "begin": "{",
+ "end": "}",
+ "name": "meta.block.java",
"patterns": [
{
- "match": "(\\w+\\.)*[A-Z]\\w*",
- "name": "entity.name.type.exception.java"
- },
- {
- "include": "#comments"
+ "include": "#block-code"
}
]
}
]
},
- "block": {
+ "paren": {
"patterns": [
{
- "begin": "{",
- "end": "}",
- "name": "meta.block.java",
+ "begin": "\\(",
+ "end": "\\)",
+ "name": "meta.paren.java",
"patterns": [
{
"include": "#code"