-1

I have a logger class with an isDebugEnabled() method. This is duplicated over 16,000 times so we now check if it is enabled in the method itself as opposed to everywhere in the project.

        if ( logger.isDebugEnabled() ) 
    {
        logger.logMethodEntryMessage();
    }

I want to remove the if statement but keep the logger.logMethodEntryMessage(); everywhere in the project. Is it possible to use Notepad++ and regex or eclipse and regex to accomplish this?

Thanks for your help

Deane Kane
  • 126
  • 2
  • 15
  • It's the same if statement everywhere? – ctwheels Nov 21 '19 at 16:22
  • @ctwheels pretty much, some invoke a different logger method but they are all the same format. – Deane Kane Nov 21 '19 at 16:25
  • 2
    @DeaneKane it's important for you to give us more specifics on it. Because based on the information here [this](https://regex101.com/r/5vKAkm/1) `(?:if\s*\(\s*logger.isDebugEnabled\(\)\s*\)\s*{\s*|\G(?!\A))(?:(logger.logMethodEntryMessage\(\)\s*;)|\s*})` works, but if it's a different method, it won't. – ctwheels Nov 21 '19 at 16:26
  • @tobias_k No I am not looking for Java code to do the replacement. Just code I am replacing written in Java. – Deane Kane Nov 21 '19 at 16:26
  • @ctwheels Thanks, if I replace that method with another method it should work? I only have about 3 different methods. `logMethodExitMessage();` My `logger.debug( ("fileType: " + fileType) );` method takes various parameters though. – Deane Kane Nov 21 '19 at 16:29
  • @DeaneKane yes [this](https://regex101.com/r/5vKAkm/2): `(?:if\s*\(\s*logger.isDebugEnabled\(\)\s*\)\s*{\s*)(logger.logMethodEntryMessage\(\)\s*;)\s*\}` works in Notepad++. You can change the method easily this way. – ctwheels Nov 21 '19 at 16:31
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/202816/discussion-between-deane-kane-and-ctwheels). – Deane Kane Nov 21 '19 at 16:37

1 Answers1

-1

I believe a simple search and replace should work, Ctrl+R in Intellij or Ctrl+F in Eclipse. Here's a similar question.

w1sh
  • 68
  • 9