SlideShare a Scribd company logo
1 of 57
Download to read offline
Platinum Sponsor
OPEN AND AUTOMATIC CODING
CONVENTIONS WITH WALKMOD
Raquel Pau
Sponsored talk by:
hello!
@raquelpau @acoroleu
which is our motivation?
DRYDon’t repeat yourself.
What are coding conventions?
“coding conventions are a 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
convention types
• Formatting rules: headers, indentation, documentation, code style..
• Naming rules: labeling rules for methods, classes..
• Best practices: software patterns, common bugs resolution..
google use conventions!
everybody follow conventions
http://sideeffect.kr/popularconvention
“it takes a while to create nothing”
Ron Jeffries
our goals
• automatizing the resolution of problems detected by code quality tools
(i.e PMD, , sonar, findbugs).
• automatizing the development and repetitive tasks i.e: creating basic
CRUD services for the entire model.
walkmod is open!
• open source: feel free to suggest changes!
• free for everybody: tell it to your boss!
• extensible by plugins do it yourself and share them! DIY+S
Introduction
walkmod is ready for Java 8
but also could by polyglot!
how it works
making awesome things happen!
>_ man walkmod
• >_ walkmod apply modifies the source code according a set of coding
conventions
• >_ walkmod check specifies which source files do not follow a set of
coding conventions
how it works
conventions driven by transformations
how it works
• Coding conventions are applied with blocks of transformations for each
source file.
•Transformations may update the same sources or creating/updating
another ones.
overview
• reader: reads the sources. i.e retrieves all files from a directory
recursively.
• walker: executes a chain of transformations for each source.
• writer: writes the sources. i.e using the eclipse formatter.
how it works
how it works
reader
• Reads the sources. By default, reads the folder src/main/java.
• Works with multiple include/exclude rules.
• Creates a resource object, whose content is iterated from the walker.
how it works
walker
• Executes a chain of transformations for each object allocated in a
resource. i.e all java source files of an specific folder.
• merges the output produced by transformations with existent
resources.
• analyzes and reports which changes have been produced by the chain
of transformations in each object.
• invokes the writer with the final (and merged) output if there is any
change.
how it works
writer
• writes each object allocated in a resource. i.e all java source files of a
specific folder.
• Has include/exclude rules.
• There are useful writer implementations, such as the storage of the
contents of a toString() object method or the eclipse formatter.
how it works
transformations
Code conventions are a reality by means of code transformations
modify or generate code without
changing walkmod
transformations
visitors
transformations
public class HelloVisitor extends VoidVisitor<VisitorContext>{
...
@Overwrite
public void visit(MethodDeclaration md, VisitorContext ctx){
//TODO
}
@Overwrite
public void visit(FieldDeclaration fd, VisitorContext ctx){
//TODO
}
...
}
transformations
why visitors?
• Visitor design pattern is a way of separating an algorithm from an
object structure on which it operates.
• Straight-forward way to design code transformations in java.
• Visitors can just be shared by means of walkmod plugins.
transformations
scripts
transformations
transformations
scripts
• Scripts allow the design of inline transformations.
• Scripts should be used to apply simple modifications in source files.
• Support for multiple languages.Those which implement the standard
Java scripting interface. i.e. groovy, javascript, python..
transformations
templates
transformations
transformations
templates
transformations
• What You See Is What You Get (WYSIWYG): Simplest way to dynamic
content to follow a given convention.
• groovy is the default template engine, but can be customized.
remember
transformations
• Visitors: a straight-forward way to design code transformations in java.
• scripts: to design inline transformations without creating a java library.
• templates: WYSIWYG transformations.
query engine
Write less to do the same!
query engine
MethodDeclaration method = null;
Collection members = type.getMembers();
Iterator it = members.iterator();
while (it.hasNext()){
BodyDeclaration member = (BodyDeclaration)it.next();
if (member instance of MethodDeclararion){
MethodDeclarion aux = (MethodDeclaration) member;
if(“execute”.equals(aux.getName()){
method = aux;
break;
}
}
}
type.methods.find({it.name.equals(“execute”)})
{ context } + query expression
query engine
query language
• The default query language is gPath (groovy), but you can change it for
your favorite language.
• Common used large query expressions can be referenced from Alias.
“TypeDeclaration.metaClass.getMethods = { -> delegate.members.findAll({it instanceof MethodDeclaration}); }”
query engine
queries from templates
Using the query object: ${query.resolve(“expr”)}.
query engine
import org.apache.log4j.Logger;
public class ${query.resolve("type.name")}{
public static Logger log = Logger.getLogger(${query.resolve("type.name")}.class);
}
template to add Loggers
queries from scripts
accessing through a binding called query
query engine
..
for( type in node.types) {
def result = query.resolve(type, “methods”);
...
}
...
groovy script querying the type methods
queries from visitors
Implementing QueryEngineAware or extendingVisitorSupport.
query engine
public class MyVisitor extends VisitorSupport{
@Overwrite
public void visit(TypeDeclaration td, VisitorContext ctx){
Object result = query(
td, //context
“methods.find({it.name.equals(“foo”)})” //expr
);
}
}
visitor code with a gpath query
merge engine
Don’t loose your changes
why a merge engine?
• Developer changes are respected (e.g. adding a new method).
• Simplify transformations. Otherwise, transformations would check
many conditions to avoid repeating code or overwriting it.
merge engine
merge engine
merge engine
merge engine
merge engine
merge engine
semantic merge
• Code is merged according to the meaning of its elements instead of
simply merging text.
• Each node type has an specific merge policy.
merge engine
named nodes | anonymous nodes
• named nodes: those nodes identifiable inside an AST.
e.g. methods or fields of a given type
• anonymous nodes: those non-identifiable.
e.g. statements of a method
merge engine
merging named nodes
• append policy: only adds non existing nodes generated by a
transformation.
• overwrite policy: always replaces existing nodes by the generated
ones.
merge engine
merging anonymous nodes
• assign policy replaces the whole original list of nodes by generated
nodes.
• unmodify policy maintains the original list of nodes.
• addall policy appends the whole list of generated nodes into the
original list.
merge engine
plugins
Let’s grow up!
walkmod is growing up
plugins
where can I find them?
plugins
how to extend walkmod?
• Creating new java libraries and deploying them into a maven
repository (public or private) with the name walkmod-xxx-plugin.
• All walkmod extensions need a plugin descriptor of their components
in the META-INF/walkmod directory inside the jar library.
plugins
plugins backend
• Walkmod embeds apache ivy to download plugins from maven
repositories in runtime.
• Custom repositories are in ${walkmod-home}/conf/ivysettings.xml
• All plugin jars and their dependencies are files loaded dynamically into
a new classloader.
plugins
roadmap
next steps
• + plugins: Create and publish new plugins (e.g. naming rules or
support for other programming languages).
• - less configuration: reutilization by inheritance / include rules of the
XML elements.
• saas: publish online services for running walkmod and all its plugins
(also private).
roadmap
thanks for your
time!
and.. do cool things that matter ;)
@walkmod

More Related Content

What's hot

What's hot (20)

TypeScript
TypeScriptTypeScript
TypeScript
 
Getting started with typescript
Getting started with typescriptGetting started with typescript
Getting started with typescript
 
TypeScript
TypeScriptTypeScript
TypeScript
 
TypeScript Best Practices
TypeScript Best PracticesTypeScript Best Practices
TypeScript Best Practices
 
PHP Basics
PHP BasicsPHP Basics
PHP Basics
 
TypeScript 101
TypeScript 101TypeScript 101
TypeScript 101
 
Learning typescript
Learning typescriptLearning typescript
Learning typescript
 
Getting started with typescript and angular 2
Getting started with typescript  and angular 2Getting started with typescript  and angular 2
Getting started with typescript and angular 2
 
Typescript for the programmers who like javascript
Typescript for the programmers who like javascriptTypescript for the programmers who like javascript
Typescript for the programmers who like javascript
 
002. Introducere in type script
002. Introducere in type script002. Introducere in type script
002. Introducere in type script
 
TypeScript: coding JavaScript without the pain
TypeScript: coding JavaScript without the painTypeScript: coding JavaScript without the pain
TypeScript: coding JavaScript without the pain
 
Web development basics (Part-4)
Web development basics (Part-4)Web development basics (Part-4)
Web development basics (Part-4)
 
Dart Workshop
Dart WorkshopDart Workshop
Dart Workshop
 
TypeScript intro
TypeScript introTypeScript intro
TypeScript intro
 
JavaScript Basics
JavaScript BasicsJavaScript Basics
JavaScript Basics
 
Lecture 5 javascript
Lecture 5 javascriptLecture 5 javascript
Lecture 5 javascript
 
TypeScript - An Introduction
TypeScript - An IntroductionTypeScript - An Introduction
TypeScript - An Introduction
 
TypeScript Overview
TypeScript OverviewTypeScript Overview
TypeScript Overview
 
Functions in javascript
Functions in javascriptFunctions in javascript
Functions in javascript
 
TypeScript: Basic Features and Compilation Guide
TypeScript: Basic Features and Compilation GuideTypeScript: Basic Features and Compilation Guide
TypeScript: Basic Features and Compilation Guide
 

Viewers also liked

Viewers also liked (17)

Challenges and best practices of database continuous delivery
Challenges and best practices of database continuous deliveryChallenges and best practices of database continuous delivery
Challenges and best practices of database continuous delivery
 
The Challenges & Pitfalls of Database Continuous Delivery
The Challenges & Pitfalls of Database Continuous DeliveryThe Challenges & Pitfalls of Database Continuous Delivery
The Challenges & Pitfalls of Database Continuous Delivery
 
Patterns and Tools for Database Versioning, Migration, Data Loading and Test ...
Patterns and Tools for Database Versioning, Migration, Data Loading and Test ...Patterns and Tools for Database Versioning, Migration, Data Loading and Test ...
Patterns and Tools for Database Versioning, Migration, Data Loading and Test ...
 
Continuous Delivery and Zero Downtime: What your architecture needs to succeed
Continuous Delivery and Zero Downtime: What your architecture needs to succeedContinuous Delivery and Zero Downtime: What your architecture needs to succeed
Continuous Delivery and Zero Downtime: What your architecture needs to succeed
 
Road to database automation: database source control
Road to database automation: database source controlRoad to database automation: database source control
Road to database automation: database source control
 
Database version control without pain - the PHPNW10 version
Database version control without pain - the PHPNW10 versionDatabase version control without pain - the PHPNW10 version
Database version control without pain - the PHPNW10 version
 
Database Source Control: Migrations vs State
Database Source Control: Migrations vs StateDatabase Source Control: Migrations vs State
Database Source Control: Migrations vs State
 
Flyway (33rd Degree)
Flyway (33rd Degree)Flyway (33rd Degree)
Flyway (33rd Degree)
 
KYSUC - Keep Your Schema Under Control
KYSUC - Keep Your Schema Under ControlKYSUC - Keep Your Schema Under Control
KYSUC - Keep Your Schema Under Control
 
Flyway
FlywayFlyway
Flyway
 
Database migration with flyway
Database migration  with flywayDatabase migration  with flyway
Database migration with flyway
 
Javaland 2016 - Flyway vs. LiquiBase - Battle der Datenbankmigrationstools
Javaland 2016 - Flyway vs. LiquiBase - Battle der DatenbankmigrationstoolsJavaland 2016 - Flyway vs. LiquiBase - Battle der Datenbankmigrationstools
Javaland 2016 - Flyway vs. LiquiBase - Battle der Datenbankmigrationstools
 
Liquibase & Flyway @ Baltic DevOps
Liquibase & Flyway @ Baltic DevOpsLiquibase & Flyway @ Baltic DevOps
Liquibase & Flyway @ Baltic DevOps
 
Database Schema Evolution
Database Schema EvolutionDatabase Schema Evolution
Database Schema Evolution
 
Database security issues
Database security issuesDatabase security issues
Database security issues
 
Database migrations with Flyway and Liquibase
Database migrations with Flyway and LiquibaseDatabase migrations with Flyway and Liquibase
Database migrations with Flyway and Liquibase
 
Data quality and data profiling
Data quality and data profilingData quality and data profiling
Data quality and data profiling
 

Similar to 33rd degree talk: open and automatic coding conventions with walkmod

Similar to 33rd degree talk: open and automatic coding conventions with walkmod (20)

Few minutes To better Code - Refactoring
Few minutes To better Code - RefactoringFew minutes To better Code - Refactoring
Few minutes To better Code - Refactoring
 
Write code that writes code! A beginner's guide to Annotation Processing - Ja...
Write code that writes code! A beginner's guide to Annotation Processing - Ja...Write code that writes code! A beginner's guide to Annotation Processing - Ja...
Write code that writes code! A beginner's guide to Annotation Processing - Ja...
 
Write code that writes code!
Write code that writes code!Write code that writes code!
Write code that writes code!
 
Java
JavaJava
Java
 
Javascript classes and scoping
Javascript classes and scopingJavascript classes and scoping
Javascript classes and scoping
 
Handlebars and Require.js
Handlebars and Require.jsHandlebars and Require.js
Handlebars and Require.js
 
Handlebars & Require JS
Handlebars  & Require JSHandlebars  & Require JS
Handlebars & Require JS
 
DSL's with Groovy
DSL's with GroovyDSL's with Groovy
DSL's with Groovy
 
How to R.E.A.D: Steps for how to select the correct module @NEWDCamp 2014
How to R.E.A.D: Steps for how to select the correct module @NEWDCamp 2014How to R.E.A.D: Steps for how to select the correct module @NEWDCamp 2014
How to R.E.A.D: Steps for how to select the correct module @NEWDCamp 2014
 
Comp102 lec 3
Comp102   lec 3Comp102   lec 3
Comp102 lec 3
 
Viva file
Viva fileViva file
Viva file
 
TypeScript . the JavaScript developer best friend!
TypeScript . the JavaScript developer best friend!TypeScript . the JavaScript developer best friend!
TypeScript . the JavaScript developer best friend!
 
How to crack java script certification
How to crack java script certificationHow to crack java script certification
How to crack java script certification
 
OCP Java (OCPJP) 8 Exam Quick Reference Card
OCP Java (OCPJP) 8 Exam Quick Reference CardOCP Java (OCPJP) 8 Exam Quick Reference Card
OCP Java (OCPJP) 8 Exam Quick Reference Card
 
Complete PPT about the Java lokesh kept it
Complete PPT about the Java lokesh kept itComplete PPT about the Java lokesh kept it
Complete PPT about the Java lokesh kept it
 
Design p atterns
Design p atternsDesign p atterns
Design p atterns
 
Welcome to React.pptx
Welcome to React.pptxWelcome to React.pptx
Welcome to React.pptx
 
The Why and What of Pattern Lab
The Why and What of Pattern LabThe Why and What of Pattern Lab
The Why and What of Pattern Lab
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
If you want to automate, you learn to code
If you want to automate, you learn to codeIf you want to automate, you learn to code
If you want to automate, you learn to code
 

Recently uploaded

Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
VictoriaMetrics
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
masabamasaba
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
masabamasaba
 

Recently uploaded (20)

WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 

33rd degree talk: open and automatic coding conventions with walkmod

  • 1. Platinum Sponsor OPEN AND AUTOMATIC CODING CONVENTIONS WITH WALKMOD Raquel Pau Sponsored talk by:
  • 3. which is our motivation? DRYDon’t repeat yourself.
  • 4. What are coding conventions? “coding conventions are a 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
  • 5. convention types • Formatting rules: headers, indentation, documentation, code style.. • Naming rules: labeling rules for methods, classes.. • Best practices: software patterns, common bugs resolution..
  • 8. “it takes a while to create nothing” Ron Jeffries
  • 9. our goals • automatizing the resolution of problems detected by code quality tools (i.e PMD, , sonar, findbugs). • automatizing the development and repetitive tasks i.e: creating basic CRUD services for the entire model.
  • 10. walkmod is open! • open source: feel free to suggest changes! • free for everybody: tell it to your boss! • extensible by plugins do it yourself and share them! DIY+S Introduction
  • 11. walkmod is ready for Java 8 but also could by polyglot!
  • 12. how it works making awesome things happen!
  • 13. >_ man walkmod • >_ walkmod apply modifies the source code according a set of coding conventions • >_ walkmod check specifies which source files do not follow a set of coding conventions how it works
  • 14. conventions driven by transformations how it works • Coding conventions are applied with blocks of transformations for each source file. •Transformations may update the same sources or creating/updating another ones.
  • 15. overview • reader: reads the sources. i.e retrieves all files from a directory recursively. • walker: executes a chain of transformations for each source. • writer: writes the sources. i.e using the eclipse formatter. how it works
  • 17. reader • Reads the sources. By default, reads the folder src/main/java. • Works with multiple include/exclude rules. • Creates a resource object, whose content is iterated from the walker. how it works
  • 18. walker • Executes a chain of transformations for each object allocated in a resource. i.e all java source files of an specific folder. • merges the output produced by transformations with existent resources. • analyzes and reports which changes have been produced by the chain of transformations in each object. • invokes the writer with the final (and merged) output if there is any change. how it works
  • 19. writer • writes each object allocated in a resource. i.e all java source files of a specific folder. • Has include/exclude rules. • There are useful writer implementations, such as the storage of the contents of a toString() object method or the eclipse formatter. how it works
  • 20. transformations Code conventions are a reality by means of code transformations
  • 21. modify or generate code without changing walkmod transformations
  • 23. public class HelloVisitor extends VoidVisitor<VisitorContext>{ ... @Overwrite public void visit(MethodDeclaration md, VisitorContext ctx){ //TODO } @Overwrite public void visit(FieldDeclaration fd, VisitorContext ctx){ //TODO } ... } transformations
  • 24. why visitors? • Visitor design pattern is a way of separating an algorithm from an object structure on which it operates. • Straight-forward way to design code transformations in java. • Visitors can just be shared by means of walkmod plugins. transformations
  • 27. scripts • Scripts allow the design of inline transformations. • Scripts should be used to apply simple modifications in source files. • Support for multiple languages.Those which implement the standard Java scripting interface. i.e. groovy, javascript, python.. transformations
  • 30. templates transformations • What You See Is What You Get (WYSIWYG): Simplest way to dynamic content to follow a given convention. • groovy is the default template engine, but can be customized.
  • 31. remember transformations • Visitors: a straight-forward way to design code transformations in java. • scripts: to design inline transformations without creating a java library. • templates: WYSIWYG transformations.
  • 32. query engine Write less to do the same!
  • 33. query engine MethodDeclaration method = null; Collection members = type.getMembers(); Iterator it = members.iterator(); while (it.hasNext()){ BodyDeclaration member = (BodyDeclaration)it.next(); if (member instance of MethodDeclararion){ MethodDeclarion aux = (MethodDeclaration) member; if(“execute”.equals(aux.getName()){ method = aux; break; } } } type.methods.find({it.name.equals(“execute”)})
  • 34. { context } + query expression query engine
  • 35. query language • The default query language is gPath (groovy), but you can change it for your favorite language. • Common used large query expressions can be referenced from Alias. “TypeDeclaration.metaClass.getMethods = { -> delegate.members.findAll({it instanceof MethodDeclaration}); }” query engine
  • 36. queries from templates Using the query object: ${query.resolve(“expr”)}. query engine import org.apache.log4j.Logger; public class ${query.resolve("type.name")}{ public static Logger log = Logger.getLogger(${query.resolve("type.name")}.class); } template to add Loggers
  • 37. queries from scripts accessing through a binding called query query engine .. for( type in node.types) { def result = query.resolve(type, “methods”); ... } ... groovy script querying the type methods
  • 38. queries from visitors Implementing QueryEngineAware or extendingVisitorSupport. query engine public class MyVisitor extends VisitorSupport{ @Overwrite public void visit(TypeDeclaration td, VisitorContext ctx){ Object result = query( td, //context “methods.find({it.name.equals(“foo”)})” //expr ); } } visitor code with a gpath query
  • 40. why a merge engine? • Developer changes are respected (e.g. adding a new method). • Simplify transformations. Otherwise, transformations would check many conditions to avoid repeating code or overwriting it. merge engine
  • 46. semantic merge • Code is merged according to the meaning of its elements instead of simply merging text. • Each node type has an specific merge policy. merge engine
  • 47. named nodes | anonymous nodes • named nodes: those nodes identifiable inside an AST. e.g. methods or fields of a given type • anonymous nodes: those non-identifiable. e.g. statements of a method merge engine
  • 48. merging named nodes • append policy: only adds non existing nodes generated by a transformation. • overwrite policy: always replaces existing nodes by the generated ones. merge engine
  • 49. merging anonymous nodes • assign policy replaces the whole original list of nodes by generated nodes. • unmodify policy maintains the original list of nodes. • addall policy appends the whole list of generated nodes into the original list. merge engine
  • 51. walkmod is growing up plugins
  • 52. where can I find them? plugins
  • 53. how to extend walkmod? • Creating new java libraries and deploying them into a maven repository (public or private) with the name walkmod-xxx-plugin. • All walkmod extensions need a plugin descriptor of their components in the META-INF/walkmod directory inside the jar library. plugins
  • 54. plugins backend • Walkmod embeds apache ivy to download plugins from maven repositories in runtime. • Custom repositories are in ${walkmod-home}/conf/ivysettings.xml • All plugin jars and their dependencies are files loaded dynamically into a new classloader. plugins
  • 56. next steps • + plugins: Create and publish new plugins (e.g. naming rules or support for other programming languages). • - less configuration: reutilization by inheritance / include rules of the XML elements. • saas: publish online services for running walkmod and all its plugins (also private). roadmap
  • 57. thanks for your time! and.. do cool things that matter ;) @walkmod