Skip to content

Hacking AutoRefactor

Fabrice TIERCELIN edited this page Nov 12, 2019 · 13 revisions

Before starting hacking on AutoRefactor, you must setup your environment and download the source code. To submit pull requests, you must have a github account, so start by creating one.

Setup Eclipse

  1. Download and install JDK 8 (not higher)
  2. Download Eclipse and install it
  3. Install the Plugin Development Environment (PDE) and the resources for Java Development Tools (JDT) development into your Eclipse installation:
    1. Help menu > Install New Software...
    2. In the opening window: Work with: select: The Eclipse Project Updates - http://download.eclipse.org/eclipse/updates/4.5 (4.5 for Mars, 4.6 for Neon, etc.)
      1. Unfold Eclipse Plugin Development Tools, and select Eclipse PDE Plug-in Developer Resources and Eclipse Plug-in Development Environment
      2. Unfold Eclipse Java Development Tools, and select Eclipse JDT Plug-in Developer Resources
      3. Unfold Eclipse Platform SDK, and select Eclipse Platform SDK
    3. Then click the Next >, Next > buttons and then Finish
    4. Then restart Eclipse once asked to
  4. Install the Tycho Configurator Plugin into your Eclipse installation:
    1. Windows menu > Preferences
    2. In the opening window: unfold Maven > Discovery, then click the Open Catalog button
      1. In the opening window: type "tycho" in the Find field
      2. Select "Tycho Configurator", and click the Finish button

Get the source code

  1. Fork the project on github

Retrieve the source code (git clone)

  1. Window menu > Perspective > Open Perspective > Other...
    1. Select Git in the dialog and click OK button
    2. Then select Clone a git repository
    3. In the opening dialog window;
      1. Enter the location URI (Copy it from your fork on Github)
      2. Then in Authentication enter the User and Password and click Store in Secure Store
      3. Then click Next > button, and Next > button again
      4. Make a note of the Destination Directory, and click the Finish button

Create Eclipse projects

  1. In the Package Explorer view, right-click, then select Import...
    1. Then in the opening dialog, select Maven > Existing Maven Projects
    2. Then click Next > button
    3. Then click Browse button and select the directory where you cloned the git repository
    4. Then click Finish
  2. Adapt the files to your Eclipse
    1. In /AutoRefactor/pom.xml, using Eclipse Oxygen for example, change this :
    -      <id>Indigo</id>
    -      <layout>p2</layout>
    -      <url>http://download.eclipse.org/eclipse/updates/3.7</url>
    +      <id>Oxygen</id>
    +      <url>http://download.eclipse.org/eclipse/releases/oxygen</url>
    
    1. In MANIFEST.MF, using Eclipse Oxygen for example, change this :
    - org.eclipse.jdt.core;bundle-version="3.7.1",
    + org.eclipse.jdt.core;bundle-version="3.12.3",
    

Advices

To save time and not being disturbed by the CheckStyle rules, you should configure some save actions:

  1. Window -> Preferences -> Java -> Editor -> Save actions -> Perform the selected actions on save -> Additional actions -> Remove trailing white space on all lines
  2. Window -> Preferences -> Java -> Code style -> Formatter -> Edit -> Indentation -> Tab policy -> Spaces only

Hack

With unit tests

You should prefer coding unit tests because:

  • it is by far the fastest code/compile/run/debug cycle
  • it provides good code coverage, thus reducing possibilities of regressions

You can run tests by:

  • Running mvn clean install
  • Or running JUnit tests directly from Eclipse:
    • RefactoringRulesTest tests each refactoring rule in isolation
      • Put the class of the refactoring rule you are working with in the WHITELIST field
    • AllRefactoringRulesTest tests all refactoring rules together
      • Put the name of the refactoring rule test you are working with in the WHITELIST field
    1. Open either file, then right-click > Run As > Run Configurations...
      1. In the opening dialog, right-click JUnit Plug-in Test > New
      2. then select the Main tab, then in Program to Run, select Run an application, and in the drop-down, select [No Application] - Headless Mode
      3. then click the Apply button, and click the Run button
      4. The JUnit view should appear, and the test run should be green

Run Eclipse with your changes

  1. Run menu > Debug Configurations...
  2. then right-click on Eclipse Application, then New
  3. type "AutoRefactor" in the Name field, click Apply button, then click Debug button