use of org.elixir_lang.psi.QualifiableAlias in project intellij-elixir by KronicDeth.
the class Protocol method execute.
/*
* Private Instance Methods
*/
private boolean execute(@NotNull Call call, @NotNull @SuppressWarnings("unused") ResolveState state) {
boolean keepProcessing = true;
if (org.elixir_lang.structure_view.element.modular.Implementation.is(call)) {
QualifiableAlias protocolNameElement = org.elixir_lang.structure_view.element.modular.Implementation.protocolNameElement(call);
PsiElement element;
boolean validResult;
if (protocolNameElement != null) {
element = protocolNameElement;
validResult = this.validResult;
} else {
element = call;
validResult = false;
}
resolveResultList = Collections.<ResolveResult>singletonList(new PsiElementResolveResult(element, validResult));
keepProcessing = false;
}
return keepProcessing;
}
use of org.elixir_lang.psi.QualifiableAlias in project intellij-elixir by KronicDeth.
the class Module method execute.
/**
* @param element candidate element.
* @param state current state of resolver.
* @return false to stop processing.
*/
@Override
public boolean execute(@NotNull final PsiElement element, @NotNull final ResolveState state) {
boolean keepProcessing = true;
if (element instanceof QualifiableAlias) {
QualifiableAlias qualifiableAlias = (QualifiableAlias) element;
String qualifiableAliasFullyQualifiedName = qualifiableAlias.fullyQualifiedName();
if (qualifiableAlias.isModuleName() && qualifiableAliasFullyQualifiedName != null && qualifiableAliasFullyQualifiedName.equals(usage.fullyQualifiedName())) {
declaration = qualifiableAlias;
keepProcessing = false;
}
}
return keepProcessing;
}
use of org.elixir_lang.psi.QualifiableAlias in project intellij-elixir by KronicDeth.
the class Used method provideNodesFromChild.
public static Collection<TreeElement> provideNodesFromChild(@NotNull TreeElement child) {
Collection<TreeElement> nodes = null;
if (child instanceof Use) {
Use use = (Use) child;
PsiElement[] finalArguments = ElixirPsiImplUtil.finalArguments(use.call());
assert finalArguments != null;
if (finalArguments.length > 0) {
PsiElement firstFinalArgument = finalArguments[0];
if (firstFinalArgument instanceof ElixirAccessExpression) {
PsiElement accessExpressionChild = stripAccessExpression(firstFinalArgument);
if (accessExpressionChild instanceof QualifiableAlias) {
PsiReference reference = accessExpressionChild.getReference();
if (reference != null) {
PsiElement ancestor = reference.resolve();
while (ancestor != null && !(ancestor instanceof PsiFile)) {
if (ancestor instanceof Call) {
Call call = (Call) ancestor;
if (Module.is(call)) {
Module module = new Module(call);
Call[] childCalls = ElixirPsiImplUtil.macroChildCalls(call);
if (childCalls != null) {
Map<Pair<String, Integer>, CallDefinition> macroByNameArity = new HashMap<Pair<String, Integer>, CallDefinition>(childCalls.length);
for (Call childCall : childCalls) {
/* portion of {@link org.elixir_lang.structure_view.element.enclosingModular.Module#childCallTreeElements}
dealing with macros, restricted to __using__/1 */
if (CallDefinitionClause.isMacro(childCall)) {
Pair<String, IntRange> nameArityRange = CallDefinitionClause.nameArityRange(childCall);
if (nameArityRange != null) {
String name = nameArityRange.first;
IntRange arityRange = nameArityRange.second;
if (name.equals(USING) && arityRange.containsInteger(1)) {
addClausesToCallDefinition(childCall, name, arityRange, macroByNameArity, module, Timed.Time.COMPILE, new Inserter<CallDefinition>() {
@Override
public void insert(CallDefinition element) {
}
});
}
}
}
}
if (macroByNameArity.size() > 0) {
PsiElement[] usingArguments;
CallDefinition macro;
CallDefinitionClause matchingClause = null;
if (finalArguments.length > 1) {
usingArguments = Arrays.copyOfRange(finalArguments, 1, finalArguments.length);
Pair<String, Integer> nameArity = pair(USING, usingArguments.length);
macro = macroByNameArity.get(nameArity);
if (macro != null) {
matchingClause = macro.matchingClause(usingArguments);
}
} else {
/* `use <ALIAS>` will calls `__using__/1` even though there is
no additional argument, but it obviously can't select a clause. */
Pair<String, Integer> nameArity = pair(USING, 1);
macro = macroByNameArity.get(nameArity);
List<CallDefinitionClause> macroClauseList = macro.clauseList();
if (macroClauseList.size() == 1) {
matchingClause = macroClauseList.get(0);
} else {
// TODO match default argument clause/head to non-default argument clause that would be executed.
}
}
if (matchingClause != null) {
TreeElement[] callDefinitionClauseChildren = matchingClause.getChildren();
int length = callDefinitionClauseChildren.length;
if (length > 0) {
TreeElement lastCallDefinitionClauseChild = callDefinitionClauseChildren[length - 1];
if (lastCallDefinitionClauseChild instanceof Quote) {
Quote quote = (Quote) lastCallDefinitionClauseChild;
Quote injectedQuote = quote.used(use);
TreeElement[] injectedQuoteChildren = injectedQuote.getChildren();
nodes = new ArrayList<TreeElement>(injectedQuoteChildren.length);
for (TreeElement injectedQuoteChild : injectedQuoteChildren) {
if (!(injectedQuoteChild instanceof Overridable)) {
nodes.add(injectedQuoteChild);
}
}
break;
}
}
}
}
}
} else {
break;
}
}
ancestor = ancestor.getParent();
}
}
}
}
}
}
if (nodes == null) {
nodes = Collections.emptyList();
}
return nodes;
}
Aggregations