Skip to content

Commit

Permalink
Add Matchit support for Java statements
Browse files Browse the repository at this point in the history
  • Loading branch information
chylex committed Jan 22, 2024
1 parent 722cffb commit be6ea3b
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/main/java/com/maddyhome/idea/vim/extension/matchit/Matchit.kt
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ private object FileTypePatterns {

return if (fileTypeName in htmlLikeFileTypes) {
this.htmlPatterns
} else if (fileTypeName == "JAVA" || fileExtension == "java") {
this.javaPatterns
} else if (fileTypeName == "Ruby" || fileExtension == "rb") {
this.rubyPatterns
} else if (fileTypeName == "RHTML" || fileExtension == "erb") {
Expand All @@ -242,6 +244,7 @@ private object FileTypePatterns {
)

private val htmlPatterns = createHtmlPatterns()
private val javaPatterns = createJavaPatterns()
private val rubyPatterns = createRubyPatterns()
private val rubyAndHtmlPatterns = rubyPatterns + htmlPatterns
private val phpPatterns = createPhpPatterns()
Expand Down Expand Up @@ -270,6 +273,14 @@ private object FileTypePatterns {
LanguagePatterns(linkedMapOf(openingTagPattern to htmlSearchPair), linkedMapOf(closingTagPattern to htmlSearchPair))
)
}

private fun createJavaPatterns(): LanguagePatterns {
return (
LanguagePatterns("\\b(?<!else\\s+)if\\b", "\\belse\\s+if\\b", "\\belse(?!\\s+if)\\b") +
LanguagePatterns("\\bdo\\b", "\\bwhile\\b") +
LanguagePatterns("\\btry\\b", "\\bcatch\\b", "\\bfinally\\b")
)
}

private fun createRubyPatterns(): LanguagePatterns {
// Original patterns: https://github.com/vim/vim/blob/master/runtime/ftplugin/ruby.vim
Expand Down

0 comments on commit be6ea3b

Please sign in to comment.