 |
Properteer
Created by DannyVanBruggen.
Manual
Properteer comes in a single jar without dependencies
that contains a few annotations and the property generator.
If you are using Java 5.0 and up, you can include the jar and use the annotations to
indicate which fields in your classes should have getters and setters.
To generate them, you run the jar with one or more simple command line parameters.
Can't use Java 5.0? Just put the annotations in comments at the end of the line.
Properteer has a very simple parser that doesn't even know what a comment or annotation is.
ProperteerDesignDecisions
Annotating your fields
Include the jar file in your project. You now have access to three annotations that can be set on fields:
| | @Property | indicates that a getter and setter should be generated for this field. |
| | @ReadOnlyProperty | indicates that only a getter should be generated. |
| | @NotNullProperty | indicates that a getter and setter should be generated, and that the setter should check for null values. The generated code will throw a NullPointerException when it sees null being passed. |
A good example can be found in the source for Properteer, since Properteer is partly generated by itself.
class PropertyInfo {
private @ReadOnlyProperty boolean readOnly;
private @ReadOnlyProperty boolean notNull;
private @ReadOnlyProperty String type;
private @ReadOnlyProperty String name;
...
Generating code
Run the jar file like this:
java -jar properteer-1.jar
It will show all command line parameters.
You can fiddle with them to change what Properteer does.
For example: if you are annoyed with the space that the getters and setters take, you can configure them to be placed on a single line.
Very economical.
This will scan all java files in a directory, scan them, and add generated code to them:
java -jar properteer-1.jar src/com/laamella/test
The generated code ends up between two "tag lines:"
// Properteer.begin
public String getType() {
return type;
}
... more getters and setters ...
// Properteer.end
The space between these lines is overwritten during regeneration, so don't write your own code there.
Automating Properteer
Ant
...
Maven
...
Eclipse
...
Netbeans
...
JDeveloper
...
|