use of org.elixir_lang.psi.ElixirAccessExpression in project intellij-elixir by KronicDeth.
the class Exception method defaultValueElementByKeyElement.
/**
* The default value elements for the struct defined for the exception.
*
* @return Maps the element for the key in the struct to the element in the default value. When the list form of
* fields without default values is used, the Map value element is {@code null}.
*/
@NotNull
public Map<PsiElement, PsiElement> defaultValueElementByKeyElement() {
PsiElement[] finalArguments = ElixirPsiImplUtil.finalArguments(navigationItem);
assert finalArguments != null;
assert finalArguments.length == 1;
PsiElement finalArgument = finalArguments[0];
Map<PsiElement, PsiElement> defaultValueElementByKeyElement = new HashMap<PsiElement, PsiElement>(finalArguments.length);
if (finalArgument instanceof ElixirAccessExpression) {
PsiElement accessExpressionChild = stripAccessExpression(finalArgument);
assert accessExpressionChild instanceof ElixirList;
ElixirList list = (ElixirList) accessExpressionChild;
PsiElement[] listChildren = list.getChildren();
if (listChildren.length == 1) {
PsiElement listChild = listChildren[0];
if (listChild instanceof QuotableKeywordList) {
QuotableKeywordList quotableKeywordList = (QuotableKeywordList) listChild;
putQuotableKeywordList(defaultValueElementByKeyElement, quotableKeywordList);
} else {
defaultValueElementByKeyElement.put(listChild, null);
}
} else {
for (PsiElement key : list.getChildren()) {
defaultValueElementByKeyElement.put(key, null);
}
}
} else if (finalArgument instanceof QuotableKeywordList) {
QuotableKeywordList quotableKeywordList = (QuotableKeywordList) finalArgument;
putQuotableKeywordList(defaultValueElementByKeyElement, quotableKeywordList);
} else {
assert finalArgument != null;
}
return defaultValueElementByKeyElement;
}
use of org.elixir_lang.psi.ElixirAccessExpression in project intellij-elixir by KronicDeth.
the class Delegation method callDefinitionHeadCallList.
/*
* Static Methods
*/
public static List<Call> callDefinitionHeadCallList(Call defdelegateCall) {
List<Call> callDefinitionHeadCallList = null;
PsiElement[] finalArguments = ElixirPsiImplUtil.finalArguments(defdelegateCall);
assert finalArguments != null;
assert finalArguments.length > 0;
PsiElement firstFinalArgument = finalArguments[0];
if (firstFinalArgument instanceof ElixirAccessExpression) {
PsiElement accessExpressionChild = stripAccessExpression(firstFinalArgument);
if (accessExpressionChild instanceof ElixirList) {
ElixirList list = (ElixirList) accessExpressionChild;
Call[] listCalls = PsiTreeUtil.getChildrenOfType(list, Call.class);
callDefinitionHeadCallList = filterCallDefinitionHeadCallList(listCalls);
}
} else if (firstFinalArgument instanceof Call) {
Call call = (Call) firstFinalArgument;
callDefinitionHeadCallList = filterCallDefinitionHeadCallList(call);
}
if (callDefinitionHeadCallList == null) {
callDefinitionHeadCallList = Collections.emptyList();
}
return callDefinitionHeadCallList;
}
use of org.elixir_lang.psi.ElixirAccessExpression 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;
}
use of org.elixir_lang.psi.ElixirAccessExpression in project intellij-elixir by KronicDeth.
the class Field method is.
/*
* Static Methods
*/
public static boolean is(ElixirAtom atom) {
boolean field = false;
PsiElement parent = atom.getParent();
if (parent instanceof ElixirAccessExpression && parent.getChildren().length == 1) {
PsiElement grandParent = parent.getParent();
if (grandParent instanceof ElixirList) {
PsiElement greatGrandParent = grandParent.getParent();
if (greatGrandParent instanceof ElixirAccessExpression && greatGrandParent.getChildren().length == 1) {
PsiElement greatGreatGrandParent = greatGrandParent.getParent();
if (greatGreatGrandParent instanceof ElixirNoParenthesesOneArgument) {
PsiElement greatGreatGreatGrandParent = greatGreatGrandParent.getParent();
if (greatGreatGreatGrandParent instanceof Call) {
Call greatGreatGreatGrandParentCall = (Call) greatGreatGreatGrandParent;
field = Structure.is(greatGreatGreatGrandParentCall);
}
}
}
}
}
return field;
}
Aggregations