Created
September 19, 2013 06:11
-
-
Save hrj/6619630 to your computer and use it in GitHub Desktop.
@properties annotation for Xtend
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package properties | |
import org.eclipse.xtend.lib.macro.AbstractClassProcessor | |
import org.eclipse.xtend.lib.macro.Active | |
import org.eclipse.xtend.lib.macro.TransformationContext | |
import org.eclipse.xtend.lib.macro.declaration.MutableClassDeclaration | |
import static extension properties.ASTExtensions.* | |
/** | |
* Adds getters and setters for all fields | |
* and default equals, hashcode and toString methods. | |
*/ | |
@Active(PropertiesProcessor) | |
public annotation Properties { | |
} | |
class PropertiesProcessor extends AbstractClassProcessor { | |
override doTransform(MutableClassDeclaration cls, extension TransformationContext context) { | |
val extension transformations = new CommonTransformations(context) | |
cls.final = true | |
cls.persistentState.forEach [ field | | |
field.addGetter | |
field.addSetter | |
] | |
if(!cls.hasDataConstructor) cls.addDataConstructor | |
if(!cls.hasEquals) cls.addDataEquals | |
if(!cls.hasHashCode) cls.addDataHashCode | |
if(!cls.hasToString) cls.addDataToString | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment