Regex that Will Match a Java Method Declaration

后端 未结 14 1287
半阙折子戏
半阙折子戏 2020-11-27 17:53

I need a Regex that will match a java method declaration. I have come up with one that will match a method declaration, but it requires the opening bracket of the method to

14条回答
  •  余生分开走
    2020-11-27 18:40

    (public|private|static|protected) ([A-Za-z0-9<>.]+) ([A-Za-z0-9]+)\(
    

    Also, here's a replace sequence you can use in IntelliJ

    $1 $2 $3(
    

    I use it like this:

    $1 $2 aaa$3(
    

    when converting Java files to Kotlin to prevent functions that start with "get" from automatically turning into variables. Doesn't work with "default" access level, but I don't use that much myself.

提交回复
热议问题