Regex that Will Match a Java Method Declaration

后端 未结 14 1324
半阙折子戏
半阙折子戏 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:36

    I found seba229's answer useful, it captures most of the scenarios, but not the following,

    public  T name(final Class x, final T y)
    

    This regex will capture that also.

    ((public|private|protected|static|final|native|synchronized|abstract|transient)+\s)+[\$_\w\<\>\w\s\[\]]*\s+[\$_\w]+\([^\)]*\)?\s*
    

    Hope this helps.

提交回复
热议问题