Create and Undo Visitors Using R3
In
this assignment you will use R3 to write two refactoring scripts: (a)
one that automatically retrofits a Visitor design pattern into a legacy
program, and (b) one that automatically removes a Visitor pattern
from a legacy program. You will use R3 (Eclipse
plug-in) and ONLY
R3 refactorings in this assignment. Using anything else gets
you 0
(zero, nada, null) for this assignment. If you vary from what is
described below, you must get permission otherwise you get no credit.
Preliminaries
Part 1: R3 Installation
Please
follow the steps below:
- Install
Java Runtime Environment (JRE) if it is not installed.
JRE version (x64)
- Download
Eclipse and unzip it. You must use the version of Eclipse below
even
if you have an existing Eclipse in your machine.
- Run Eclipse.
Video
- You
have to watch every video tutorial very carefully.
- The
video shows examples so they may not be consistent with what
you actually do.
- Download
R3 and then import into Eclipse as a project.
Video
R3.zip or
R3.zipp
(rename to R3.zip after downloading)
- Copy
and paste the following codes into the body of method myMethod() in class MyClass.
///////////////////////////////////////////////////////////////////////
//
// Write your script here
//
//Create a new class named “D”.
RPackage pkg = RProject.getPackage("TestProject",
"testPackage");
RClassOrInterface cls = pkg.newClass("D");
//
///////////////////////////////////////////////////////////////////////
- Run
R3 (as "Eclipse Application").
Video
- Download
TestProject program. TestProject is the target program to be
refactored.
TestProject.zip
- Import
the TestProject program into Eclipse plug-in. Now you have
two Eclipse instances (R3 and TestProject) running.
Video
- Try "Preview".
Video
- Clicking "Preview" menu runs the R3 scripts written inside the body of method
myMethod()
in class MyClass
and prints out refactored TestProject to
console of the Eclipse R3 instance.
- However,
it does not change the source codes in the Eclipse TestProject instance.
- "Preview"
is useful when you want to preview how your R3 script refactors the
target program.
- Execute
the R3 script.
Video
- Clicking "Refactor" menu refactors the source codes in the Eclipse TestProject
instance directly.
- Do
not forget to "refresh (F5)" the Eclipse Project Explorer.
- Check
whether a new class named "D" is created successfully.
Do
NOT proceed to the next part of this assignment if you fail the test in
Step 11.
Preliminaries
Part 2: Initialize R3
Please
follow the steps below:
- Read
very carefully tutorials below.
- Delete
Eclipse "runtime-EclipseApplication" directory (if it does exist):
Video
The location is:
- Windows:
the same directory with Eclipse
- Linux:
the same directory with Eclipse
- Mac
OS: /Users/username/Documents/R3
- Run
Eclipse (installed at Preliminaries Part 1).
Part
1: Make-Visitor Using R3
Please
follow the steps below:
- Follow
Preliminaries Part 2: Initialize R3
- Find
R3 project in the Eclipse "Package Explorer".
- Find
class MyClass.
- Copy
source code of MyClass.java
to MyClass.
- Run
R3 (as "Eclipse Application").
- Download
RefactoringCrawler program and then import into Eclipse plug-in.
RefactoringCrawler is the target program to be refactored You
don’t need to understand the semantics of RefactoringCrawler.
Watch this video on how to import an Eclipse Project.
Download RefactoringCrawler.zip
- Write
your R3 script that makes a Visitor pattern for method computeLikeliness(Node, Node)
in class edu.uiuc.detectRefactorings.detection.FieldDetection.
- Your
R3 script should be written inside the body of method myMethod() in
class MyClass.
- You
must close the Eclipse RefactoringCrawler instance (if it is opened)
and run R3 again before proceeding to the next step.
- Execute
your R3 script. (Tip: "Preview" is useful to see if your R3
script can run.)
- You
may make mistakes in your R3 script and want to reimport the original
RefactoringCrawler program, and repair your R3 script.
- Close the
Eclipse RefactoringCrawler instance (if it is opened).
- Delete your "runtime-EclipseApplication" directory.
- Run R3 and
import the original RefactoringCrawler program.
- Run
regression tests on package edu.uiuc.tests
to see if the refactored
RefactoringCrawler works correctly. If it works, proceed to the next
step.
Run as "JUnit Test" (not as "JUnit Plug-in Test") which executes 10 (not 15) regression tests. Watch this video.
- Export your RefactoringCrawler+ a PDF File containing/explaining your R3 script named "MakeVisitorUsingR3.zip". Watch this video.
- Export
your RefactoringCrawler + a PDF File containing/explaining your R3 script named "MakeVisitorUsingR3.zip".
- Create "MakeVisitorUsingR3.zip".
Part
2: Undo-Visitor Using R3
Please
follow the steps below:
- Follow
Preliminaries Part 2: Initialize R3
- Find
R3 project in the Eclipse "Package Explorer".
- Find
class MyClass.
- Copy
source code of MyClass.java
to MyClass.
- Run
R3 (as "Eclipse Application").
- Download
RefactoringCrawlerWithVisitor program and then import into Eclipse as a
project. RefactoringCrawlerWithVisitor
is the target program
to
be refactored. You don’t need to understand the semantics of
RefactoringCrawlerWithVisitor.
Watch this video on how to import an Eclipse Project.
Then download RefactoringCrawlerWithVisitor.zip
- Write
your R3 script that undoes a Visitor pattern of class Visitor in
package edu.uiuc.detectRefactorings.detection
and set the original
method name as "isRename".
- Your
R3 script should be written inside the body of method myMethod() in
class MyClass.
- You
must close the Eclipse RefactoringCrawlerWithVisitor
instance (if it is opened)
and run R3 again before proceeding to the next step.
- Execute
your R3 script. (Tip: "Preview" is useful to see if your R3
script can run.)
- You
may make mistakes in your R3 script and want to reimport the original
RefactoringCrawlerWithVisitor program, and repair your R3 script.
- Close
the Eclipse RefactoringCrawlerWithVisitor instance (if it is opened).
- Delete
your "runtime-EclipseApplication" directory.
- Run
R3 and import the original RefactoringCrawlerWithVisitor program.
- Run
regression tests on package edu.uiuc.tests
to see if the refactored
RefactoringCrawlerWithVisitor works correctly. If it works, proceed to
the next step.
Run as "JUnit Test" (not as "JUnit Plug-in Test") which executes 10 (not 15) regression tests. Watch this video.
- Export
your RefactoringCrawlerWithVisitor + a PDF File containing/explaining your R3 script named "UndoVisitorUsingR3.zip". Watch this video.
- Create "UndoVisitorUsingR3.zip".
What to Submit
All of the below in a zip file (including your R3 Eclipse Projects). The zip file must unzip into <yourName>/<YourFilesAndDirectories>.
- Your
program needs to run correctly on Linux machines, even though you may
have developed them on Macs and Windoze. The TA will grade your
program running on Linux.
- A short description that the Grader needs to know to run your program, other than the above.
- A short writeup explaining any difficulties in using R3 for this assignment.
- A PDF file (in the required format) that the Grader should read to provide any information that is not obvious. The contents of the PDF file can be minimal.
A
critical part of any design is clarity and understandability. Hence,
you will be graded on the clarity of your project and its ability to
work correctly. Sloppy code, documentation, or anything that makes
grading or understanding your program difficult will cost you points.
Beware, some of these "beauty" points are subjective.
Remember: No late assignments/submissions will be accepted.