DIY Refactorings in Wrangler Huiqing Li Simon Thompson School of Computing University of Kent.

Slides:



Advertisements
Similar presentations
Tool Support for Refactoring Functional Programs Huiqing Li Claus Reinke Simon Thompson Computing Lab, University of Kent
Advertisements

Progress on ‘HaRe: The Haskell Refactorer’ Huiqing Li, Claus Reinke, Simon Thompson Computing Laboratory, University of Kent Refactoring is the process.
Chapter 4 Quality Assurance in Context
Konstanz, Jens Gerken ZuiScat An Overview of data quality problems and data cleaning solution approaches Data Cleaning Seminarvortrag: Digital.
MP IP Strategy Stateye-GUI Provided by Edotronik Munich, May 05, 2006.
Automated creation of verification models for C-programs Yury Yusupov Saint-Petersburg State Polytechnic University The Second Spring Young Researchers.
Refactoring Erlang Programs Huiqing Li Simon Thompson University of Kent.
The Formalisation of Haskell Refactorings Huiqing Li Simon Thompson Computing Lab, University of Kent
20-Jun-15 Eclipse. Most slides from: 2 About IDEs An IDE is an Integrated Development Environment.
Refactoring Haskell Programs Huiqing Li Computing Lab, University of Kent
Demo of Software Refactoring with Eclipse Giriprasad Sridhara CISC 879 Spring 2007 May
WRT 2007 Refactoring Functional Programs Huiqing Li Simon Thompson Computing Lab Chris Brown Claus Reinke University of Kent.
Functional programming: LISP Originally developed for symbolic computing First interactive, interpreted language Dynamic typing: values have types, variables.
The Haskell Refactorer, HaRe, and its API Huiqing Li Claus Reinke Simon Thompson Computing Lab, University of Kent
Views Dwight Deugo Nesa Matic
Generative Programming. Generic vs Generative Generic Programming focuses on representing families of domain concepts Generic Programming focuses on representing.
CODING Research Data Management. Research Data Management Coding When writing software or analytical code it is important that others and your future.
1 An introduction to design patterns Based on material produced by John Vlissides and Douglas C. Schmidt.
CSC 8310 Programming Languages Meeting 2 September 2/3, 2014.
Python Mini-Course University of Oklahoma Department of Psychology Day 1 – Lesson 2 Fundamentals of Programming Languages 4/5/09 Python Mini-Course: Day.
Comp. Eng. SW Lab II: FP with Scheme 1 Computer Eng. Software Lab II , Semester 2, Who I am: Andrew Davison CoE, WiG Lab Office.
Xactium xDSLs Run Models Not Code Tony Clark
Working Out with KURL! Shayne Koestler Kinetic Data.
C++ Code Analysis: an Open Architecture for the Verification of Coding Rules Paolo Tonella ITC-irst, Centro per la Ricerca Scientifica e Tecnologica
8 Shell Programming Mauro Jaskelioff. Introduction Environment variables –How to use and assign them –Your PATH variable Introduction to shell programming.
Hands-on Refactoring with Wrangler Simon Thompson Huiqing Li, Xingdong Bian University of Kent.
1 The Software Development Process  Systems analysis  Systems design  Implementation  Testing  Documentation  Evaluation  Maintenance.
Reviewing Recent ICSE Proceedings For:.  Defining and Continuous Checking of Structural Program Dependencies  Automatic Inference of Structural Changes.
Computational Methods of Scientific Programming Lecturers Thomas A Herring, Room A, Chris Hill, Room ,
Automate Administration with KURL Shayne Koestler.
Supported by ELTE IKKK, Ericsson Hungary, in cooperation with University of Kent Erlang refactoring with relational database Anikó Víg and Tamás Nagy Supervisors:
Generative Programming. Automated Assembly Lines.
User Support Chapter 8. Overview Assumption/IDEALLY: If a system is properly design, it should be completely of ease to use, thus user will require little.
Supported by ELTE IKKK, Ericsson Hungary, in cooperation with University of Kent Erlang refactoring with relational database Anikó Víg and Tamás Nagy Supervisors:
C++ History C++ was designed at AT&T Bell Labs by Bjarne Stroustrup in the early 80's Based on the ‘C’ programming language C++ language standardised in.
1 5 Nov 2002 Risto Pohjonen, Juha-Pekka Tolvanen MetaCase Consulting AUTOMATED PRODUCTION OF FAMILY MEMBERS: LESSONS LEARNED.
Eclipse Eclipse An IDE is an Integrated Development Environment Different IDEs meet different needs – BlueJ, DrJava are designed as teaching.
© 2006 by WTP PMC; made available under the EPL v1.0 | Cambridge | September 6, 2006 Hakeem Shittu Software Consultant Customizing Eclipse Functionality.
Sed, awk, & perl CS 2204 Class meeting 13 *Notes by Mir Farooq Ali and other members of the CS faculty at Virginia Tech. Copyright 2003.
Refactoring Erlang Programs Huiqing Li Simon Thompson University of Kent Zoltán Horváth Eötvös Loránd Univ.
Eclipse 24-Apr-17.
EMACS Jim Vallino Proud emacs user since The truth about editors Editors are like religions. Everyone has one that they like.
The Software Development Process
Demeter Aspects We study techniques for the emerging area of Aspect-Oriented Software Development and focus on the following areas:  Aspectual Collaborations.
Trinity College Dublin, The University of Dublin GE3M25: Computer Programming for Biologists Python Karsten Hokamp, PhD Genetics TCD, 03/11/2015.
Basic Scheme February 8, 2007 Compound expressions Rules of evaluation Creating procedures by capturing common patterns.
Scalable Clone Detection and Elimination for Erlang Programs Huiqing Li, Simon Thompson University of Kent Canterbury, UK.
Differences Training BAAN IVc-BaanERP 5.0c: Application Administration, Customization and Exchange BaanERP 5.0c Tools / Exchange.
1/33 Basic Scheme February 8, 2007 Compound expressions Rules of evaluation Creating procedures by capturing common patterns.
Static Techniques for V&V. Hierarchy of V&V techniques Static Analysis V&V Dynamic Techniques Model Checking Simulation Symbolic Execution Testing Informal.
Recent Enhancements to Quality Assurance and Case Management within the Emissions Modeling Framework Alison Eyth, R. Partheepan, Q. He Carolina Environmental.
Cs498dm Software Testing Darko Marinov January 27, 2009.
Haskell Basics CSCE 314 Spring CSCE 314 – Programming Studio Using GHC and GHCi Log in to unix.cse.tamu.edu (or some other server) From a shell.
Duke CPS Programming Heuristics l Identify the aspects of your application that vary and separate them from what stays the same ä Take what varies.
Computer Eng. Software Lab II , Semester 2, Who I am: Andrew Davison CoE, WiG Lab Office Functional Programming.
Model Transformation By Demonstration Yu Sun, Jules White, Jeff Gray This work funded in part by NSF CAREER award CCF CIS Dept. – University of.
Eclipse 27-Apr-17.
ECE 750 Topic 8 Meta-programming languages, systems, and applications Automatic Program Specialization for J ava – U. P. Schultz, J. L. Lawall, C. Consel.
Text2PTO: Modernizing Patent Application Filing A Proposal for Submitting Text Applications to the USPTO.
Introduction to Software Testing (2nd edition) Chapter 5 Criteria-Based Test Design Paul Ammann & Jeff Offutt
Being Productive With Emacs Part 2
Operational Semantics of Scheme
Development Environment
Basic Scheme February 8, 2007 Compound expressions Rules of evaluation
PowerShell Introduction Copyright © 2016 – Curt Hill.
A video coding and data visualization tool
Eclipse 20-Sep-18.
Lecture 15 (Notes by P. N. Hilfinger and R. Bodik)
6.001 SICP Variations on a Scheme
Presentation transcript:

DIY Refactorings in Wrangler Huiqing Li Simon Thompson School of Computing University of Kent

Overview Refactoring. Wrangler. DIY Elementary Refactorings. DIY Code Inspections. DIY Composite Refactorings. Demo...

Refactoring Change how a program works without changing what it does. RefactorModify

Why Refactor? Extension and reuse. – function extraction, generalisation,... Correct a syntactic decision made earlier. – renaming, re-arrange arguments, relocate functions, map to list comprehension,... Counteract decay. – clone elimination, module restructure,... API migration. – regexp → re, lists:keysearch/2 → list:keyfind/2,...

How to Refactor? By hand … using an editor. – flexible, but error-prone. – infeasible in the large. Tool support. – scalable to large codebase. – quick and reliable. – undo/redo.

Wrangler A Refactoring and code smell inspection tool for Erlang

Wrangler in a nutshell Automate the simple things, and provide decision support tools otherwise. Embedded in common IDEs: (X)Emacs, Eclipse. Handle full language. Faithful to layout and comments. Undo Build in Erlang, and apply the tool to itself.

Wrangler

Basic Refactorings and Code inspections Code clone detection and removal Module structural improvement

Demo

Wrangler So what are the limitations? Only a set of `core' refactorings supported. Only elementary refactorings are supported, i.e., batch refactorings are not supported. Wrangler is designed as a black-box.

Wrangler Basic Refactorings and Code inspections Code Clone Detection and Removal Module structural improvement Template- and rule- base API for DIY basic refactorings/ code inspections A DSL for DIY batch refactorings

Wrangler built-in refactorings Refactorings contributed by users User's own refactorings + +

DIY Basic Refactorings Design criteria We assume you can program Erlang … … but don't want to learn the internal syntax or details of our representation and libraries. We aim for simplicity and clarity, rather than full coverage.

DIY elementary refactorings 16 Templates describe code fragments Rules describe transformations Context available for condition analysis Traversals describe how rules are applied Erlang Behaviour for refactoring

Templates Templates are enclosed in the ?T macro call. Meta-variables in templates are Erlang variables end e.g. Meta-atoms in templates are Erlang atoms end e.g.

Templates Examples 2)'') matches a single element. matches a sequence of elements of some kind. matches a function clause. matches a function definition of a single function clause.

Rules rule({M,F,A}, N) -> begin end, == {M,F,A}). delete(N, List) -> … delete Nth elem of List … ?RULE(Template, NewCode, Cond) The old code, the new code and the pre-condition.

Information in the AAST Wrangler uses the syntax_tools AST, augmented with information about the program semantics. API functions provide access to this. Variables bound, free and visible at a node. Location information. All bindings (if a vbl). Where defined (if a fn). Atom usage info: name, function, module etc. Process info …

Collecting Information ?COLLECT(Template, Collector, Cond) The template to match. In information to extract (“collect”). Condition on when to collect information.

Collecting information when -> lists:nth(Nth, =={M, F, A}) == variable andalso [ _ ] == current file subtree matching ?T(…) Collect the nth parameters Unnecessary match

AST Traversals ?FULL_TD_TP(Rules, Scope) Traverse top-down. At each node, apply first of Rules to succeed … TP = “Type Preserving”.

AST Traversals ?STOP_TD_TU(Collectors, Scope) Traverse top-down. … apply all of the collectors to succeed… TU = “Type Unifying”.

Generic Refactoring Behaviour Behaviour gen_refac encapsulates what a refactoring needs to provide Callback functions : input_par_prompts/0: prompts for interactive input. select_focus/1: what to do with focus information. selective/0: selective refactoring or not. pre_cond_check/1: check pre-conditions. transform/1: if the pre-condition is ok, do the transformation.

DIY Refactorings In Wrangler -module(refac_replace_append). %module name is also refactoring name. -include_lib(“wrangler/lib/wrangler.hrl”) -behaviour(gen_refac). -export([input_par_prompts/0, select_focus/1,check_pre_cond/1, selective/0,transform/1]). % Callback functions. input_par_prompts() -> []. % No user input is needed. select_focus(_Args) -> {ok, none}. % No focus selection is need. check_pre_cond(_Args) -> ok. % No pre-condition. selective() -> true. % Allow selective refactoring. transform(_Args=#args{search_paths=SearchPaths})-> ?FULL_TD_TP([rule_replace_append()], SearchPaths). rule_replace_append() -> {lists,append,2} ==

DIY Refactorings In Wrangler rule1({M,F,A}, I, J) -> % transform the function definition itself. when -> begin when end, == {M, F, A}). rule2({M,F,A}, I, J) -> % Transform the different kinds of function applications. ?RULE(?FUN_APPLY(M,F,A), begin NewArgs=swap(Args, I, J), end, true). rule3({_M, F, A}, I, J) -> % transform the type spec. I, J), {F, A})). Transformation rules for swapping arguments

DIY Code Inspections In Wrangler calls_to_specific_function(input_par_prompts) -> ["Module name: ", "Function name: ", "Arity: "]; calls_to_specific_function(_Args=#args{user_inputs=[M,F,A], search_paths=SearchPaths}) -> {M1, F1, A1}={list_to_atom(M), list_to_atom(F), list_to_integer(A)}, ?FULL_TD_TU([?COLLECT_LOC(?FUN_APPLY(M1, F1, A1), true)], [SearchPaths]). Collect falls to a specific Function

Demo

DIY Composite Refactorings A set of elementary refactorings to be applied in a sequence in order to achieve a complex refactoring effect. Composite Refactoring

DIY Composite Refactorings Example 1. Batch renaming of function names from CamelCase to camel_case. – Rename, Rename, Rename,...

DIY Composite Refactorings Example 2. Clone elimination. – generate new function, – rename function, – rename variables, – re-order parameters, – add to export, – folding.

DIY Composite Refactorings Generation of refactoring commands. Tracking of program entity names. Handling of failure. User control over the execution of refactorings. Issues to handle

DIY Composite Refactorings Manual vs. automatic. Static vs. dynamic. Generation of refactoring cmds

Generation of Refactoring Cmds

Generation of Refactoring Commands ?refac_(rename_fun, [{file, fun(_File)-> true end}, fun({F, _A}) -> camelCase_to_camel_case(F) /= F end, {generator, fun({_File, F,_A}) -> camelCase_to_camel_case(F) end}], SearchPaths). Example: Generation of refactoring cmds that rename function names in camelCase to camel_case. ?refac_(CmdName, Args, Scope)

Track Program Entity Names The name of an entity (function, module, process name) referred by a refactoring may have been changed by one or more previous refactorings. Manual tracking of names infeasible. Wrangler tracks the renaming history in the background … … uses use the macro ?current to retrieve the latest name of an entity.

Handling of Failure What to do if a refactoring fails? Atomic composite refactoring. ?atomic(Refacs)

Handling of Failure What to do if a refactoring fails? Non-atomic composite refactoring. ?non_atomic(Refacs)

Handling of Failure What to do if a refactoring fails? ?non_atomic( ?refac_(rename_fun, [{file, fun(_File)-> true end}, fun({F, _A}) -> camelCase_to_camel_case(F) /= F end, {generator, fun({_File, F,_A}) -> camelCase_to_camel_case(F) end}], SearchPaths))

User control Allow the user to control whether a refactoring should be performed. ?interative(Refacs). ?interactive( ?non_atomic( ?refac_(rename_fun, [{file, fun(_File)-> true end}, fun({F, _A}) -> camelCase_to_camel_case(F) /= F end, {generator, fun({_File, F,_A}) -> camelCase_to_camel_case(F) end}], SearchPaths)))

A DSL for Compound Refactorings % conditional cmd generation. % repetitive conditional cmd % g eneration. % repetitive interaction.

DIY Composite Refactorings Example 2. Clone elimination. – generate new function, – rename function, – rename variables, – re-order parameters, – add to export, – folding.

Demo

Generic Refactoring Behaviour Behaviour gen_composite_refac encapsulates what a composite refactoring needs to provide. Callback functions : input_par_prompts/0: prompts for interactive input. select_focus/1: what to do with focus information. composite_refac/1: defines the refactoring script.

Find out more 48 Latest release of Wrangler: Papers: A User-extensible Refactoring Tool for Erlang Programs. Huiqing Li and Simon Thompson A Domain-Specific Language for Scripting Refactorings in Erlang. Huiqing Li and Simon Thompson

Installation: Mac OS X and Linux Download Wrangler-1.0 from or get it from In the wrangler directory./configure make (sudo) make install 49

Installation: Mac OS X and Linux Add to ~/.emacs file: (add-to-list 'load-path "/usr/local/lib/erlang/lib/wrangler- /elisp") (require 'wrangler) If you’re installing emacs now, then you add the following lines to your ~/.emacs file (setq load-path (cons "/usr/local/otp/lib/tools- /emacs" load-path)) (setq erlang-root-dir "/usr/local/otp") (setq exec-path (cons "/usr/local/otp/bin" exec-path)) (require 'erlang-start) 50

Installation: Windows Requires R11B-5 or later + Emacs Download installer from Requires no other actions. 51

Installation: Eclipse + ErlIDE Requires Erlang R11B-5 or later, if it isn't already present on your system. On Windows systems, use a path with no spaces in it. Install Eclipse 3.5, if you didn't already. All the details at 52

Starting Wrangler in Emacs Open emacs, and open a.erl file. M-x erlang-refactor-on or C-c, C-r New menu: Wrangler Customise for dir Undo C-c, C-w, _ 53

Preview Feature Preview changes before confirming the change Emacs ediff is used. 54

Stopping Wrangler in Emacs M-x erlang-refactor-off to stop Wrangler Shortcut C-c, C-r 55

Carrying on … Try on your own project code … Feedback: or 56