Nobody likes to write properties boilerplate--the getter, the setter, the Javadoc for the getter, the Javadoc for the setter, you know the drill. Ok, you say, Eclipse writes it for you. But you still have to read it. Pages and pages of it in many real life classes. My graduate student Alexandre Alves implemented a Mustang compiler extension to remove the drudgery. We want to get this feature into Dolphin and need your help. Try it out and let us know what you like and what needs work!
Here is a simple code example from the JBoss EJB3 tutorial.
@Entity public class LineItem implements java.io.Serializable { private int id; private double subtotal; private int quantity; private String product; private Order order; @Id @GeneratedValue(strategy=GenerationType.AUTO) public int getId() { return id; } public void setId(int id) { this.id = id; } public double getSubtotal() { return subtotal; } public void setSubtotal(double subtotal) { this.subtotal = subtotal; } public int getQuantity() { return quantity; } public void setQuantity(int quantity) { this.quantity = quantity; } public String getProduct() { return product; } public void setProduct(String product) { this.product = product; } @ManyToOne @JoinColumn(name = "order_id") public Order getOrder() { return order; } public void setOrder(Order order) { this.order = order; } }
64 lines.
Here is what you want to read:
@Entity public class LineItem implements java.io.Serializable { @Id @GeneratedValue(strategy=GenerationType.AUTO) @Property private int id; @Property private double subtotal; @Property private int quantity; @Property private String product; @ManyToOne @JoinColumn(name = "order_id") @Property private Order order;@ }
12 lines.
That's only 20% of the original. The remaining 80% is boilerplate.
And that's not even counting the Javadoc!
There has to be a better way. My graduate student Alexandre Alves has provided just that in his M.S. thesis. He implemented
His tools support the @Property annotation of the preceding example. Simply call his propjavac, and it synthesizes the getters and setters and adds a Properties section to the Javadoc.
But wait, there's more. We give you syntax for accessing the properties, almost like in JavaScript or Visual Basic:
LineItem item = new LineItem(); item.@subtotal = 100; // calls item.setSubtotal(100) em.persist(item); int id = item.@id; // calls item.getId()
We chose the .@ operator rather than the simple dot in JS/VB so that there is no confusion with the field access item.id.
Alexandre worked out the pesky details with visibility, read-only properties, BeanInfo, inheritance, and so on.
But there is still work to be done.
private int @id; private Order @order;That's just a token, which doesn't break backwards compatibility because you couldn't have an annotation at that spot. Too subtle, or just right?
I really want native properties to happen in Dolphin. I am sick of the boilerplate. Two years ago, I thought it would be too late, but I have learned from EJB3 that Java can do the right thing...after we've tried everything else.