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

2022-09-04 01:59:20

我想看看从我自己的来源生成的代码,但似乎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并将其添加到某个模块中,但它看起来不像一个正常的解决方案。

我可以让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>

答案 1

在我的情况下,问题是我已经安装了“Java Decompiler IntelliJ插件”。Unistall 它使工作。


答案 2

我遇到了同样的问题,但我用Kotlin编写。我已经通过安装插件解决了这个问题。请执行下列操作:Kotlin to Java decompiler

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

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


推荐