Skip to content

Commit deb36e3

Browse files
committed
ADD: readme.md
UPDATE: jar file
1 parent 46e41c1 commit deb36e3

File tree

2 files changed

+53
-9
lines changed

2 files changed

+53
-9
lines changed

README.md

Lines changed: 53 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,17 @@ JavaRefactor is a tool that can refactor java code while keeping original semant
1616

1717
## Usage
1818

19-
This project is build by maven and has been test on Java11, you can import it directly import it to your IDE (IDEA, Eclipse...).
19+
This project is build by maven and has been tested on Java11. You can import it directly import it to your IDE (IDEA, Eclipse...), or directly use the [Jar file](https://github.com/Feng-Jay/JavaRefactor/blob/master/out/artifacts/JavaRefactor_jar/JavaRefactor.jar) like:
2020

21-
Or you can use the [Jar file](https://github.com/Feng-Jay/JavaRefactor/blob/master/out/artifacts/JavaRefactor_jar/JavaRefactor.jar) in here.
22-
23-
JavaRefactor accept two file paths, the first is the location of the file need to be transformed, the second is the location of transformed outcome.
24-
25-
For now, the input file should be either a class which contains a function or just one function, there is an [example](https://github.com/Feng-Jay/JavaRefactor/blob/master/d4j-info/testCases/test.java)
21+
```bash
22+
java -jar JavaRefactor.jar path/to/the/target/javafile.java path/to/the/transformed/result.java
23+
```
2624

27-
You can set the function of JavaRefactor by using this [setting file](https://github.com/Feng-Jay/JavaRefactor/blob/master/src/main/resources/setting.properties).
25+
As shown, JavaRefactor accept two parameters: the first one is the path of the file need to be transformed, the second one is the path of transformed result.
2826

27+
> [!NOTE]
28+
> The input file should be either a class which contains a function or just one function, here is an [example](https://github.com/Feng-Jay/JavaRefactor/blob/master/d4j-info/testCases/test.java)
29+
> You can set the behavior of JavaRefactor by modifying this [file](https://github.com/Feng-Jay/JavaRefactor/blob/master/src/main/resources/setting.properties).
2930
3031
## Implement Details
3132

@@ -47,9 +48,13 @@ You can set the function of JavaRefactor by using this [setting file](https://gi
4748

4849
## Known Bug
4950

50-
The `SwithToIf` module is incomplete:
51+
> ![CAUTION]
52+
> The `SwitchToIf` module is complete, it will cause two types of bugs:
53+
> 1. When encountered with Enumerate object in switchCase, JavaRefactor may trigger a `can not find symbol ...` error.
54+
> 2. Due to JavaRefactor change switchStatement to a bunch of IfStatement, compiler may not aware the equality of these, and report `uninitialized object` or `missing returnStatement` errors.
55+
> The detailed explanations are below:
5156
52-
When encountered with enum in switch cases, Java will inference the enum classes automatically, like this example from [Java tutorial](https://docs.oracle.com/javase/tutorial/java/javaOO/enum.html):
57+
1. When encountered with enum in switch cases, Java will inference the enum classes automatically, like this example from [Java tutorial](https://docs.oracle.com/javase/tutorial/java/javaOO/enum.html):
5358

5459
```java
5560
public class EnumTest {
@@ -95,6 +100,45 @@ else if (day == FRIDAY)
95100

96101
We can directly find the transformed version can not pass the compiler. This project use a tricky way to solve this problem, it skip cases whose expression is all-uppercase.
97102

103+
2. Uninitialized object or Missing ReturnStatement error
104+
105+
```java
106+
...
107+
OneClass example;
108+
switch (expr):
109+
case x:
110+
example = ...;
111+
return null;
112+
case y:
113+
example = ...;
114+
return example;
115+
default:
116+
example = ...;
117+
return xxx;
118+
...
119+
```
120+
the transformed version of this will be:
121+
122+
```java
123+
...
124+
OneClass example;
125+
if (condition1){
126+
example = ...;
127+
return null;
128+
}
129+
if (condition2){
130+
example = ...;
131+
return example;
132+
}
133+
if (condition3){
134+
example = ...;
135+
return xxx;
136+
}
137+
...
138+
```
139+
140+
The compiler will report error after analysis even the semantic of this two versions of codes are identical. But these two kinds of codes are rare: only 4 bugs out of 438 defects4j bugs suffer from this.
141+
98142
## Contribution
99143

100144
Fell free to raise issues and submit pull requests! I will give you a quick response! :)
Binary file not shown.

0 commit comments

Comments
 (0)