Andrew
Andrew

Reputation: 577

Adding custom auto-comments to new functions or logic statements in Netbeans 7.3.1 (java)

I've recently started working on a project with someone and he prefers the code to be commented in a very particular manner. Instead off adding it all by hand I was wondering if Netbeans had any way to add custom comments to new functions and logic statements. The comments added would be backslashes after a closing bracket and then the name of what it's closing. For example:

public void funcA(int arg){
   if(arg>2)
   {
      System.out.println("hi");
   } //if
} //funcA

I looked around but all I could find was creating your own code template for a new class, which isn't what I need. Any help? thanks.

Upvotes: 1

Views: 169

Answers (1)

MikeFHay
MikeFHay

Reputation: 9023

If your code is consistently indented as in your question, you can manage with a regular expression like this:

Capture:

(?s)^(\s*)if.*?\1\{.*?\1\}

Replace:

$0 //if

Where the (?s) at the start turns on single-line mode (meaning dots match newlines), and the backreferences ensure that the if statement and braces match in indentation and are therefore matching.

Upvotes: 1

Related Questions