Skip to content

Commit f577815

Browse files
authored
Merge pull request #19 from moacirrf/ft-refactor
Made a big refactor
2 parents f560c34 + 0dfea29 commit f577815

File tree

18 files changed

+397
-453
lines changed

18 files changed

+397
-453
lines changed

pom.xml

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
<licenseName>GNU GENERAL PUBLIC LICENSE 3.0</licenseName>
1818
<licenseFile>LICENSE</licenseFile>
1919
<!-- Path of Netbeans instalation.
20-
<netbeansInstallation>${netbeansInstalationPath}</netbeansInstallation>
21-
-->
20+
<netbeansInstallation>${netbeansInstalationPath}</netbeansInstallation>
21+
-->
2222
</configuration>
2323
</plugin>
2424
<plugin>
@@ -40,6 +40,11 @@
4040
</archive>
4141
</configuration>
4242
</plugin>
43+
<plugin>
44+
<groupId>org.apache.maven.plugins</groupId>
45+
<artifactId>maven-surefire-plugin</artifactId>
46+
<version>2.22.0</version>
47+
</plugin>
4348
</plugins>
4449
</build>
4550
<dependencies>
@@ -57,6 +62,28 @@
5762
<version>1.8.0</version>
5863
</dependency>
5964

65+
<!-- Junit -->
66+
<dependency>
67+
<groupId>org.junit.jupiter</groupId>
68+
<artifactId>junit-jupiter-api</artifactId>
69+
<version>5.6.0</version>
70+
<scope>test</scope>
71+
</dependency>
72+
73+
<dependency>
74+
<groupId>org.junit.jupiter</groupId>
75+
<artifactId>junit-jupiter-params</artifactId>
76+
<version>5.6.0</version>
77+
<scope>test</scope>
78+
</dependency>
79+
80+
<dependency>
81+
<groupId>org.junit.jupiter</groupId>
82+
<artifactId>junit-jupiter-engine</artifactId>
83+
<version>5.6.0</version>
84+
<scope>test</scope>
85+
</dependency>
86+
6087
<!-- Netbeans modules -->
6188
<dependency>
6289
<groupId>org.netbeans.api</groupId>

src/main/java/com/mrf/javadecompiler/builder/FileSystemBuilder.java

Lines changed: 0 additions & 69 deletions
This file was deleted.

src/main/java/com/mrf/javadecompiler/builder/SourceWindowBuilder.java

Lines changed: 0 additions & 89 deletions
This file was deleted.

src/main/java/com/mrf/javadecompiler/constants/Constants.java

Lines changed: 0 additions & 42 deletions
This file was deleted.

src/main/java/com/mrf/javadecompiler/decompiler/Decompiler.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,12 @@
1616
*/
1717
package com.mrf.javadecompiler.decompiler;
1818

19-
import org.openide.filesystems.FileObject;
2019

2120
/**
2221
*
2322
* @author Moacir da Roza Flores <moacirrf@gmail.com>
2423
*/
25-
public interface Decompiler<T> {
24+
public interface Decompiler<T,P> {
2625

27-
public T decompile(FileObject input);
26+
public T decompile(P input);
2827
}

src/main/java/com/mrf/javadecompiler/decompiler/DecompilerClassImpl.java

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,38 +16,36 @@
1616
*/
1717
package com.mrf.javadecompiler.decompiler;
1818

19+
import com.mrf.javadecompiler.decompiler.jdcore.PrinterImpl;
20+
import com.mrf.javadecompiler.decompiler.jdcore.LoaderImpl;
1921
import static com.machinezoo.noexception.Exceptions.wrap;
20-
import static com.mrf.javadecompiler.constants.Constants.CLASSFILE_BINARY_NAME;
21-
import static com.mrf.javadecompiler.constants.Constants.CLASS_EXT;
22-
import static com.mrf.javadecompiler.exception.ExceptionHandler.handleException;
23-
import static java.io.File.separatorChar;
24-
import static java.util.Objects.nonNull;
25-
import com.mrf.javadecompiler.builder.FileSystemBuilder;
22+
import com.mrf.javadecompiler.exception.ExceptionHandler;
23+
import com.mrf.javadecompiler.filesystems.FileSystemHelper;
2624
import org.jd.core.v1.ClassFileToJavaSourceDecompiler;
2725
import org.openide.filesystems.FileObject;
2826

2927
/**
3028
*
3129
* @author Moacir da Roza Flores <moacirrf@gmail.com>
3230
*/
33-
public class DecompilerClassImpl implements Decompiler<String> {
31+
public final class DecompilerClassImpl implements Decompiler<String, FileObject> {
32+
33+
public static final String HEADER_COMMENT = "//\n"
34+
+ "// Source code recreated by Apache Netbeans\n"
35+
+ "// (powered by Java Decompiler http://java-decompiler.github.io )\n"
36+
+ "//\n";
3437

3538
@Override
3639
public String decompile(FileObject file) {
37-
return wrap(e -> handleException(e)).get(() -> {
38-
LoaderImpl loader = new LoaderImpl(FileSystemBuilder.build(file));
40+
return wrap(ExceptionHandler::handleException).get(() -> {
41+
LoaderImpl loader = new LoaderImpl(FileSystemHelper.of(file));
3942
PrinterImpl printer = new PrinterImpl();
43+
4044
ClassFileToJavaSourceDecompiler decompiler = new ClassFileToJavaSourceDecompiler();
41-
decompiler.decompile(loader, printer, getFileName(file));
42-
return printer.toString();
45+
decompiler.decompile(loader, printer, FileSystemHelper.extractName(file));
46+
47+
return HEADER_COMMENT + printer.toString();
4348
});
4449
}
4550

46-
private String getFileName(FileObject file) {
47-
Object fileName = file.getAttribute(CLASSFILE_BINARY_NAME);
48-
if (nonNull(fileName)) {
49-
return String.valueOf(fileName) + CLASS_EXT;
50-
}
51-
return file.getParent().getPath() + separatorChar + file.getName() + CLASS_EXT;
52-
}
5351
}

src/main/java/com/mrf/javadecompiler/factory/DecompilerFactory.java renamed to src/main/java/com/mrf/javadecompiler/decompiler/DecompilerFactory.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@
1414
* You should have received a copy of the GNU General Public License
1515
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1616
*/
17-
package com.mrf.javadecompiler.factory;
18-
19-
import com.mrf.javadecompiler.decompiler.Decompiler;
20-
import com.mrf.javadecompiler.decompiler.DecompilerClassImpl;
17+
package com.mrf.javadecompiler.decompiler;
2118

2219
/**
2320
*

src/main/java/com/mrf/javadecompiler/decompiler/LoaderImpl.java renamed to src/main/java/com/mrf/javadecompiler/decompiler/jdcore/LoaderImpl.java

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,39 +14,44 @@
1414
* You should have received a copy of the GNU General Public License
1515
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1616
*/
17-
package com.mrf.javadecompiler.decompiler;
17+
package com.mrf.javadecompiler.decompiler.jdcore;
1818

19+
import com.mrf.javadecompiler.filesystems.FileSystemHelper;
1920
import java.io.IOException;
21+
import static java.util.Objects.nonNull;
2022
import org.jd.core.v1.api.loader.Loader;
2123
import org.jd.core.v1.api.loader.LoaderException;
2224
import org.openide.filesystems.FileObject;
23-
import org.openide.filesystems.FileSystem;
2425

2526
/**
2627
*
2728
* @author Moacir da Roza Flores <moacirrf@gmail.com>
2829
*/
2930
public class LoaderImpl implements Loader {
3031

31-
private final FileSystem fileSystem;
32-
33-
public LoaderImpl(FileSystem fileSystem) {
34-
this.fileSystem = fileSystem;
32+
private final FileSystemHelper input;
33+
34+
public LoaderImpl(FileSystemHelper input) {
35+
this.input = input;
3536
}
3637

3738
@Override
3839
public boolean canLoad(String internalName) {
39-
FileObject fileObject = fileSystem.findResource(internalName);
40-
if (fileObject == null) {
41-
return false;
42-
}
43-
return fileObject.canRead();
40+
FileObject file = input.findResource(internalName);
41+
if (nonNull(file)) {
42+
return file.canRead();
43+
}
44+
return false;
4445
}
4546

4647
@Override
4748
public byte[] load(String internalName) throws LoaderException {
4849
try {
49-
return fileSystem.findResource(internalName).asBytes();
50+
FileObject file = input.findResource(internalName);
51+
if (nonNull(file)) {
52+
return file.asBytes();
53+
}
54+
return null;
5055
} catch (IOException ex) {
5156
throw new LoaderException(ex);
5257
}

0 commit comments

Comments
 (0)