Upload
walkmod
View
617
Download
3
Tags:
Embed Size (px)
DESCRIPTION
Devoxx UK quickie talk about walkmod, an open source tool to apply and share coding conventions
Citation preview
@walkmod#walkmodevoxx
walkmod an open source tool to apply coding conventions
Raquel Pau@raquelpau
www.walkmod.com
@walkmod#walkmodevoxx
A bit of me
• 7 years working with Java
• Team leader in the research group DAMA-UPC
• Experience in Social Network Analysis, Deduplication algorithms &
recommendation engines
• Research publications about software engineering
• Currently involved in CoherentPaaS (EU project)
@walkmod#walkmodevoxx
Developers principle
DRYdon’t repeat yourself
@walkmod#walkmodevoxx
Coding conventions
“Set of guidelines for a specific programming language that recommend programming style, practices and methods for each aspect of a piece program written in this language” - wikipedia
• Define rules to accomplish DRY and make code readable
• Are partially supported by IDEs & Text editors
@walkmod#walkmodevoxx
... shall we dream again? yes!
walkmod• Tool to apply coding conventions
• Extensible tool by plugins (DIY)
• Respects your code changes
• Works with Java 8 code
• Open source + free
@YourTwitterHandle@walkmod#walkmodevoxx
Demo
@walkmod#walkmodevoxx
How walkmod works?
•Most code conventions can be automatically assured using code transformations. Types:
•Visitors (Visitor pattern): an straight-way java transformation
•Scripts: Polyglot inline transformations
•Template: DYSWYG transformations
@walkmod#walkmodevoxx
public class HelloVisitor extends VoidVisitor<VisitorContext>{...@Overwritepublic void visit(MethodDeclaration md, VisitorContext ctx){//TODO
}
@Overwritepublic void visit(FieldDeclaration fd, VisitorContext ctx){//TODO
}...
}
Visitor Example
@walkmod#walkmodevoxx
import org.walkmod.javalang.ast.body.ModifierSet;import java.lang.reflect.Modifier;import org.walkmod.javalang.ast.body.FieldDeclaration;
for(type in node.types){! def fields = type.members.findAll({it instanceof FieldDeclaration}); for (field in fields){ int modifiers = ModifierSet.addModifier(field.modifiers, Modifier.PRIVATE); modifiers = ModifierSet.removeModifier(modifiers, Modifier.PROTECTED); modifiers = ModifierSet.removeModifier(modifiers, Modifier.PUBLIC); field.setModifiers(modifiers); }}
Script Example (Groovy)
@walkmod#walkmodevoxx
package ${query.resolve("root.package.name")};
import javax.persistence.Id;import javax.persistence.GeneratedValue;import javax.persistence.GenerationType;
public class ${query.resolve("type.name")} {
! @Id! @GeneratedValue(strategy = GenerationType.SEQUENCE)! Integer id;
! @Override! public boolean equals(Object o) {! ! if (o instanceof ${query.resolve("type.name")}) {! ! ! return id.equals(((${query.resolve("type.name")}) o).id);! ! }! ! return false;! }
}
Template Example (Groovy)
@walkmod#walkmodevoxx
How does walkmod respect your changes?
• Applies a semantic merge after each transformation.
• Each source code element (e.g. methods, fields, statements...) has an specific merge policy.
• Liberates code transformations from change-management responsibility.
@walkmod#walkmodevoxx
Can walkmod grow up?
• Creating new plugins and deploying them into maven
• The whole architecture is extensible and configurable.
• Plugins are loaded in runtime before applying transformations.
@YourTwitterHandle#DVXFR14{session hashtag} @walkmod#walkmodevoxx
Follow your dreams!
@walkmod#walkmodevoxx
Thanks / Creative Commons
•Presentation Template — Guillaume LaForge
•The Queen — A prestigious heritage with some inspiration from The Sex Pistols and funny Devoxxians
•Girl with a Balloon & Follow your dreams — Banksy
•Tube — Michael Keen