Search in sources :

Example 1 with Atoms

use of org.elixir_lang.beam.chunk.Atoms in project intellij-elixir by KronicDeth.

the class BeamTest method elixirModule.

@Test
public void elixirModule() throws IOException, OtpErlangDecodeException {
    Beam beam = beam("Elixir.Kernel");
    assertNotNull(beam);
    Atoms atoms = beam.atoms();
    assertNotNull(atoms);
    assertEquals("Elixir.Kernel", atoms.moduleName());
    Exports exports = beam.exports();
    assertNotNull(exports);
    int exportCount = exports.size();
    assertTrue("There are no exports", exportCount > 0);
    SortedSet<MacroNameArity> macroNameAritySortedSet = exports.macroNameAritySortedSet(atoms);
    assertEquals("There are nameless exports", exportCount, macroNameAritySortedSet.size());
    List<MacroNameArity> nodes = ContainerUtil.filter(macroNameAritySortedSet, new Condition<MacroNameArity>() {

        @Override
        public boolean value(MacroNameArity macroNameArity) {
            return "node".equals(macroNameArity.name);
        }
    });
    assertEquals(nodes.size(), 2);
    assertEquals(0, (int) nodes.get(0).arity);
    assertEquals(1, (int) nodes.get(1).arity);
}
Also used : Atoms(org.elixir_lang.beam.chunk.Atoms) Exports(org.elixir_lang.beam.chunk.Exports) Test(org.junit.Test)

Example 2 with Atoms

use of org.elixir_lang.beam.chunk.Atoms in project intellij-elixir by KronicDeth.

the class BeamTest method erlangModule.

@Test
public void erlangModule() throws IOException, OtpErlangDecodeException {
    Beam beam = beam("elixir_interpolation");
    assertNotNull(beam);
    Atoms atoms = beam.atoms();
    assertNotNull(atoms);
    assertEquals("elixir_interpolation", atoms.moduleName());
    Exports exports = beam.exports();
    assertNotNull(exports);
    int exportCount = exports.size();
    assertTrue("There are no exports", exportCount > 0);
    SortedSet<MacroNameArity> macroNameAritySortedSet = exports.macroNameAritySortedSet(atoms);
    assertEquals("There are nameless exports", exportCount, macroNameAritySortedSet.size());
    List<MacroNameArity> extracts = ContainerUtil.filter(macroNameAritySortedSet, new Condition<MacroNameArity>() {

        @Override
        public boolean value(MacroNameArity macroNameArity) {
            return "extract".equals(macroNameArity.name);
        }
    });
    assertEquals(1, extracts.size());
    assertEquals(6, (int) extracts.get(0).arity);
}
Also used : Atoms(org.elixir_lang.beam.chunk.Atoms) Exports(org.elixir_lang.beam.chunk.Exports) Test(org.junit.Test)

Example 3 with Atoms

use of org.elixir_lang.beam.chunk.Atoms in project intellij-elixir by KronicDeth.

the class Decompiler method decompiled.

@NotNull
private static CharSequence decompiled(@Nullable Beam beam) {
    StringBuilder decompiled = new StringBuilder("Decompilated Error");
    if (beam != null) {
        Atoms atoms = beam.atoms();
        if (atoms != null) {
            String moduleName = atoms.moduleName();
            if (moduleName != null) {
                String defmoduleArgument = defmoduleArgument(moduleName);
                decompiled = new StringBuilder("# Source code recreated from a .beam file by IntelliJ Elixir\n").append("defmodule ").append(defmoduleArgument).append(" do\n");
                appendExports(decompiled, beam, atoms);
                decompiled.append("end\n");
            }
        }
    }
    return decompiled;
}
Also used : Atoms(org.elixir_lang.beam.chunk.Atoms) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with Atoms

use of org.elixir_lang.beam.chunk.Atoms in project intellij-elixir by KronicDeth.

the class BeamFileImpl method buildModuleStub.

@Nullable
private static ModuleStub buildModuleStub(PsiFileStub<ElixirFile> parentStub, Beam beam) {
    ModuleStub moduleStub = null;
    if (beam != null) {
        Atoms atoms = beam.atoms();
        if (atoms != null) {
            String moduleName = atoms.moduleName();
            if (moduleName != null) {
                String name = defmoduleArgument(moduleName);
                moduleStub = new ModuleStubImpl(parentStub, name);
                buildCallDefinitions(moduleStub, beam, atoms);
            }
        }
    }
    return moduleStub;
}
Also used : ModuleStubImpl(org.elixir_lang.beam.psi.impl.ModuleStubImpl) Atoms(org.elixir_lang.beam.chunk.Atoms) ModuleStub(org.elixir_lang.beam.psi.stubs.ModuleStub) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with Atoms

use of org.elixir_lang.beam.chunk.Atoms in project intellij-elixir by KronicDeth.

the class Beam method atoms.

/*
     * Instance Methods
     */
@Nullable
public Atoms atoms() {
    Atoms atoms = null;
    Chunk chunk = chunk(ATOM);
    if (chunk != null) {
        atoms = Atoms.from(chunk);
    }
    return atoms;
}
Also used : Atoms(org.elixir_lang.beam.chunk.Atoms) Chunk(org.elixir_lang.beam.chunk.Chunk) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

Atoms (org.elixir_lang.beam.chunk.Atoms)5 Exports (org.elixir_lang.beam.chunk.Exports)2 Nullable (org.jetbrains.annotations.Nullable)2 Test (org.junit.Test)2 Chunk (org.elixir_lang.beam.chunk.Chunk)1 ModuleStubImpl (org.elixir_lang.beam.psi.impl.ModuleStubImpl)1 ModuleStub (org.elixir_lang.beam.psi.stubs.ModuleStub)1 NotNull (org.jetbrains.annotations.NotNull)1