Giter Site home page Giter Site logo

shehan / refdiff Goto Github PK

View Code? Open in Web Editor NEW

This project forked from aserg-ufmg/refdiff

0.0 1.0 0.0 35 MB

A tool to mine refactorings in the commit history of git repositories.

License: MIT License

Java 41.56% C 0.60% C++ 0.01% JavaScript 57.81% HTML 0.02%

refdiff's Introduction

RefDiff

RefDiff is a tool to mine refactorings in the commit history of git repositories. Currently, three programming languages are supported: Java, JavaScript, and C.

RefDiff finds relationships between code elements of two given revisions of the project. Relationships indicate that both elements are the same, or that a refactoring operation involving them was applied. The following relationship types are supported:

  • Same
  • Convert Type
  • Change Signature of Method/Function
  • Pull Up Method
  • Push Down Method
  • Rename
  • Move
  • Move and Rename
  • Extract Supertype (e.g., Class/Interface)
  • Extract Method/Function
  • Inline Method/Function

Getting started

git clone https://github.com/aserg-ufmg/RefDiff.git

Use gradle to create the Eclipse IDE project metadata.

cd RefDiff
gradlew eclipse

Import all projects within RefDiff folder to Eclipse. Then, see the examples in RefDiffExample.java from refdiff-example.

You can detect refactorings in a certain repository/commit using the following code:

private static void runExamples() throws Exception {
	// This is a temp folder to clone or checkout git repositories.
	File tempFolder = new File("temp");

	// Creates a RefDiff instance configured with the JavaScript parser.
	JsParser jsParser = new JsParser();
	RefDiff refDiffJs = new RefDiff(jsParser);

	// Clone the angular.js GitHub repo.
	File angularJsRepo = refDiffJs.cloneGitRepository(
		new File(tempFolder, "angular.js"),
		"https://github.com/refdiff-study/angular.js.git");

	// You can compute the relationships between the code elements in a commit with
	// its previous commit. The result of this operation is a CstDiff object, which
	// contains all relationships between CstNodes. Relationships whose type is different
	// from RelationshipType.SAME are refactorings.
	CstDiff diffForCommit = refDiffJs.computeDiffForCommit(angularJsRepo, "2636105");
	printRefactorings("Refactorings found in angular.js 2636105", diffForCommit);
}
private static void printRefactorings(String headLine, CstDiff diff) {
	System.out.println(headLine);
	for (Relationship rel : diff.getRefactoringRelationships()) {
		System.out.println(rel.getStandardDescription());
	}
}

You can also mine recatorings from the commit history:

// You can also mine refactoring from the commit history. In this example we navigate
// the commit graph backwards up to 5 commits. Merge commits are skipped.
refDiffJs.computeDiffForCommitHistory(angularJsRepo, 5, (commit, diff) -> {
	printRefactorings("Refactorings found in angular.js " + commit.getId().name(), diff);
});

You can use different parsers to mine refactorings in other programming languages:

// In this example, we use the parser for C.
CParser cParser = new CParser();
RefDiff refDiffC = new RefDiff(cParser);

File gitRepo = refDiffC.cloneGitRepository(
	new File(tempFolder, "git"),
	"https://github.com/refdiff-study/git.git");

printRefactorings(
	"Refactorings found in git ba97aea",
	refDiffC.computeDiffForCommit(gitRepo, "ba97aea1659e249a3a58ecc5f583ee2056a90ad8"));


// Now, we use the parser for Java.
JavaParser javaParser = new JavaParser(tempFolder);
RefDiff refDiffJava = new RefDiff(javaParser);

File eclipseThemesRepo = refDiffC.cloneGitRepository(
	new File(tempFolder, "eclipse-themes"),
	"https://github.com/icse18-refactorings/eclipse-themes.git");

printRefactorings(
	"Refactorings found in eclipse-themes 72f61ec",
	refDiffJava.computeDiffForCommit(eclipseThemesRepo, "72f61ec"));

Extending RefDiff to support other programming languages

You can implement the CstParser interface to support other programming languages. Soon, we will provide a detailed tutorial on how to do this.

Example data

The following figure shows the number of refactorings detected by RefDiff when executed over all commits of JUnit4.

Junit4 results

Publications

The algorithm RefDiff uses is described in details in the following paper:

The data used in the evaluation is available in this spreadsheet.

Learn more about our research group at http://aserg.labsoft.dcc.ufmg.br/

refdiff's People

Contributors

danilofes avatar joaopribs avatar mtov avatar

Watchers

James Cloos avatar

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.