does anyone know of an existing script to create java objects based on constructor?
I was thinking about writing one but decided to see if one already exists because it seems pretty simple.
Basically a common component of java objects involves writing
-
public class nameofObjectwhere the IDE typically takes care of the package statement and the class statement. -
creating private variables
-
creating the constructor with the same names of those variables passed in
-
making getters and setters
-
deciding to assign the private variables to the local variables within the constructor , ie
public nameofObject(String a, String b, String c){ this.a = a; this.b = b; this.c = c; }
this process is very predictable (great for a script) and can be tedious (also great for a computer)
That example only has 3 variables, but objects can have 20, or hundreds of variables.
I haven’t seen an IDE or a script automatically create an entire object based on its constructor, but that would be very convenient, and I am considering writing a script in python or ant or bash to do this.
But before I reinvent the wheel, have you ever seen one that does this?
Eclipse can help you as long as you create the arguments to the constructor.
New classes (with package definition) can be created using the New class wizard (1).
Ctrl+1 or Command+1 can:
Create field assignments including the private variables, when pressed while cursor is in a constructor argument (2, 5)
Create setters/getters, when pressed while cursor is in a field (4)
This requires multiple actions/key presses, but is quite fast and convenient, and very flexible.