tsantalis / JDeodorant

JDeodorant
https://marketplace.eclipse.org/content/jdeodorant
MIT License
139 stars 59 forks source link

Duplicate Code refactoring not working #43

Closed prabh27 closed 8 years ago

prabh27 commented 8 years ago

I use NiCad4 to detect the duplicate code, but when I use JDeodorant to refactor the code, nothing happens.

tsantalis commented 8 years ago

Please report the project (repository or link to download) and the exact clone fragments you tried to refactor.

prabh27 commented 8 years ago

Project -> https://github.com/prabh27/DuplicateCodeAntipattern1 Functions that are cloned are: shift, shift2. NiCad detects the functions, but when I select both the clones and click on refactor, nothing happens. I am using a 64-bit Mac.

tsantalis commented 8 years ago

You need to setup your code as an Eclipse Java project. It works fine. See screenshot below.

2016-08-10 09_06_22-extract clone

prabh27 commented 8 years ago

Unable to do it. I followed the steps given in the video. Could you please tell me the steps that you followed?

tsantalis commented 8 years ago

I first made an Eclipse Java project (File -> New -> Java Project) with the source code you provided. Then in the Package Explorer view (Java Perspective), I selected both methods (by holding down Ctrl), and right-clicked on them. A pop-up menu appears and you select "Refactor Duplicated code".

Alternatively, you can import results from NiCad or other clone detectors. From the Bad Smells menu, click Duplicated Code to open the view. The view has an import button (i) that opens the Import wizard. Select the project in the Package Explorer and click on the import button. In the wizard you should browse to the *-classes.xml file exported by NiCad (for example _blocks-blind-clones-0.2-classes.xml) After parsing the file, the clone groups will appear in the Duplicated code view. You can scroll up/down to find the clone group corresponding to these methods. Select the two clones in the group holding down Ctrl, right click, and then Refactor.

dominicpp commented 4 years ago

old but gold. Thank you @tsantalis I had the same issue.