Regex that Will Match a Java Method Declaration

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

    This is for a more specific use case but it's so much simpler I believe its worth sharing. I did this for finding 'public static void' methods i.e. Play controller actions, and I did it from the Windows/Cygwin command line, using grep; see: https://stackoverflow.com/a/7167115/34806

    cat Foobar.java | grep -Pzo '(?s)public static void.*?\)\s+{'
    

    The last two entries from my output are as follows:

    public static void activeWorkEventStations (String type,
                String symbol,
                String section,
                String day,
                String priority,
                @As("yyyy-MM-dd") Date scheduleDepartureDate) {
    public static void getActiveScheduleChangeLogs(String type,
                String symbol,
                String section,
                String day,
                String priority,
                @As("yyyy-MM-dd") Date scheduleDepartureDate) {
    

提交回复
热议问题