Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Go To Symbol #257

Merged
merged 11 commits into from
Mar 19, 2016
Prev Previous commit
Next Next commit
Go To Symbol for CallDefinitionSpecification
Go To Symbol should work for all `@spec`.
  • Loading branch information
KronicDeth committed Mar 19, 2016
commit 2f94e2e70a33aad1f969b108445de2765b00fb7c
23 changes: 19 additions & 4 deletions src/org/elixir_lang/navigation/GotoSymbolContributor.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@
import com.intellij.util.ArrayUtil;
import com.intellij.util.containers.ContainerUtil;
import org.apache.commons.lang.math.IntRange;
import org.elixir_lang.psi.AtUnqualifiedNoParenthesesCall;
import org.elixir_lang.psi.NamedElement;
import org.elixir_lang.psi.call.Call;
import org.elixir_lang.psi.stub.index.AllName;
import org.elixir_lang.structure_view.element.CallDefinition;
import org.elixir_lang.structure_view.element.CallDefinitionClause;
import org.elixir_lang.structure_view.element.Callback;
import org.elixir_lang.structure_view.element.Timed;
import org.elixir_lang.structure_view.element.*;
import org.elixir_lang.structure_view.element.modular.Modular;
import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -102,6 +100,23 @@ public NavigationItem[] getItemsByName(String name,
items.add(callDefinitionClause);
}
}
} else if (CallDefinitionSpecification.is(call)) {
Modular modular = enclosingModularByCall.putNew(call);

assert modular != null;

// pseudo-named-arguments
boolean callback = false;
Timed.Time time = Timed.Time.RUN;

//noinspection ConstantConditions
CallDefinitionSpecification callDefinitionSpecification = new CallDefinitionSpecification(
modular,
(AtUnqualifiedNoParenthesesCall) call,
callback,
time
);
items.add(callDefinitionSpecification);
} else if (Callback.is(call)) {
Modular modular = enclosingModularByCall.putNew(call);

Expand Down
4 changes: 3 additions & 1 deletion src/org/elixir_lang/psi/impl/ElixirPsiImplUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import com.intellij.psi.*;
import com.intellij.psi.impl.source.tree.Factory;
import com.intellij.psi.scope.PsiScopeProcessor;
import com.intellij.psi.stubs.StubElement;
import com.intellij.psi.tree.IElementType;
import com.intellij.psi.tree.TokenSet;
import com.intellij.psi.util.PsiTreeUtil;
Expand All @@ -31,6 +30,7 @@
import org.elixir_lang.psi.qualification.Unqualified;
import org.elixir_lang.psi.stub.call.Stub;
import org.elixir_lang.structure_view.element.CallDefinitionClause;
import org.elixir_lang.structure_view.element.CallDefinitionSpecification;
import org.elixir_lang.structure_view.element.Callback;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -2055,6 +2055,8 @@ public static PsiElement getNameIdentifier(
nameIdentifier = operation.operator();
} else if (CallDefinitionClause.is(named)) {
nameIdentifier = CallDefinitionClause.nameIdentifier(named);
} else if (CallDefinitionSpecification.is(named)) {
nameIdentifier = CallDefinitionSpecification.nameIdentifier(named);
} else if (Callback.is(named)) {
nameIdentifier = Callback.nameIdentifier(named);
} else if (named instanceof AtUnqualifiedNoParenthesesCall) { // module attribute
Expand Down
2 changes: 2 additions & 0 deletions src/org/elixir_lang/psi/stub/type/call/Stub.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.intellij.psi.stubs.StubOutputStream;
import org.elixir_lang.psi.call.Call;
import org.elixir_lang.structure_view.element.CallDefinitionClause;
import org.elixir_lang.structure_view.element.CallDefinitionSpecification;
import org.elixir_lang.structure_view.element.Callback;
import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -39,6 +40,7 @@ public boolean shouldCreateStub(ASTNode node) {

// TODO do reset of isSuitable
return (CallDefinitionClause.is(call) ||
CallDefinitionSpecification.is(call) ||
// skip CallDefinitionHead because it is covered by CallDefinitionClause
Callback.is(call)) &&
// if it doesn't have a name then it can't be searched for, so there's no reason to stub it.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ public void specification(AtUnqualifiedNoParenthesesCall moduleAttributeDefiniti
boolean callback = false;
Timed.Time time = Time.RUN;

//noinspection ConstantConditions
CallDefinitionSpecification callDefinitionSpecification = new CallDefinitionSpecification(
modular,
moduleAttributeDefinition,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,40 @@ public static Pair<String, Integer> moduleAttributeNameArity(AtUnqualifiedNoPare
return nameArity;
}

@Nullable
public static Pair<String, Integer> moduleAttributeNameArity(Call call) {
Pair<String, Integer> nameArity = null;

if (call instanceof AtUnqualifiedNoParenthesesCall) {
nameArity = moduleAttributeNameArity((AtUnqualifiedNoParenthesesCall) call);
}

return nameArity;
}

@Nullable
public static PsiElement nameIdentifier(AtUnqualifiedNoParenthesesCall atUnqualifiedNoParenthesesCall) {
Call specification = specification(atUnqualifiedNoParenthesesCall);
PsiElement nameIdentifier = null;

if (specification != null) {
nameIdentifier = specificationNameIdentifier(specification);
}

return nameIdentifier;
}

@Nullable
public static PsiElement nameIdentifier(Call call) {
PsiElement nameIdentifier = null;

if (call instanceof AtUnqualifiedNoParenthesesCall) {
nameIdentifier = nameIdentifier((AtUnqualifiedNoParenthesesCall) call);
}

return nameIdentifier;
}

@Nullable
public static Call specification(AtUnqualifiedNoParenthesesCall atUnqualifiedNoParenthesesCall) {
PsiElement[] arguments = atUnqualifiedNoParenthesesCall.getNoParenthesesOneArgument().arguments();
Expand All @@ -80,30 +114,31 @@ public static Call specification(AtUnqualifiedNoParenthesesCall atUnqualifiedNoP
}

@Nullable
public static Pair<String, Integer> moduleAttributeNameArity(Call call) {
public static Pair<String, Integer> specificationNameArity(Call specification) {
Pair<String, Integer> nameArity = null;

if (call instanceof AtUnqualifiedNoParenthesesCall) {
nameArity = moduleAttributeNameArity((AtUnqualifiedNoParenthesesCall) call);
if (specification instanceof ElixirMatchedTypeOperation) {
nameArity = typeNameArity((ElixirMatchedTypeOperation) specification);
} else if (specification instanceof ElixirMatchedWhenOperation) {
nameArity = typeNameArity((ElixirMatchedWhenOperation) specification);
}

return nameArity;
}

@Nullable
public static Pair<String, Integer> specificationNameArity(Call specification) {
Pair<String, Integer> nameArity = null;
public static PsiElement specificationNameIdentifier(Call specification) {
PsiElement nameIdentifier = null;

if (specification instanceof ElixirMatchedTypeOperation) {
nameArity = typeNameArity((ElixirMatchedTypeOperation) specification);
nameIdentifier = typeNameIdentifier((ElixirMatchedTypeOperation) specification);
} else if (specification instanceof ElixirMatchedWhenOperation) {
nameArity = typeNameArity((ElixirMatchedWhenOperation) specification);
nameIdentifier = typeNameIdentifier((ElixirMatchedWhenOperation) specification);
}

return nameArity;
return nameIdentifier;
}


@NotNull
public static Pair<String, Integer> typeNameArity(Call call) {
String name = call.functionName();
Expand Down Expand Up @@ -136,6 +171,36 @@ public static Pair<String, Integer> typeNameArity(ElixirMatchedWhenOperation mat
return nameArity;
}

@Contract(pure = true)
@Nullable
public static PsiElement typeNameIdentifier(Call call) {
return call.functionNameElement();
}

@Nullable
public static PsiElement typeNameIdentifier(ElixirMatchedTypeOperation matchedTypeOperation) {
PsiElement leftOperand = matchedTypeOperation.leftOperand();
PsiElement nameIdentifier = null;

if (leftOperand instanceof Call) {
nameIdentifier = typeNameIdentifier((Call) leftOperand);
}

return nameIdentifier;
}

@Nullable
public static PsiElement typeNameIdentifier(ElixirMatchedWhenOperation matchedWhenOperation) {
PsiElement leftOperand = matchedWhenOperation.leftOperand();
PsiElement nameIdentifier = null;

if (leftOperand instanceof ElixirMatchedTypeOperation) {
nameIdentifier = typeNameIdentifier((ElixirMatchedTypeOperation) leftOperand);
}

return nameIdentifier;
}

/*
* Constructors
*/
Expand Down