java-decompiler: switch to bundled engine

This commit is contained in:
Roman Shevchenko
2014-09-01 20:47:45 +04:00
parent 62ab512155
commit 4761ed348a
8 changed files with 30 additions and 99 deletions
+1 -8
View File
@@ -554,14 +554,7 @@ public def layoutCommunityPlugins(String home) {
}
}
pluginDir("java-decompiler") {
dir("lib") {
jar("java-decompiler.jar") {
module("java-decompiler")
}
fileset(file: "$home/plugins/java-decompiler/lib/fernflower.jar")
}
}
layoutPlugin("java-decompiler")
}
}
-1
View File
@@ -285,4 +285,3 @@ jetbrainsLibrary("JPS")
jetbrainsLibrary("Maven Embedder")
jetbrainsLibrary("tcServiceMessages")
jetbrainsLibrary("optimizedFileManager.jar")
jetbrainsLibrary("fernflower.jar")
@@ -4,6 +4,3 @@ org.jetbrains.idea.svn.*
org.jetbrains.idea.svn16.*
com.intellij.util.net.ssl.*
com.intellij.tasks.integration.live.*
[DECOMPILER_TESTS]
org.jetbrains.java.decompiler.*
+3 -9
View File
@@ -5,6 +5,9 @@
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/engine/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/engine/test" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/engine/out" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
@@ -13,15 +16,6 @@
<orderEntry type="module" module-name="java-psi-impl" />
<orderEntry type="module" module-name="util" />
<orderEntry type="module" module-name="testFramework-java" scope="TEST" />
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/lib/fernflower.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="library" name="asm5" level="project" />
</component>
</module>
Binary file not shown.
@@ -30,12 +30,12 @@ import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
import com.intellij.psi.compiled.ClassFileDecompilers;
import com.intellij.psi.impl.compiled.ClsFileImpl;
import com.intellij.util.containers.ContainerUtil;
import de.fernflower.main.decompiler.IdeDecompiler;
import de.fernflower.main.extern.IBytecodeProvider;
import de.fernflower.main.extern.IDecompilatSaver;
import de.fernflower.main.extern.IFernflowerLogger;
import de.fernflower.main.extern.IFernflowerPreferences;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.java.decompiler.main.decompiler.IdeDecompiler;
import org.jetbrains.java.decompiler.main.extern.IBytecodeProvider;
import org.jetbrains.java.decompiler.main.extern.IDecompilatSaver;
import org.jetbrains.java.decompiler.main.extern.IFernflowerLogger;
import org.jetbrains.java.decompiler.main.extern.IFernflowerPreferences;
import org.jetbrains.org.objectweb.asm.ClassReader;
import org.jetbrains.org.objectweb.asm.ClassVisitor;
import org.jetbrains.org.objectweb.asm.Opcodes;
@@ -51,10 +51,10 @@ public class IdeaDecompiler extends ClassFileDecompilers.Light {
private static final Logger LOG = Logger.getInstance(IdeaDecompiler.class);
private static final String BANNER =
"//\n" +
"// Source code recreated from a .class file by IntelliJ IDEA\n" +
"// (powered by Fernflower decompiler)\n" +
"//\n\n";
"//\n" +
"// Source code recreated from a .class file by IntelliJ IDEA\n" +
"// (powered by Fernflower decompiler)\n" +
"//\n\n";
private final IFernflowerLogger myLogger = new IdeaLogger();
private final HashMap<String, Object> myOptions = new HashMap<String, Object>();
@@ -16,7 +16,7 @@
package org.jetbrains.java.decompiler;
import com.intellij.openapi.diagnostic.Logger;
import de.fernflower.main.extern.IFernflowerLogger;
import org.jetbrains.java.decompiler.main.extern.IFernflowerLogger;
public class IdeaLogger implements IFernflowerLogger {
private final static Logger LOG = Logger.getInstance(IdeaDecompiler.class);
@@ -15,30 +15,32 @@
*/
package org.jetbrains.java.decompiler;
import com.intellij.openapi.application.PathManager;
import com.intellij.openapi.fileTypes.StdFileTypes;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.StandardFileSystems;
import com.intellij.openapi.vfs.VfsUtilCore;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.VirtualFileVisitor;
import com.intellij.psi.*;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.impl.compiled.ClsFileImpl;
import com.intellij.testFramework.PlatformTestUtil;
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.File;
import java.io.IOException;
public class IdeaDecompilerTest extends LightCodeInsightFixtureTestCase {
private static final String BANNER =
"//\n" +
"// Source code recreated from a .class file by IntelliJ IDEA\n" +
"// (powered by Fernflower decompiler)\n" +
"//\n\n";
public void testSimple() {
String path = PlatformTestUtil.getRtJarPath() + "!/java/lang/String.class";
VirtualFile file = StandardFileSystems.jar().findFileByPath(path);
assertNotNull(path, file);
String decompiled = new IdeaDecompiler().getText(file).toString();
assertTrue(decompiled.startsWith(BANNER + "package java.lang;\n"));
assertTrue(decompiled, decompiled.contains("public final class String"));
assertTrue(decompiled, decompiled.contains("@deprecated"));
assertTrue(decompiled, decompiled.contains("private static class CaseInsensitiveComparator"));
@@ -46,83 +48,29 @@ public class IdeaDecompilerTest extends LightCodeInsightFixtureTestCase {
assertFalse(decompiled, decompiled.contains("synthetic"));
}
public void testStubCompatibilityRt() {
String path = PlatformTestUtil.getRtJarPath() + "!/";
public void testStubCompatibility() {
String path = PlatformTestUtil.getRtJarPath() + "!/java";
VirtualFile dir = StandardFileSystems.jar().findFileByPath(path);
assertNotNull(path, dir);
doTestStubCompatibility(dir);
}
public void testStubCompatibilityIdea() {
String path = PathManager.getHomePath() + "/out/production";
if (!new File(path).exists()) path = PathManager.getHomePath() + "/out/classes/production";
VirtualFile dir = StandardFileSystems.local().refreshAndFindFileByPath(path);
assertNotNull(path, dir);
doTestStubCompatibility(dir);
}
private void doTestStubCompatibility(VirtualFile root) {
doTestStubCompatibility(root, null);
}
private void doTestStubCompatibility(VirtualFile root, @Nullable final String textPath) {
final int pathStart = root.getPath().length();
final boolean compare = textPath != null && new File(textPath).exists();
VfsUtilCore.visitChildrenRecursively(root, new VirtualFileVisitor() {
@Override
public boolean visitFile(@NotNull VirtualFile file) {
if (!file.isDirectory() && file.getFileType() == StdFileTypes.CLASS && !file.getName().contains("$")) {
if (file.isDirectory()) {
System.out.println(file.getPath());
}
else if (file.getFileType() == StdFileTypes.CLASS && !file.getName().contains("$")) {
PsiFile clsFile = getPsiManager().findFile(file);
assertNotNull(file.getPath(), clsFile);
PsiElement mirror = ((ClsFileImpl)clsFile).getMirror().copy();
if (textPath != null) {
collapseCodeBlocks(mirror);
}
PsiElement mirror = ((ClsFileImpl)clsFile).getMirror();
String decompiled = mirror.getText();
assertTrue(file.getPath(), decompiled.contains(file.getNameWithoutExtension()));
if (textPath != null) {
try {
File txtFile = new File(textPath, file.getPath().substring(pathStart));
if (!compare) {
FileUtil.writeToFile(txtFile, decompiled.getBytes("UTF-8"));
}
else {
String expected = FileUtil.loadFile(txtFile, "UTF-8");
assertEquals(file.getPath(), expected, decompiled);
}
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
}
return true;
}
});
}
private static void collapseCodeBlocks(PsiElement original) {
final PsiElementFactory factory = PsiElementFactory.SERVICE.getInstance(original.getProject());
original.accept(new JavaRecursiveElementWalkingVisitor() {
@Override
public void visitMethod(PsiMethod method) {
PsiCodeBlock body = method.getBody();
if (body != null) {
body.replace(factory.createCodeBlockFromText("{ /* collapsed */}", null));
}
}
@Override
public void visitClass(PsiClass aClass) {
for (PsiClassInitializer initializer : aClass.getInitializers()) {
PsiCodeBlock body = initializer.getBody();
body.replace(factory.createCodeBlockFromText("{ /* collapsed */}", null));
}
super.visitClass(aClass);
}
});
}
}