-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
In unit tests, check that the decompiled source code can be recompiled.
- Loading branch information
emmanue1
committed
Jul 29, 2019
1 parent
87ecfad
commit 518515c
Showing
9 changed files
with
1,034 additions
and
782 deletions.
There are no files selected for viewing
1,705 changes: 939 additions & 766 deletions
1,705
src/test/java/org/jd/core/v1/ClassFileToJavaSourceTest.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 3 additions & 2 deletions
5
.../util/ControlFlowGraphPlantUMLWriter.java → ...1/cfg/ControlFlowGraphPlantUMLWriter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright (c) 2008, 2019 Emmanuel Dupuy. | ||
* This project is distributed under the GPLv3 license. | ||
* This is a Copyleft license that gives the user the right to use, | ||
* copy and modify the code freely for non-commercial purposes. | ||
*/ | ||
|
||
package org.jd.core.v1.compiler; | ||
|
||
import javax.tools.*; | ||
import java.io.File; | ||
import java.io.StringWriter; | ||
import java.util.Arrays; | ||
|
||
public class CompilerUtil { | ||
protected static final File DESTINATION_DIRECTORY = new File("build/test-recompiled"); | ||
protected static final String DESTINATION_DIRECTORY_PATH = DESTINATION_DIRECTORY.getAbsolutePath(); | ||
|
||
public static boolean compile(String javaVersion, JavaFileObject... JavaFileObjects) throws Exception { | ||
boolean compilationSuccess = false; | ||
|
||
DESTINATION_DIRECTORY.mkdirs(); | ||
|
||
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); | ||
StringWriter writer = new StringWriter(); | ||
DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<>(); | ||
|
||
try (StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnostics, null, null)) { | ||
Iterable<String> options = Arrays.asList("-source", javaVersion, "-target", javaVersion, "-d", DESTINATION_DIRECTORY_PATH); | ||
Iterable<? extends JavaFileObject> compilationUnits = Arrays.asList(JavaFileObjects); | ||
compilationSuccess = compiler.getTask(writer, fileManager, diagnostics, options, null, compilationUnits).call(); | ||
|
||
for (Diagnostic d : diagnostics.getDiagnostics()) { | ||
if (d.getLineNumber() > 0) { | ||
System.err.print(String.format("%-7s - line %-4d- %s%n", d.getKind(), d.getLineNumber(), d.getMessage(null))); | ||
} else { | ||
System.err.print(String.format("%-7s - - %s%n", d.getKind(), d.getMessage(null))); | ||
} | ||
} | ||
} | ||
|
||
return compilationSuccess; | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/test/java/org/jd/core/v1/compiler/JavaSourceFileObject.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright (c) 2008, 2019 Emmanuel Dupuy. | ||
* This project is distributed under the GPLv3 license. | ||
* This is a Copyleft license that gives the user the right to use, | ||
* copy and modify the code freely for non-commercial purposes. | ||
*/ | ||
|
||
package org.jd.core.v1.compiler; | ||
|
||
import javax.tools.JavaFileObject; | ||
import javax.tools.SimpleJavaFileObject; | ||
import java.net.URI; | ||
|
||
public class JavaSourceFileObject extends SimpleJavaFileObject { | ||
/** | ||
* The source code of this "file". | ||
*/ | ||
final String code; | ||
|
||
/** | ||
* Constructs a new JavaSourceFromString. | ||
* @param name the name of the compilation unit represented by this file object | ||
* @param code the source code for the compilation unit represented by this file object | ||
*/ | ||
public JavaSourceFileObject(String name, String code) { | ||
super(URI.create("string:///" + name.replace('.','/') + JavaFileObject.Kind.SOURCE.extension), JavaFileObject.Kind.SOURCE); | ||
this.code = code; | ||
} | ||
|
||
@Override | ||
public CharSequence getCharContent(boolean ignoreEncodingErrors) { | ||
return code; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...ava/org/jd/core/v1/util/PatternMaker.java → ...va/org/jd/core/v1/regex/PatternMaker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters