Permalink
Browse files

Go To Symbol for decompiled functions and macros

  • Loading branch information...
1 parent 7036207 commit 0b602e7b478d24abe8d2ef0c178fccab823d2ad4 @KronicDeth committed Jan 1, 2017
@@ -6,4 +6,4 @@
<JAVADOC />
<SOURCES />
</library>
-</component>
+</component>
@@ -29,6 +29,11 @@
@NotNull
Set<String> canonicalNameSet();
+ int exportedArity();
+
+ @Nullable
+ String exportedName();
+
@Nullable
String functionName();
@@ -40,6 +45,8 @@
boolean hasDoBlockOrKeyword();
+ boolean isExported();
+
@Nullable
String getName();
@@ -32,6 +32,11 @@
@NotNull
Set<String> canonicalNameSet();
+ int exportedArity();
+
+ @Nullable
+ String exportedName();
+
@Nullable
String functionName();
@@ -40,6 +45,8 @@
boolean hasDoBlockOrKeyword();
+ boolean isExported();
+
@Nullable
String getName();
@@ -60,6 +60,15 @@ public String canonicalName() {
return ElixirPsiImplUtil.canonicalNameSet(this);
}
+ public int exportedArity() {
+ return ElixirPsiImplUtil.exportedArity(this);
+ }
+
+ @Nullable
+ public String exportedName() {
+ return ElixirPsiImplUtil.exportedName(this);
+ }
+
@Nullable
public String functionName() {
return ElixirPsiImplUtil.functionName(this);
@@ -79,6 +88,10 @@ public boolean hasDoBlockOrKeyword() {
return ElixirPsiImplUtil.hasDoBlockOrKeyword(this);
}
+ public boolean isExported() {
+ return ElixirPsiImplUtil.isExported(this);
+ }
+
@Nullable
public String getName() {
return ElixirPsiImplUtil.getName(this);
@@ -66,6 +66,15 @@ public String canonicalName() {
return ElixirPsiImplUtil.canonicalNameSet(this);
}
+ public int exportedArity() {
+ return ElixirPsiImplUtil.exportedArity(this);
+ }
+
+ @Nullable
+ public String exportedName() {
+ return ElixirPsiImplUtil.exportedName(this);
+ }
+
@Nullable
public String functionName() {
return ElixirPsiImplUtil.functionName(this);
@@ -80,6 +89,10 @@ public boolean hasDoBlockOrKeyword() {
return ElixirPsiImplUtil.hasDoBlockOrKeyword(this);
}
+ public boolean isExported() {
+ return ElixirPsiImplUtil.isExported(this);
+ }
+
@Nullable
public String getName() {
return ElixirPsiImplUtil.getName(this);
@@ -1828,6 +1828,38 @@ matchedUnqualifiedNoParenthesesCall ::= identifier noParenthesesOneArgument
"org.elixir_lang.psi.MatchedCall"
"org.elixir_lang.psi.UnqualifiedNoParenthesesCall<org.elixir_lang.psi.stub.MatchedUnqualifiedNoParenthesesCall>"
]
+ methods = [
+ canonicalName
+ canonicalNameSet
+ exportedArity
+ exportedName
+ functionName
+ functionNameElement
+ getDoBlock
+ hasDoBlockOrKeyword
+ isExported
+ getName
+ getNameIdentifier
+ getPresentation
+ getReference
+ getStub
+ getUseScope
+ isCalling
+ isCallingMacro
+ moduleName
+ primaryArguments
+ primaryArity
+ processDeclarations
+ quote
+ resolvedFinalArity
+ resolvedFinalArityRange
+ resolvedModuleName
+ resolvedPrimaryArity
+ resolvedSecondaryArity
+ secondaryArguments
+ secondaryArity
+ setName
+ ]
mixin = "org.elixir_lang.psi.impl.NamedStubbedPsiElementBase<org.elixir_lang.psi.stub.MatchedUnqualifiedNoParenthesesCall>"
stubClass = "org.elixir_lang.psi.stub.MatchedUnqualifiedNoParenthesesCall"
}
@@ -2570,6 +2602,38 @@ unmatchedAtUnqualifiedNoParenthesesCall ::= atIdentifier noParenthesesOneArgumen
unmatchedUnqualifiedNoParenthesesCall ::= identifier noParenthesesOneArgument doBlock?
{
implements = "org.elixir_lang.psi.UnqualifiedNoParenthesesCall<org.elixir_lang.psi.stub.UnmatchedUnqualifiedNoParenthesesCall>"
+ methods = [
+ canonicalName
+ canonicalNameSet
+ exportedArity
+ exportedName
+ functionName
+ functionNameElement
+ getDoBlock
+ hasDoBlockOrKeyword
+ isExported
+ getName
+ getNameIdentifier
+ getPresentation
+ getReference
+ getStub
+ getUseScope
+ isCalling
+ isCallingMacro
+ moduleName
+ primaryArguments
+ primaryArity
+ processDeclarations
+ quote
+ resolvedFinalArity
+ resolvedFinalArityRange
+ resolvedModuleName
+ resolvedPrimaryArity
+ resolvedSecondaryArity
+ secondaryArguments
+ secondaryArity
+ setName
+ ]
mixin = "org.elixir_lang.psi.impl.NamedStubbedPsiElementBase<org.elixir_lang.psi.stub.UnmatchedUnqualifiedNoParenthesesCall>"
stubClass="org.elixir_lang.psi.stub.UnmatchedUnqualifiedNoParenthesesCall"
}
@@ -124,7 +124,7 @@ public static String defmoduleArgument(String moduleName) {
@Contract(pure = true)
@NotNull
- private static Pair<String, String> macroArgument(@NotNull String name) {
+ public static Pair<String, String> macroArgument(@NotNull String name) {
String argument = name;
String macro = DEF;
@@ -10,6 +10,7 @@
import com.intellij.openapi.fileTypes.FileType;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.util.Key;
+import com.intellij.openapi.util.Pair;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.*;
import com.intellij.psi.impl.source.PsiFileImpl;
@@ -27,10 +28,15 @@
import com.intellij.util.IncorrectOperationException;
import org.elixir_lang.ElixirLanguage;
import org.elixir_lang.beam.Beam;
+import org.elixir_lang.beam.Decompiler;
import org.elixir_lang.beam.chunk.Atoms;
+import org.elixir_lang.beam.chunk.Exports;
+import org.elixir_lang.beam.chunk.exports.Export;
import org.elixir_lang.beam.psi.impl.ModuleElementImpl;
import org.elixir_lang.beam.psi.impl.ModuleImpl;
import org.elixir_lang.beam.psi.impl.ModuleStubImpl;
+import org.elixir_lang.beam.psi.impl.CallDefinitionStubImpl;
+import org.elixir_lang.beam.psi.stubs.CallDefinitionStub;
import org.elixir_lang.beam.psi.stubs.ModuleStub;
import org.elixir_lang.psi.ElixirFile;
import org.elixir_lang.psi.ModuleOwner;
@@ -42,6 +48,8 @@
import java.io.IOException;
import java.util.List;
+import java.util.SortedMap;
+import java.util.SortedSet;
import static com.intellij.reference.SoftReference.dereference;
import static org.elixir_lang.beam.Decompiler.defmoduleArgument;
@@ -89,6 +97,17 @@ private BeamFileImpl(@NotNull FileViewProvider fileViewProvider, boolean isForDe
LOGGER.error(e);
}
+ ModuleStub moduleStub = buildModuleStub(stub, beam);
+
+ if (moduleStub == null) {
+ stub = null;
+ }
+
+ return stub;
+ }
+
+ @Nullable
+ private static ModuleStub buildModuleStub(PsiFileStub<ElixirFile> parentStub, Beam beam) {
ModuleStub moduleStub = null;
if (beam != null) {
@@ -99,16 +118,53 @@ private BeamFileImpl(@NotNull FileViewProvider fileViewProvider, boolean isForDe
if (moduleName != null) {
String name = defmoduleArgument(moduleName);
- moduleStub = new ModuleStubImpl(stub, name);
+ moduleStub = new ModuleStubImpl(parentStub, name);
+
+ buildCallDefinitions(moduleStub, beam, atoms);
}
}
}
- if (moduleStub == null) {
- stub = null;
+ return moduleStub;
+ }
+
+ private static void buildCallDefinitions(@NotNull ModuleStub parentStub, @NotNull Beam beam, @NotNull Atoms atoms) {
+ Exports exports = beam.exports();
+
+ if (exports != null) {
+ Pair<SortedMap<String, SortedMap<Integer, Export>>, SortedSet<Export>>
+ exportByArityByNameNamelessExports = exports.exportByArityByName(atoms);
+
+ SortedMap<String, SortedMap<Integer, Export>> exportByArityByName =
+ exportByArityByNameNamelessExports.first;
+
+ for (SortedMap.Entry<String, SortedMap<Integer, Export>> nameExportByArity :
+ exportByArityByName.entrySet()) {
+ String name = nameExportByArity.getKey();
+ Pair<String, String> macroArgument = Decompiler.macroArgument(name);
+
+ SortedMap<Integer, Export> exportByArity = nameExportByArity.getValue();
+
+ for (SortedMap.Entry<Integer, Export> arityExport : exportByArity.entrySet()) {
+ buildCallDefinition(parentStub, macroArgument, arityExport.getKey());
+ }
+ }
}
+ }
- return stub;
+ @NotNull
+ private static CallDefinitionStub buildCallDefinition(@NotNull ModuleStub parentStub,
+ @NotNull Pair<String, String> macroArgument,
+ int arity) {
+ return buildCallDefinition(parentStub, macroArgument.first, macroArgument.second, arity);
+ }
+
+ @NotNull
+ private static CallDefinitionStub buildCallDefinition(@NotNull ModuleStub parentStub,
+ @NotNull String macro,
+ @NotNull String name,
+ int arity) {
+ return new CallDefinitionStubImpl(parentStub, macro, name, arity);
}
@Override
@@ -0,0 +1,9 @@
+package org.elixir_lang.beam.psi;
+
+import com.intellij.psi.PsiCompiledElement;
+import org.elixir_lang.psi.NamedElement;
+import org.elixir_lang.psi.call.CanonicallyNamed;
+import org.elixir_lang.psi.call.MaybeExported;
+
+public interface CallDefinition extends CanonicallyNamed, MaybeExported, NamedElement, PsiCompiledElement {
+}
@@ -0,0 +1,11 @@
+package org.elixir_lang.beam.psi;
+
+import com.intellij.psi.impl.source.tree.CompositeElement;
+import com.intellij.psi.tree.IElementType;
+import org.jetbrains.annotations.NotNull;
+
+public class CallDefinitionElement extends CompositeElement {
+ public CallDefinitionElement(@NotNull IElementType type) {
+ super(type);
+ }
+}
Oops, something went wrong.

0 comments on commit 0b602e7

Please sign in to comment.