Top Banner
@walkmod #walkmodevoxx walkmod an open source tool to apply coding conventions Raquel Pau @raquelpau www.walkmod.com
15

Devoxx UK quickie talk about walkmod

May 27, 2015

Download

Software

walkmod

Devoxx UK quickie talk about walkmod, an open source tool to apply and share coding conventions
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Devoxx UK quickie talk about walkmod

@walkmod#walkmodevoxx

walkmod an open source tool to apply coding conventions

Raquel Pau@raquelpau

www.walkmod.com

Page 2: Devoxx UK quickie talk about walkmod

@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)

Page 3: Devoxx UK quickie talk about walkmod

@walkmod#walkmodevoxx

Developers principle

DRYdon’t repeat yourself

Page 4: Devoxx UK quickie talk about walkmod

@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

Page 5: Devoxx UK quickie talk about walkmod
Page 6: Devoxx UK quickie talk about walkmod

@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

Page 7: Devoxx UK quickie talk about walkmod

@YourTwitterHandle@walkmod#walkmodevoxx

Demo

Page 8: Devoxx UK quickie talk about walkmod

@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

Page 9: Devoxx UK quickie talk about walkmod

@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

Page 10: Devoxx UK quickie talk about walkmod

@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)

Page 11: Devoxx UK quickie talk about walkmod

@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)

Page 12: Devoxx UK quickie talk about walkmod

@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.

Page 13: Devoxx UK quickie talk about walkmod

@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.

Page 14: Devoxx UK quickie talk about walkmod

@YourTwitterHandle#DVXFR14{session hashtag} @walkmod#walkmodevoxx

Follow your dreams!

Page 15: Devoxx UK quickie talk about walkmod

@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