Giter VIP home page Giter VIP logo

refdiff-python's Introduction

Welcome ๐Ÿ˜Š I'm Khalid Almosallamy and I'm a Software Developer

refdiff-python's People

Contributors

mosallamy avatar qassemna avatar rodrigo-brito avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

refdiff-python's Issues

Extract and Inline Function Refactorings

I found some issues with function calls
The parser identifies the function calls very well, but this relationship is not defined in nodes.

To extract and inline function works, we need to create relationships with the nodes:

root.getRelationships().add(new CstNodeRelationship(CstNodeRelationshipType.USE, caller.getId(),
						nodeByAddress.get(functionCall).getId()));

In RefDiff we have two relationships to setup up (USE for call functions and SUBTYPE for inheritance)

  • USE relationship is necessary to identify and extract / moves / inlines. For example, an Extract Function moves a block of code, creates a new function and USE it in the old place (function call).
  • SUBTYPE is used for Push Down and Pull Up refactorings as well (if you want support for this)

We have the information to construct the USE relationship. But, it is difficult to identify nodes. The snippet above uses a map that contains all nodes found in the parser step, in which the KEY of the map should be a unique identifier for each node. For the following example https://github.com/rodrigo-brito/refactoring-python-example/blob/master/main.py, it should look like:

{
   /main.py: <CST Node of main.py>,
   /main.py/isEven: <CST Node of isEven function>,
   /main.py/printIsEven: <CST Node of printIsEven function>,
   /calculator.py: <CST Node of calculator.py>,
   /calculator.py/Calculator: <CST Node of Calculator Class>,
   /calculator.py/Calculator/summary: <CST Node of summary Function>,
   /calculator.py/Calculator/multiply: <CST Node of multiply Function>,
}

The KEY format is free, but it should be equal between commits. Then, a good way to construct this key could be joining Parent KEY + Node name.

And functionCalls map, should contain the relationship between these unique IDs. For example, in the example repository. The CST Node /main.py should contain function calls for summary, multiply, and printIsEven. Also, printIsEven should contains a function call for isEven function.

For this example, functionCalls must be something like this:

{
   /main.py: [
      /calculator.py/Calculator/summary,
      /calculator.py/Calculator/multiply,
      /main.py/printIsEven,
   ],
   /main.py/printIsEven: [
      /main.py/isEven
   ]
}

If it is done, I think all other refactorings will work.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.