Parsing decompiled source using target language's extensions


I'm able to decompile the .beam files used on the Erlang BEAM VM to faked Elixir code, using


<filetype.decompiler filetype="BEAM" implementationClass="org.elixir_lang.beam.Decompiler"/>


but, the text is shown as just plain text.  How do I get the editor tab to highlight and annotate the code from the decompiler so it works like normal Elixir code from .ex and .exs files?  I'd also like to index the decompiled code so that I can do Go To Declaration to the decompiled modules and functions in those modules.

Comment actions Permalink

For basic highlighting, you need to implement `SyntaxHighlighterProvider` and register it via `syntaxHighlighter` EP.

Comment actions Permalink

For indexing, there is `FileBasedIndexExtension` (EP: `fileBasedIndex`). But to make "Go To Declaration" work you will need to change existing resolve code to look into the index.

Comment actions Permalink

I have the syntax highlighting working using the syntax highlighter, but as you probably know, the syntax highlighter only handles highlighting lexer tokens.

<syntaxHighlighter key="BEAM" factoryClass="org.elixir_lang.ElixirSyntaxHighlighterFactory"/>

To get full highlighting on normal source files I have a bunch of annotators, but the problem is that the annotator extensions expect a `language` attribute and the compiled .beam files don't have a language since it's a binary format (so a FileType, but not a LanguageFileType).  

How do I use these annotators

<annotator implementationClass="org.elixir_lang.annonator.Alias" language="Elixir"/>
<annotator implementationClass="org.elixir_lang.annonator.Atom" language="Elixir"/>
<annotator implementationClass="org.elixir_lang.annonator.Callable" language="Elixir"/>
<annotator implementationClass="org.elixir_lang.annonator.EscapeSequence" language="Elixir"/>
<annotator implementationClass="org.elixir_lang.annonator.Kernel" language="Elixir"/>
<annotator implementationClass="org.elixir_lang.annonator.Map" language="Elixir"/>
<annotator implementationClass="org.elixir_lang.annonator.ModuleAttribute" language="Elixir"/>

against the decompiled source?


I ended up using the "mirror" system that Java .class decompilation uses, so I was able to reuse the structure view from the normal source files, by asking the compiled BeamFileImpl for it's mirror, which gave me a normal ElixirFile like a normal source file.

<structureViewBuilder key="BEAM" factoryClass="org.elixir_lang.beam.StructureViewBuilderProvider"/>

 Can I leverage the mirror system for annotators?



Comment actions Permalink

Sorry, don't have a ready answer. AFAIK annotators are invoked by `GeneralHighlightingPass`, and IDEA omits certain passes for binary files (see `TextEditorBackgroundHighlighter.getPasses()`).

You may try to register a custom highlighting pass for BEAM files and make it call existing annotators.


Please sign in to leave a comment.