IDEA 14.反编译我自己的类(从输出目录)

时间:2015-02-09 00:10:07

标签: java intellij-idea decompiling

我想查看从我自己的源代码生成的代码,但似乎IDEA没有使用 IntelliJ API Decompiler 使用新的fernflower插件对它们进行反编译。

至少我有标题评论

// IntelliJ API Decompiler stub source generated from a class file
// Implementation of methods is not available

和类似的方法:public void update() { /* compiled code */ }

同时,在外部库(例如JDK)中,我看到了正常的标题和反编译代码。

// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)

我可以使反编译工作,如果我将代码编译到jar并将其添加到某个模块,但它看起来不像普通的解决方案。

我可以使用fernflower使IDEA对任何类文件进行反编译吗?

编辑:在打开文件时,我在IDEA日志文件中遇到异常。请参阅代码段。

<pre>
2015-02-13 19:16:29,991 [119281666]   WARN - l.compiled.ClassFileDecompiler - decompiler: class org.jetbrains.java.decompiler.IdeaDecompiler
com.intellij.psi.compiled.ClassFileDecompilers$Light$CannotDecompileException: org.jetbrains.java.decompiler.IdeaLogger$InternalException: Method <init> (Ljava/util/HashMap;)V couldn't be decompiled.
	at org.jetbrains.java.decompiler.IdeaDecompiler.getText(IdeaDecompiler.java:162)
	at com.intellij.psi.impl.compiled.ClassFileDecompiler.decompile(ClassFileDecompiler.java:57)
	at com.intellij.openapi.fileEditor.impl.LoadTextUtil.loadText(LoadTextUtil.java:364)
	at com.intellij.openapi.fileEditor.impl.FileDocumentManagerImpl.getDocument(FileDocumentManagerImpl.java:167)
	at com.intellij.openapi.fileEditor.impl.text.PsiAwareTextEditorProvider.createEditorAsync(PsiAwareTextEditorProvider.java:58)
	at com.intellij.openapi.fileEditor.impl.FileEditorManagerImpl.openFileImpl4(FileEditorManagerImpl.java:778)
	at com.intellij.openapi.fileEditor.impl.FileEditorManagerImpl.openFileImpl3(FileEditorManagerImpl.java:736)
	at com.intellij.openapi.fileEditor.impl.FileEditorManagerImpl$8.run(FileEditorManagerImpl.java:716)
	at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:117)
	at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:99)
	at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:85)
	at com.intellij.openapi.fileEditor.impl.FileEditorManagerImpl.openFileImpl2(FileEditorManagerImpl.java:713)
	at com.intellij.openapi.fileEditor.impl.FileEditorManagerImpl.openFileWithProviders(FileEditorManagerImpl.java:654)
	at com.intellij.openapi.fileEditor.ex.FileEditorManagerEx.openFile(FileEditorManagerEx.java:146)
	at com.intellij.openapi.fileEditor.impl.FileEditorManagerImpl$14.run(FileEditorManagerImpl.java:1071)
	at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:124)
	at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:99)
	at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:85)
	at com.intellij.openapi.fileEditor.impl.FileEditorManagerImpl.openEditor(FileEditorManagerImpl.java:1067)
	at com.intellij.openapi.fileEditor.OpenFileDescriptor.navigateInAnyFileEditor(OpenFileDescriptor.java:152)
	at com.intellij.openapi.fileEditor.OpenFileDescriptor.navigateInEditor(OpenFileDescriptor.java:138)
	at com.intellij.openapi.fileEditor.OpenFileDescriptor.navigateInEditorOrNativeApp(OpenFileDescriptor.java:134)
	at com.intellij.openapi.fileEditor.OpenFileDescriptor.navigate(OpenFileDescriptor.java:121)
	at com.intellij.psi.impl.PsiElementBase.navigate(PsiElementBase.java:197)
	at com.intellij.codeInsight.navigation.NavigationUtil.openFileWithPsiElement(NavigationUtil.java:167)
	at com.intellij.ide.projectView.impl.nodes.AbstractPsiBasedNode.navigate(AbstractPsiBasedNode.java:207)
	at com.intellij.ide.projectView.impl.nodes.AbstractPsiBasedNode.navigate(AbstractPsiBasedNode.java:217)
	at com.intellij.ide.projectView.impl.nodes.PsiFileNode.navigate(PsiFileNode.java:132)
	at com.intellij.util.OpenSourceUtil.navigate(OpenSourceUtil.java:53)
	at com.intellij.util.OpenSourceUtil.openSourcesFrom(OpenSourceUtil.java:31)
	at com.intellij.util.EditSourceOnDoubleClickHandler$TreeMouseListener.processDoubleClick(EditSourceOnDoubleClickHandler.java:130)
	at com.intellij.util.EditSourceOnDoubleClickHandler$TreeMouseListener.onDoubleClick(EditSourceOnDoubleClickHandler.java:122)
	at com.intellij.ui.DoubleClickListener.onClick(DoubleClickListener.java:30)
	at com.intellij.ui.ClickListener$1.mouseReleased(ClickListener.java:73)
	at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:273)
	at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:272)
	at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:272)
	at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:272)
	at java.awt.Component.processMouseEvent(Component.java:6414)
	at javax.swing.JComponent.processMouseEvent(JComponent.java:3275)
	at com.intellij.ui.treeStructure.Tree.processMouseEvent(Tree.java:421)
	at com.intellij.ide.dnd.aware.DnDAwareTree.processMouseEvent(DnDAwareTree.java:53)
	at java.awt.Component.processEvent(Component.java:6179)
	at java.awt.Container.processEvent(Container.java:2084)
	at java.awt.Component.dispatchEventImpl(Component.java:4776)
	at java.awt.Container.dispatchEventImpl(Container.java:2142)
	at java.awt.Component.dispatchEvent(Component.java:4604)
	at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4618)
	at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4279)
	at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4209)
	at java.awt.Container.dispatchEventImpl(Container.java:2128)
	at java.awt.Window.dispatchEventImpl(Window.java:2492)
	at java.awt.Component.dispatchEvent(Component.java:4604)
	at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:717)
	at java.awt.EventQueue.access$400(EventQueue.java:82)
	at java.awt.EventQueue$2.run(EventQueue.java:676)
	at java.awt.EventQueue$2.run(EventQueue.java:674)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:86)
	at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:97)
	at java.awt.EventQueue$3.run(EventQueue.java:690)
	at java.awt.EventQueue$3.run(EventQueue.java:688)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:86)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:687)
	at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:748)
	at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:573)
	at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:384)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:296)
	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:211)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:201)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:196)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:188)
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
Caused by: org.jetbrains.java.decompiler.IdeaLogger$InternalException: Method <init> (Ljava/util/HashMap;)V couldn't be decompiled.
	at org.jetbrains.java.decompiler.IdeaLogger.writeMessage(IdeaLogger.java:44)
	at org.jetbrains.java.decompiler.main.rels.ClassWrapper.init(ClassWrapper.java:151)
	at org.jetbrains.java.decompiler.main.ClassesProcessor.initWrappers(ClassesProcessor.java:305)
	at org.jetbrains.java.decompiler.main.ClassesProcessor.writeClass(ClassesProcessor.java:252)
	at org.jetbrains.java.decompiler.main.Fernflower.getClassContent(Fernflower.java:86)
	at org.jetbrains.java.decompiler.struct.ContextUnit.save(ContextUnit.java:113)
	at org.jetbrains.java.decompiler.struct.StructContext.saveContext(StructContext.java:72)
	at org.jetbrains.java.decompiler.main.Fernflower.decompileContext(Fernflower.java:54)
	at org.jetbrains.java.decompiler.main.decompiler.BaseDecompiler.decompileContext(BaseDecompiler.java:41)
	at org.jetbrains.java.decompiler.IdeaDecompiler.getText(IdeaDecompiler.java:151)
	... 73 more
Caused by: java.lang.ClassCastException: org.jetbrains.java.decompiler.struct.consts.PrimitiveConstant cannot be cast to org.jetbrains.java.decompiler.struct.consts.LinkConstant
	at org.jetbrains.java.decompiler.modules.decompiler.ExprProcessor.processBlock(ExprProcessor.java:563)
	at org.jetbrains.java.decompiler.modules.decompiler.ExprProcessor.processStatement(ExprProcessor.java:202)
	at org.jetbrains.java.decompiler.main.rels.MethodProcessorThread.codeToJava(MethodProcessorThread.java:162)
	at org.jetbrains.java.decompiler.main.rels.ClassWrapper.init(ClassWrapper.java:92)
	... 81 more
</pre>

2 个答案:

答案 0 :(得分:8)

在我的情况下,问题是我安装了“Java Decompiler IntelliJ Plugin”。 Unistall它可以完成这项工作。

答案 1 :(得分:1)

我遇到了同样的问题,但是我用科特林写作。我已经通过安装Kotlin to Java decompiler插件解决了。请执行以下操作:

  1. Ctrl + Alt + S打开设置。
  2. 插件->市场->输入Kotlin to Java decompiler
  3. 安装插件并重新启动IntelliJ IDEA。
  4. 构建项目以生成.class个文件。
  5. 在打开的Ctrl + Shift + Alt + D.kt文件中按.class,以查看其反编译的Java代码。

UPD。另外,您也可以在没有插件的情况下将Kotlin反编译为Java。 转到Tools-> Kotlin-> Show Kotlin bytecode。在打开的选项卡中,单击Decompile按钮。但是无论如何,该插件更方便。 :)