SlideShare a Scribd company logo
1 of 48
Download to read offline
walkmod
a tool to apply coding conventions

@walkmod

http://walkmod.com
hello!

@raquelpau
raquelpau@gmail.com

@acoroleu
acoroleu@gmail.com
introduction
how it works
transformations
query engine
merge engine
plugins
roadmap
Introduction

motivation
ā€¢

Donā€™t repeat yourself (DRY) principle. Multiple layer architectures
contains lots of wrappers, which might be generated. E.g. Tests, DAOs,
Facades..

ā€¢

The application domain relevance. The business rules / domain logic
canā€™t be generated (really?). We need to focus on this!

ā€¢

Code review of ALL contributors. Who ļ¬xes the code?
Introduction
Introduction

What are coding conventions?
ā€œcoding conventions are a set of guidelines for a speciļ¬c programming
language that recommend programming style, practices and methods for
each aspect of a piece program written in this language.ā€ wikipedia
Introduction

examples
ā€¢
ā€¢
ā€¢
ā€¢

Naming conventions
Code formatting
Code licenses
Code documentation

ā€¢
ā€¢
ā€¢
ā€¢

Code refactoring
Apply programming practices
Architectural best practices
More..
Introduction

examples
Introduction

walkmod

ā€¢

automatizes the practice of code conventions in development teams
(i.e license usage).

ā€¢

automatizes the resolution of problems detected by code quality tools
(i.e PMD, , sonar, findbugs).

ā€¢

automatizes the development and repetitive tasks i.e: creating basic
CRUD services for the entire model.

ā€¢

automatizes global code changes: i.e refactorings.
Introduction

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
editor/IDE independent
community support
introduction
how it works
transformations
query engine
merge engine
plugins
roadmap
how it works

ā€¢ All conventions are applied
with blocks of
transformations for each
source ļ¬le.

ā€¢ Transformations may

update the same sources or
creating/updating another
ones.

workflow
how it works

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.

transformation: updates or creates sources for the following
transformation. Transformations are connected like a pipe through a
shared context.
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.
Works for sources of any programming language. The resource object
could be a source folder, a parsed json ļ¬le, etc..
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.

ā€¢
ā€¢

invokes the writer with the ļ¬nal (and merged) output.
analyzes and reports which changes have been produced by the chain
of transformations in each object.
how it works

transformations
ā€¢
ā€¢

modifies or creates objects that will be written.
There are three ways to design a transformation. Using:
templates,
scripts,
or visitors.
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

remember
introduction
how it works
transformations
query engine
merge engine
plugins
roadmap
transformations

why templates?
ā€¢
ā€¢
ā€¢
ā€¢

Templates are used to avoid manipulating the AST directly.
Generates dynamic content querying the AST.
DRY compliance.
groovy is the default template engine, but can be customized.
transformations

template configuration
<!DOCTYPE walkmod PUBLIC "-//WALKMOD//DTD" "http://www.walkmod.com/dtd/walkmod-1.0.dtd">
<walkmod>
...
<transformation type="walkmod:commons:template" >
<param name="templates">
["src/main/walkmod/templates/jpa-entities.groovy"]
</param>
</transformation>
...
</walkmod>
transformations

why scripts?
ā€¢
ā€¢
ā€¢

Scripts allow the design of inline transformations.
Scripts should be used to apply simple modifications in source ļ¬les.
Support for multiple languages. Those which implement the standard
Java scripting interface. i.e. groovy, javascript, python..
transformations

script configuration
...
<transformation type="walkmod:commons:scripting" >
<param name="language">
groovy
</param>
<param name="location">
src/main/walkmod/scripts/fields.groovy
</param>
</transformation>
...
transformations

why visitors?
ā€¢
ā€¢

Visitors are developed and compiled in java.

ā€¢

Visitors should be used to apply complex modifications in source ļ¬les.

To include transformations as plugins to be shared inside the
community.
transformations

visitor 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

visitor configuration
<!DOCTYPE walkmod PUBLIC "-//WALKMOD//DTD" "http://www.walkmod.com/dtd/walkmod-1.0.dtd">
<walkmod>
<plugins>
	 	 <plugin groupId="mygroupId" artifactId="myartifactId" version="versionNumber">
	
</plugin>
	 </plugins>
...
<transformation type="mygroupId:myartifactId:my-visitor" >
<param name="param1">
value1
</param>
<param name="paramN">
valueN
</param>
</transformation>
...
</walkmod>
introduction
how it works
transformations
query engine
merge engine
plugins
roadmap
query engine

query engine
ā€¢
ā€¢

Write less to do the same!

ā€¢

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}); }ā€

All queries have an object context and a query expression. By default, the
context is the root element of a parsed source ļ¬le.
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ā€)})
query engine

queries from templates
Using the query object: ${query.resolve(ā€œexprā€)}.
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
query engine

queries from scripts
accessing through a binding called query
..
for( type in node.types) {
def result = query.resolve(type, ā€œmethodsā€);
...
}
...

groovy script querying the type methods
query engine

queries from visitors
Implementing QueryEngineAware or extending VisitorSupport.
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
introduction
how it works
transformations
query engine
merge engine
plugins
roadmap
merge engine

why a merge engine?
ā€¢

To avoid duplicate results by transformations (i.e duplicate a method)
in existing code.

ā€¢

Simplify transformations. Otherwise, transformations must check many
conditions to avoid repeating code or overwriting it.

ā€¢

Sometimes, developer changes (i.e. adding a new method) must be
respected by the engine.
walkmod merges outputs with existential sources
merge engine

semantic merge
ā€¢

Code is merged according to the meaning of its elements instead of
simply merging text.

ā€¢

Only elements with the same identifier are merged. Indentiļ¬able
element types must implement the interface mergeable.
merge engine

previous concepts
ā€¢
ā€¢

local object is the current version of an element.
remote object is the modiļ¬ed version of an element generated by a
single transformation. It may be a fragment to add in a local object.
merge engine

merge policies
Conļ¬gurable and extensible merge policies for each object type.
Object
merge
policy

Finds the equivalent local version of a remote (and thus,
generated) object and merge recursively their children.
These objects must be identifiable to be searched and found.
These policies should be applied for fields, , methods, , types ā€¦

Type select which merge action do for local and remote objects which are
merge not identiļ¬able, although being instances of the same class. i.e policies
policy for the statements of an existent method.
merge engine

object merge policies
ā€¢

append policy only writes new values for null ļ¬elds. Otherwise, these
are not modiļ¬ed.

ā€¢

overwrite policy modiļ¬es all ļ¬eld values of a local object for those
generated by a transformation.
merge engine

type merge policies
ā€¢

assign policy only writes the remote values. i.e replacing the list of
statements of a method for the generated list.

ā€¢

unmodify policy only writes the local values. i.e to respect the
developer changes in the statements of an old transformation.

ā€¢

addall policy that appends the remote values into the local values.
introduction
how it works
transformations
query engine
merge engine
plugins
roadmap
plugins

why and how to
extend walkmod?

ā€¢

You can extend walkmod with new components or override the
existing ones (visitors, readers, writers, walkers, merge policiesā€¦)

ā€¢

Creating new plugins (java libraries) and deploying them into a maven
repository (public or private). See repo.maven.apache.org

ā€¢

All walkmod extensions need a plugin descriptor of their components
in the META-INF/walkmod directory inside the jar library.
plugins

plugin descriptor

ā€¢

Plugin descriptor is a XML file with the name walkmod-xxx-plugin.xml
which follows the spring bean conļ¬guration.

ā€¢

New readers, writers, walkers or transformations must be speciļ¬ed
with a unique name ā€œgroupId:artifactId:nameā€ as a spring bean in the
plugin descriptor.
<beans>
...
	 <bean id="walkmod:commons:import-cleaner" class="org.walkmod.visitors.ImportOrganizer" />
	 ...
</beans>
plugins

plugin usage (I)
Plugins are declared into ${project}/walkmod.xml
<walkmod>
<plugins>
<plugins>
	 	 <plugin groupId="walkmod" artifactId="walkmod-commons-plugin" version="1.0">
	 	 </plugin>
	 </plugins>
<chain name="my-chain">
	 	 ...
	 </chain>
<walkmod>
plugins

plugin usage (II)
Beans declared in a plugin descriptor can be referenced from walkmod.xml
using the type attribute.
<walkmod>
<plugins>
	 	 <plugin groupId="walkmod" artifactId="walkmod-commons-plugin" version="1.0">
	 	 </plugin>
	 </plugins>
<chain name="my-chain">
...
<transformation type="walkmod:commons:imports-cleaner" />
...
</chain>
</walkmod>
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.

ā€¢

All beans used and declared in plugin descriptors are resolved by the
spring source engine using the new classloader.
introduction
how it works
transformations
query engine
merge engine
plugins
roadmap
roadmap

next steps

ā€¢

modularization: split the project in modules in GitHub and deploy them in a
Maven public repository.

ā€¢
ā€¢

Java 8 support (lambda expressions)

ā€¢

- less configuration: reutilization by inheritance / include rules of the XML
elements.

ā€¢

saas: publish online services for running walkmod and all its plugins (also
private).

+ plugins: Create and publish new plugins (e.g. refactoring or support for other
programming languages).

More Related Content

What's hot

An Introduction to JavaScript
An Introduction to JavaScriptAn Introduction to JavaScript
An Introduction to JavaScripttonyh1
Ā 
TypeScript - Silver Bullet for the Full-stack Developers
TypeScript - Silver Bullet for the Full-stack DevelopersTypeScript - Silver Bullet for the Full-stack Developers
TypeScript - Silver Bullet for the Full-stack DevelopersRutenis Turcinas
Ā 
Wt unit 5
Wt unit 5Wt unit 5
Wt unit 5team11vgnt
Ā 
Method Handles in Java
Method Handles in JavaMethod Handles in Java
Method Handles in Javahendersk
Ā 
002. Introducere in type script
002. Introducere in type script002. Introducere in type script
002. Introducere in type scriptDmitrii Stoian
Ā 
Code generating beans in Java
Code generating beans in JavaCode generating beans in Java
Code generating beans in JavaStephen Colebourne
Ā 
2. overview of c#
2. overview of c#2. overview of c#
2. overview of c#Rohit Rao
Ā 
Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to JavascriptAmit Tyagi
Ā 
Java script final presentation
Java script final presentationJava script final presentation
Java script final presentationAdhoura Academy
Ā 
Introduction to JavaScript Programming
Introduction to JavaScript ProgrammingIntroduction to JavaScript Programming
Introduction to JavaScript ProgrammingRaveendra R
Ā 
Developing Useful APIs
Developing Useful APIsDeveloping Useful APIs
Developing Useful APIsDmitry Buzdin
Ā 
Typescript tips & tricks
Typescript tips & tricksTypescript tips & tricks
Typescript tips & tricksOri Calvo
Ā 
8 introduction to_java_script
8 introduction to_java_script8 introduction to_java_script
8 introduction to_java_scriptVijay Kalyan
Ā 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScriptRangana Sampath
Ā 
TypeScript Best Practices
TypeScript Best PracticesTypeScript Best Practices
TypeScript Best Practicesfelixbillon
Ā 

What's hot (20)

An Introduction to JavaScript
An Introduction to JavaScriptAn Introduction to JavaScript
An Introduction to JavaScript
Ā 
TypeScript
TypeScriptTypeScript
TypeScript
Ā 
TypeScript - Silver Bullet for the Full-stack Developers
TypeScript - Silver Bullet for the Full-stack DevelopersTypeScript - Silver Bullet for the Full-stack Developers
TypeScript - Silver Bullet for the Full-stack Developers
Ā 
Typescript
TypescriptTypescript
Typescript
Ā 
Wt unit 5
Wt unit 5Wt unit 5
Wt unit 5
Ā 
Functions in javascript
Functions in javascriptFunctions in javascript
Functions in javascript
Ā 
Method Handles in Java
Method Handles in JavaMethod Handles in Java
Method Handles in Java
Ā 
002. Introducere in type script
002. Introducere in type script002. Introducere in type script
002. Introducere in type script
Ā 
JS - Basics
JS - BasicsJS - Basics
JS - Basics
Ā 
Code generating beans in Java
Code generating beans in JavaCode generating beans in Java
Code generating beans in Java
Ā 
2. overview of c#
2. overview of c#2. overview of c#
2. overview of c#
Ā 
Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to Javascript
Ā 
Java script final presentation
Java script final presentationJava script final presentation
Java script final presentation
Ā 
Introduction to JavaScript Programming
Introduction to JavaScript ProgrammingIntroduction to JavaScript Programming
Introduction to JavaScript Programming
Ā 
Introduction to JavaScript Programming
Introduction to JavaScript ProgrammingIntroduction to JavaScript Programming
Introduction to JavaScript Programming
Ā 
Developing Useful APIs
Developing Useful APIsDeveloping Useful APIs
Developing Useful APIs
Ā 
Typescript tips & tricks
Typescript tips & tricksTypescript tips & tricks
Typescript tips & tricks
Ā 
8 introduction to_java_script
8 introduction to_java_script8 introduction to_java_script
8 introduction to_java_script
Ā 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
Ā 
TypeScript Best Practices
TypeScript Best PracticesTypeScript Best Practices
TypeScript Best Practices
Ā 

Similar to Apply Coding Conventions with walkmod

GDG Addis - An Introduction to Django and App Engine
GDG Addis - An Introduction to Django and App EngineGDG Addis - An Introduction to Django and App Engine
GDG Addis - An Introduction to Django and App EngineYared Ayalew
Ā 
FFW Gabrovo PMG - JavaScript 1
FFW Gabrovo PMG - JavaScript 1FFW Gabrovo PMG - JavaScript 1
FFW Gabrovo PMG - JavaScript 1Toni Kolev
Ā 
Handlebars & Require JS
Handlebars  & Require JSHandlebars  & Require JS
Handlebars & Require JSIvano Malavolta
Ā 
Handlebars and Require.js
Handlebars and Require.jsHandlebars and Require.js
Handlebars and Require.jsIvano Malavolta
Ā 
Advanced guide to develop ajax applications using dojo
Advanced guide to develop ajax applications using dojoAdvanced guide to develop ajax applications using dojo
Advanced guide to develop ajax applications using dojoFu Cheng
Ā 
Few minutes To better Code - Refactoring
Few minutes To better Code - RefactoringFew minutes To better Code - Refactoring
Few minutes To better Code - RefactoringDiaa Al-Salehi
Ā 
Design Patterns
Design PatternsDesign Patterns
Design Patternsimedo.de
Ā 
Compiler Construction
Compiler ConstructionCompiler Construction
Compiler ConstructionAhmed Raza
Ā 
Hsc IT Chap 3. Advanced javascript-1.pdf
Hsc IT Chap 3. Advanced javascript-1.pdfHsc IT Chap 3. Advanced javascript-1.pdf
Hsc IT Chap 3. Advanced javascript-1.pdfAAFREEN SHAIKH
Ā 
Owner - Java properties reinvented.
Owner - Java properties reinvented.Owner - Java properties reinvented.
Owner - Java properties reinvented.Luigi Viggiano
Ā 
Pluggable patterns
Pluggable patternsPluggable patterns
Pluggable patternsCorey Oordt
Ā 
TypeScript . the JavaScript developer best friend!
TypeScript . the JavaScript developer best friend!TypeScript . the JavaScript developer best friend!
TypeScript . the JavaScript developer best friend!Alessandro Giorgetti
Ā 
Introduction to Software - Coder Forge - John Mulhall
Introduction to Software - Coder Forge - John MulhallIntroduction to Software - Coder Forge - John Mulhall
Introduction to Software - Coder Forge - John MulhallJohn Mulhall
Ā 
Ruby On Rails
Ruby On RailsRuby On Rails
Ruby On RailsBalint Erdi
Ā 
The Meteor Framework
The Meteor FrameworkThe Meteor Framework
The Meteor FrameworkDamien Magoni
Ā 
Unit 1 - TypeScript & Introduction to Angular CLI.pptx
Unit 1 - TypeScript & Introduction to Angular CLI.pptxUnit 1 - TypeScript & Introduction to Angular CLI.pptx
Unit 1 - TypeScript & Introduction to Angular CLI.pptxMalla Reddy University
Ā 
SFDC Deployments
SFDC DeploymentsSFDC Deployments
SFDC DeploymentsSujit Kumar
Ā 

Similar to Apply Coding Conventions with walkmod (20)

GDG Addis - An Introduction to Django and App Engine
GDG Addis - An Introduction to Django and App EngineGDG Addis - An Introduction to Django and App Engine
GDG Addis - An Introduction to Django and App Engine
Ā 
FFW Gabrovo PMG - JavaScript 1
FFW Gabrovo PMG - JavaScript 1FFW Gabrovo PMG - JavaScript 1
FFW Gabrovo PMG - JavaScript 1
Ā 
Web Technology Part 2
Web Technology Part 2Web Technology Part 2
Web Technology Part 2
Ā 
Handlebars & Require JS
Handlebars  & Require JSHandlebars  & Require JS
Handlebars & Require JS
Ā 
Handlebars and Require.js
Handlebars and Require.jsHandlebars and Require.js
Handlebars and Require.js
Ā 
Advanced guide to develop ajax applications using dojo
Advanced guide to develop ajax applications using dojoAdvanced guide to develop ajax applications using dojo
Advanced guide to develop ajax applications using dojo
Ā 
Few minutes To better Code - Refactoring
Few minutes To better Code - RefactoringFew minutes To better Code - Refactoring
Few minutes To better Code - Refactoring
Ā 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
Ā 
Compiler Construction
Compiler ConstructionCompiler Construction
Compiler Construction
Ā 
Welcome to React.pptx
Welcome to React.pptxWelcome to React.pptx
Welcome to React.pptx
Ā 
Hsc IT Chap 3. Advanced javascript-1.pdf
Hsc IT Chap 3. Advanced javascript-1.pdfHsc IT Chap 3. Advanced javascript-1.pdf
Hsc IT Chap 3. Advanced javascript-1.pdf
Ā 
Design p atterns
Design p atternsDesign p atterns
Design p atterns
Ā 
Owner - Java properties reinvented.
Owner - Java properties reinvented.Owner - Java properties reinvented.
Owner - Java properties reinvented.
Ā 
Pluggable patterns
Pluggable patternsPluggable patterns
Pluggable patterns
Ā 
TypeScript . the JavaScript developer best friend!
TypeScript . the JavaScript developer best friend!TypeScript . the JavaScript developer best friend!
TypeScript . the JavaScript developer best friend!
Ā 
Introduction to Software - Coder Forge - John Mulhall
Introduction to Software - Coder Forge - John MulhallIntroduction to Software - Coder Forge - John Mulhall
Introduction to Software - Coder Forge - John Mulhall
Ā 
Ruby On Rails
Ruby On RailsRuby On Rails
Ruby On Rails
Ā 
The Meteor Framework
The Meteor FrameworkThe Meteor Framework
The Meteor Framework
Ā 
Unit 1 - TypeScript & Introduction to Angular CLI.pptx
Unit 1 - TypeScript & Introduction to Angular CLI.pptxUnit 1 - TypeScript & Introduction to Angular CLI.pptx
Unit 1 - TypeScript & Introduction to Angular CLI.pptx
Ā 
SFDC Deployments
SFDC DeploymentsSFDC Deployments
SFDC Deployments
Ā 

Recently uploaded

Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
Ā 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
Ā 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
Ā 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
Ā 
SIEMENS: RAPUNZEL ā€“ A Tale About Knowledge Graph
SIEMENS: RAPUNZEL ā€“ A Tale About Knowledge GraphSIEMENS: RAPUNZEL ā€“ A Tale About Knowledge Graph
SIEMENS: RAPUNZEL ā€“ A Tale About Knowledge GraphNeo4j
Ā 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
Ā 
Integration and Automation in Practice: CI/CD in MuleĀ Integration and Automat...
Integration and Automation in Practice: CI/CD in MuleĀ Integration and Automat...Integration and Automation in Practice: CI/CD in MuleĀ Integration and Automat...
Integration and Automation in Practice: CI/CD in MuleĀ Integration and Automat...Patryk Bandurski
Ā 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
Ā 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsAndrey Dotsenko
Ā 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
Ā 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
Ā 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
Ā 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
Ā 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
Ā 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Neo4j
Ā 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
Ā 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
Ā 

Recently uploaded (20)

Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
Ā 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
Ā 
Hot Sexy call girls in Panjabi Bagh šŸ” 9953056974 šŸ” Delhi escort Service
Hot Sexy call girls in Panjabi Bagh šŸ” 9953056974 šŸ” Delhi escort ServiceHot Sexy call girls in Panjabi Bagh šŸ” 9953056974 šŸ” Delhi escort Service
Hot Sexy call girls in Panjabi Bagh šŸ” 9953056974 šŸ” Delhi escort Service
Ā 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
Ā 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
Ā 
SIEMENS: RAPUNZEL ā€“ A Tale About Knowledge Graph
SIEMENS: RAPUNZEL ā€“ A Tale About Knowledge GraphSIEMENS: RAPUNZEL ā€“ A Tale About Knowledge Graph
SIEMENS: RAPUNZEL ā€“ A Tale About Knowledge Graph
Ā 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
Ā 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
Ā 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
Ā 
Integration and Automation in Practice: CI/CD in MuleĀ Integration and Automat...
Integration and Automation in Practice: CI/CD in MuleĀ Integration and Automat...Integration and Automation in Practice: CI/CD in MuleĀ Integration and Automat...
Integration and Automation in Practice: CI/CD in MuleĀ Integration and Automat...
Ā 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
Ā 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Ā 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
Ā 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
Ā 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
Ā 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
Ā 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
Ā 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024
Ā 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
Ā 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Ā 

Apply Coding Conventions with walkmod

  • 1. walkmod a tool to apply coding conventions @walkmod http://walkmod.com
  • 3. introduction how it works transformations query engine merge engine plugins roadmap
  • 4. Introduction motivation ā€¢ Donā€™t repeat yourself (DRY) principle. Multiple layer architectures contains lots of wrappers, which might be generated. E.g. Tests, DAOs, Facades.. ā€¢ The application domain relevance. The business rules / domain logic canā€™t be generated (really?). We need to focus on this! ā€¢ Code review of ALL contributors. Who ļ¬xes the code?
  • 6. Introduction What are coding conventions? ā€œcoding conventions are a set of guidelines for a speciļ¬c programming language that recommend programming style, practices and methods for each aspect of a piece program written in this language.ā€ wikipedia
  • 7. Introduction examples ā€¢ ā€¢ ā€¢ ā€¢ Naming conventions Code formatting Code licenses Code documentation ā€¢ ā€¢ ā€¢ ā€¢ Code refactoring Apply programming practices Architectural best practices More..
  • 9. Introduction walkmod ā€¢ automatizes the practice of code conventions in development teams (i.e license usage). ā€¢ automatizes the resolution of problems detected by code quality tools (i.e PMD, , sonar, findbugs). ā€¢ automatizes the development and repetitive tasks i.e: creating basic CRUD services for the entire model. ā€¢ automatizes global code changes: i.e refactorings.
  • 10. Introduction 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 editor/IDE independent community support
  • 11. introduction how it works transformations query engine merge engine plugins roadmap
  • 12. how it works ā€¢ All conventions are applied with blocks of transformations for each source ļ¬le. ā€¢ Transformations may update the same sources or creating/updating another ones. workflow
  • 13. how it works 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. transformation: updates or creates sources for the following transformation. Transformations are connected like a pipe through a shared context.
  • 14. 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. Works for sources of any programming language. The resource object could be a source folder, a parsed json ļ¬le, etc..
  • 15. 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. ā€¢ ā€¢ invokes the writer with the ļ¬nal (and merged) output. analyzes and reports which changes have been produced by the chain of transformations in each object.
  • 16. how it works transformations ā€¢ ā€¢ modifies or creates objects that will be written. There are three ways to design a transformation. Using: templates, scripts, or visitors.
  • 17. 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.
  • 19. introduction how it works transformations query engine merge engine plugins roadmap
  • 20. transformations why templates? ā€¢ ā€¢ ā€¢ ā€¢ Templates are used to avoid manipulating the AST directly. Generates dynamic content querying the AST. DRY compliance. groovy is the default template engine, but can be customized.
  • 21. transformations template configuration <!DOCTYPE walkmod PUBLIC "-//WALKMOD//DTD" "http://www.walkmod.com/dtd/walkmod-1.0.dtd"> <walkmod> ... <transformation type="walkmod:commons:template" > <param name="templates"> ["src/main/walkmod/templates/jpa-entities.groovy"] </param> </transformation> ... </walkmod>
  • 22. transformations why scripts? ā€¢ ā€¢ ā€¢ Scripts allow the design of inline transformations. Scripts should be used to apply simple modifications in source ļ¬les. Support for multiple languages. Those which implement the standard Java scripting interface. i.e. groovy, javascript, python..
  • 23. transformations script configuration ... <transformation type="walkmod:commons:scripting" > <param name="language"> groovy </param> <param name="location"> src/main/walkmod/scripts/fields.groovy </param> </transformation> ...
  • 24. transformations why visitors? ā€¢ ā€¢ Visitors are developed and compiled in java. ā€¢ Visitors should be used to apply complex modifications in source ļ¬les. To include transformations as plugins to be shared inside the community.
  • 25. transformations visitor 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 } ... }
  • 26. transformations visitor configuration <!DOCTYPE walkmod PUBLIC "-//WALKMOD//DTD" "http://www.walkmod.com/dtd/walkmod-1.0.dtd"> <walkmod> <plugins> <plugin groupId="mygroupId" artifactId="myartifactId" version="versionNumber"> </plugin> </plugins> ... <transformation type="mygroupId:myartifactId:my-visitor" > <param name="param1"> value1 </param> <param name="paramN"> valueN </param> </transformation> ... </walkmod>
  • 27. introduction how it works transformations query engine merge engine plugins roadmap
  • 28. query engine query engine ā€¢ ā€¢ Write less to do the same! ā€¢ 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}); }ā€ All queries have an object context and a query expression. By default, the context is the root element of a parsed source ļ¬le.
  • 29. 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ā€)})
  • 30. query engine queries from templates Using the query object: ${query.resolve(ā€œexprā€)}. 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
  • 31. query engine queries from scripts accessing through a binding called query .. for( type in node.types) { def result = query.resolve(type, ā€œmethodsā€); ... } ... groovy script querying the type methods
  • 32. query engine queries from visitors Implementing QueryEngineAware or extending VisitorSupport. 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
  • 33. introduction how it works transformations query engine merge engine plugins roadmap
  • 34. merge engine why a merge engine? ā€¢ To avoid duplicate results by transformations (i.e duplicate a method) in existing code. ā€¢ Simplify transformations. Otherwise, transformations must check many conditions to avoid repeating code or overwriting it. ā€¢ Sometimes, developer changes (i.e. adding a new method) must be respected by the engine.
  • 35. walkmod merges outputs with existential sources
  • 36. merge engine semantic merge ā€¢ Code is merged according to the meaning of its elements instead of simply merging text. ā€¢ Only elements with the same identifier are merged. Indentiļ¬able element types must implement the interface mergeable.
  • 37. merge engine previous concepts ā€¢ ā€¢ local object is the current version of an element. remote object is the modiļ¬ed version of an element generated by a single transformation. It may be a fragment to add in a local object.
  • 38. merge engine merge policies Conļ¬gurable and extensible merge policies for each object type. Object merge policy Finds the equivalent local version of a remote (and thus, generated) object and merge recursively their children. These objects must be identifiable to be searched and found. These policies should be applied for fields, , methods, , types ā€¦ Type select which merge action do for local and remote objects which are merge not identiļ¬able, although being instances of the same class. i.e policies policy for the statements of an existent method.
  • 39. merge engine object merge policies ā€¢ append policy only writes new values for null ļ¬elds. Otherwise, these are not modiļ¬ed. ā€¢ overwrite policy modiļ¬es all ļ¬eld values of a local object for those generated by a transformation.
  • 40. merge engine type merge policies ā€¢ assign policy only writes the remote values. i.e replacing the list of statements of a method for the generated list. ā€¢ unmodify policy only writes the local values. i.e to respect the developer changes in the statements of an old transformation. ā€¢ addall policy that appends the remote values into the local values.
  • 41. introduction how it works transformations query engine merge engine plugins roadmap
  • 42. plugins why and how to extend walkmod? ā€¢ You can extend walkmod with new components or override the existing ones (visitors, readers, writers, walkers, merge policiesā€¦) ā€¢ Creating new plugins (java libraries) and deploying them into a maven repository (public or private). See repo.maven.apache.org ā€¢ All walkmod extensions need a plugin descriptor of their components in the META-INF/walkmod directory inside the jar library.
  • 43. plugins plugin descriptor ā€¢ Plugin descriptor is a XML file with the name walkmod-xxx-plugin.xml which follows the spring bean conļ¬guration. ā€¢ New readers, writers, walkers or transformations must be speciļ¬ed with a unique name ā€œgroupId:artifactId:nameā€ as a spring bean in the plugin descriptor. <beans> ... <bean id="walkmod:commons:import-cleaner" class="org.walkmod.visitors.ImportOrganizer" /> ... </beans>
  • 44. plugins plugin usage (I) Plugins are declared into ${project}/walkmod.xml <walkmod> <plugins> <plugins> <plugin groupId="walkmod" artifactId="walkmod-commons-plugin" version="1.0"> </plugin> </plugins> <chain name="my-chain"> ... </chain> <walkmod>
  • 45. plugins plugin usage (II) Beans declared in a plugin descriptor can be referenced from walkmod.xml using the type attribute. <walkmod> <plugins> <plugin groupId="walkmod" artifactId="walkmod-commons-plugin" version="1.0"> </plugin> </plugins> <chain name="my-chain"> ... <transformation type="walkmod:commons:imports-cleaner" /> ... </chain> </walkmod>
  • 46. 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. ā€¢ All beans used and declared in plugin descriptors are resolved by the spring source engine using the new classloader.
  • 47. introduction how it works transformations query engine merge engine plugins roadmap
  • 48. roadmap next steps ā€¢ modularization: split the project in modules in GitHub and deploy them in a Maven public repository. ā€¢ ā€¢ Java 8 support (lambda expressions) ā€¢ - less configuration: reutilization by inheritance / include rules of the XML elements. ā€¢ saas: publish online services for running walkmod and all its plugins (also private). + plugins: Create and publish new plugins (e.g. refactoring or support for other programming languages).