Add getters and setters to a set of variables Any improvements are welcome.

a.bat

sed -r "s/private (.*) (.*);(.*)/&amp;\npublic \1 get\u\2(){return \2;}\npublic void set\u\2(\u\2){this.\2=\u\2;}\n/" "%~1"&gt;"%~2"


in:

private String firstName;// Stores firstName
private String lastName;
private String address;


using a.bat in out

out:

private String firstName;// Stores firstName
public String getFirstName(){return firstName;}
public void setFirstName(FirstName){this.firstName=FirstName;}

private String lastName;
public String getLastName(){return lastName;}
public void setLastName(LastName){this.lastName=LastName;}

private String address;
public String getAddress(){return address;}
public void setAddress(Address){this.address=Address;}


To do:
add javadoc generation to methods.
You forgot the parameter type in the setter methods (including @blufox suggestion):

sed -r "s/private\s+([^; ]+)\s+([^; ]+)\s*;(.*)$/&amp;\npublic \1 get\u\2(){return \2;}\npublic void set\u\2(\1 \2){this.\2=\u\2;}\n/" "%~1"&gt;"%~2"


which produces:

private String firstName;// Stores firstName
public String getFirstName(){return firstName;}
public void setFirstName(String firstName){this.firstName=FirstName;}


But: you better use an IDE (e.g., Eclipse) for these tasks. You are trying to parse Java code with a regex which is a bad idea.

Just some examples:


declarations could be on different lines

private String // some comment
    myVariableOnTheNextLine
    // some other comment
    ; // semicolon

the public or private modifier could be omitted

String myString;

fields can be initialized

String myString = "my string";

fields can be declared final

private final String myString;

and so on