You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+53-9Lines changed: 53 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,16 +16,17 @@ JavaRefactor is a tool that can refactor java code while keeping original semant
16
16
17
17
## Usage
18
18
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:
20
20
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)
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.
28
26
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).
29
30
30
31
## Implement Details
31
32
@@ -47,9 +48,13 @@ You can set the function of JavaRefactor by using this [setting file](https://gi
47
48
48
49
## Known Bug
49
50
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:
51
56
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):
53
58
54
59
```java
55
60
publicclassEnumTest {
@@ -95,6 +100,45 @@ else if (day == FRIDAY)
95
100
96
101
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.
97
102
103
+
2. Uninitialized object or Missing ReturnStatement error
104
+
105
+
```java
106
+
...
107
+
OneClass example;
108
+
switch (expr):
109
+
case x:
110
+
example =...;
111
+
returnnull;
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
+
returnnull;
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
+
98
142
## Contribution
99
143
100
144
Fell free to raise issues and submit pull requests! I will give you a quick response! :)
0 commit comments