Reputation: 8563
I want to write an aspect that will generate getters/setters for the fields of a class where it is being used.
I am a beginner to AspectJ, can someone point me in the right direction? A sample would be nice.
Upvotes: 4
Views: 1806
Reputation: 49085
Check out Spring Roo which generates getters and setters by generating AspectJ ITDs.
Not the most elegant thing but it gets the job done with out the runtime cost of other things like lambok.
Upvotes: 5
Reputation: 340723
What you are looking for is Project Lombok. It generates getters/setters and various other handy methods. It integrates with Eclipse so technically non-existing accessors are visible.
Upvotes: 1
Reputation: 13841
(not fully sure but...) I'm affraid that aspect programming can add behaviour to classes, not interface. If you could generate getters/setters in runtime... anyway you coudn't call them in your code because they wouldn't exist yet. You'd have a compile-time error.
Maybe you could use some IDE source generator. As in Eclipse: Source menu -> generate getters/setters.
Upvotes: 0