diff --git a/crates/core/src/test.rs b/crates/core/src/test.rs index 0fc94f0d5..11d047672 100644 --- a/crates/core/src/test.rs +++ b/crates/core/src/test.rs @@ -8848,9 +8848,10 @@ fn matches_java_imports() { |language java | |or { - | `import $_` => `generic import`, - | `import org.springframework.mock.$_` => `spring mock import`, - | `import org.springframework.$_` => `spring import`, + | `import $import;` where { + | $import <: contains `org.springframework` + | } => `spring import`, + | `import $_;` => `generic import`, |} |"# .trim_margin() @@ -8861,7 +8862,7 @@ fn matches_java_imports() { |import org.springframework.mock.web.MockHttpServletRequest; |import org.junit.Test; |import org.junit.runner.RunWith; - |import org.springframework.mock.web.MockHttpServletRequest; + |import org.springframework.mine.web.MockHttpServletRequest; |"# .trim_margin() .unwrap() @@ -8869,10 +8870,10 @@ fn matches_java_imports() { expected: r#" |package com.example.test; | + |spring import |generic import - |spring mock import |generic import - |spring mock import + |spring import |"# .trim_margin() .unwrap() diff --git a/crates/language/src/java.rs b/crates/language/src/java.rs index 3b71c2b3f..32b206ba1 100644 --- a/crates/language/src/java.rs +++ b/crates/language/src/java.rs @@ -62,6 +62,7 @@ impl Language for Java { fn snippet_context_strings(&self) -> &[(&'static str, &'static str)] { &[ ("", ""), + ("import ", ";"), ("GRIT_VAR = ", ";"), ("class GRIT_CLASS { ", " }"), ("class GRIT_CLASS { ", " GRIT_FUNCTION() {} }"), diff --git a/resources/language-metavariables/tree-sitter-java/grammar.js b/resources/language-metavariables/tree-sitter-java/grammar.js index b1247689f..d76c92c88 100644 --- a/resources/language-metavariables/tree-sitter-java/grammar.js +++ b/resources/language-metavariables/tree-sitter-java/grammar.js @@ -795,13 +795,13 @@ module.exports = grammar({ seq(field('annotations', repeat($._annotation)), 'package', field('package', $._name), ';'), import_declaration: ($) => - prec(PREC.DECL, seq( + seq( 'import', optional('static'), - field('package', choice($._name, $.grit_metavariable)), + field('package', $._name), optional(seq('.', $.asterisk)), ';', - )), + ), asterisk: ($) => '*', diff --git a/resources/metavariable-grammars/java-metavariable-grammar.js b/resources/metavariable-grammars/java-metavariable-grammar.js index 55a79c628..d76c92c88 100644 --- a/resources/metavariable-grammars/java-metavariable-grammar.js +++ b/resources/metavariable-grammars/java-metavariable-grammar.js @@ -181,7 +181,7 @@ module.exports = grammar({ token.immediate( seq( '\\', - choice(/[^xu0-7]/, /[0-7]{1,3}/, /x[0-9a-fA-F]{2}/, /u[0-9a-fA-F]{4}/, /u{[0-9a-fA-F]+}/), + choice(/[^xu0-7]/, /[0-7]{1,3}/, /x[0-9a-fA-F]{2}/, /u[0-9a-fA-F]{4}/, /u[0-9a-fA-F]+/), ), ),