Regex that Will Match a Java Method Declaration

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

    I built a vim regex to do this for ctrlp/funky based on Georgios Gousios's answer.

        let regex = '\v^\s+'                " preamble
        let regex .= '%(<\w+>\s+){0,3}'     " visibility, static, final
        let regex .= '%(\w|[<>[\]])+\s+'    " return type
        let regex .= '\w+\s*'               " method name
        let regex .= '\([^\)]*\)'           " method parameters
        let regex .= '%(\w|\s|\{)+$'        " postamble
    

    I'd guess that looks like this in Java:

    ^\s+(?:<\w+>\s+){0,3}(?:[\w\<\>\[\]])+\s+\w+\s*\([^\)]*\)(?:\w|\s|\{)+$
    

提交回复
热议问题