use of org.jetbrains.annotations.Contract in project intellij-elixir by KronicDeth.
the class CallDefinitionClause method childCallTreeElements.
@Contract(pure = true)
@Nullable
private TreeElement[] childCallTreeElements(@Nullable Call[] childCalls) {
TreeElement[] treeElements = null;
if (childCalls != null) {
List<TreeElement> treeElementList = new ArrayList<TreeElement>(childCalls.length);
for (Call childCall : childCalls) {
addChildCall(treeElementList, childCall);
}
treeElements = treeElementList.toArray(new TreeElement[treeElementList.size()]);
}
return treeElements;
}
use of org.jetbrains.annotations.Contract in project intellij-elixir by KronicDeth.
the class CallDefinitionSpecification method is.
@Contract(pure = true)
public static boolean is(@NotNull final Call call) {
boolean is = false;
if (call instanceof AtUnqualifiedNoParenthesesCall) {
AtUnqualifiedNoParenthesesCall atUnqualifiedNoParenthesesCall = (AtUnqualifiedNoParenthesesCall) call;
String moduleAttributeName = ElixirPsiImplUtil.moduleAttributeName(atUnqualifiedNoParenthesesCall);
if (moduleAttributeName.equals("@spec")) {
is = true;
}
}
return is;
}
use of org.jetbrains.annotations.Contract in project intellij-elixir by KronicDeth.
the class ElixirPsiImplUtil method maybeAliasToModular.
/**
* @return {@link Call} for the {@code defmodule}, {@code defimpl}, or {@code defprotocol} that defines
* {@code maybeAlias} after it is resolved through any {@code alias}es.
*/
@Contract(pure = true)
@Nullable
public static Call maybeAliasToModular(@NotNull final PsiElement maybeAlias, @NotNull PsiElement maxScope) {
PsiElement maybeQualifiableAlias = stripAccessExpression(maybeAlias);
Call modular = null;
if (maybeQualifiableAlias instanceof QualifiableAlias) {
QualifiableAlias qualifiableAlias = (QualifiableAlias) maybeQualifiableAlias;
if (!recursiveKernelImport(qualifiableAlias, maxScope)) {
/* need to construct reference directly as qualified aliases don't return a reference except for the
outermost */
PsiPolyVariantReference reference = new org.elixir_lang.reference.Module(qualifiableAlias, maxScope);
modular = aliasToModular(qualifiableAlias, reference);
}
}
return modular;
}
use of org.jetbrains.annotations.Contract in project intellij-elixir by KronicDeth.
the class ElixirPsiImplUtil method resolvedFinalArity.
@Contract(pure = true)
@NotNull
public static int resolvedFinalArity(@NotNull final org.elixir_lang.psi.call.StubBased<Stub> stubBased) {
Stub stub = stubBased.getStub();
Integer resolvedFinalArity;
if (stub != null) {
resolvedFinalArity = stub.resolvedFinalArity();
} else {
resolvedFinalArity = resolvedFinalArity((Call) stubBased);
}
if (resolvedFinalArity == null) {
resolvedFinalArity = 0;
}
return resolvedFinalArity;
}
use of org.jetbrains.annotations.Contract in project intellij-elixir by KronicDeth.
the class ElixirPsiImplUtil method enclosingMacroCall.
/**
*
* @param call
* @return {@code null} if call is at top-level
*/
@Contract(pure = true)
@Nullable
public static Call enclosingMacroCall(PsiElement element) {
Call enclosingMacroCall = null;
PsiElement parent = element.getParent();
if (parent instanceof ElixirDoBlock) {
PsiElement grandParent = parent.getParent();
if (grandParent instanceof Call) {
enclosingMacroCall = (Call) grandParent;
}
} else if (parent instanceof ElixirStabBody) {
PsiElement grandParent = parent.getParent();
if (grandParent instanceof ElixirStab) {
PsiElement greatGrandParent = grandParent.getParent();
if (greatGrandParent instanceof ElixirBlockItem) {
PsiElement greatGreatGrandParent = greatGrandParent.getParent();
if (greatGreatGrandParent instanceof ElixirBlockList) {
PsiElement greatGreatGreatGrandParent = greatGreatGrandParent.getParent();
if (greatGreatGreatGrandParent instanceof ElixirDoBlock) {
PsiElement greatGreatGreatGreatGrandParent = greatGreatGreatGrandParent.getParent();
if (greatGreatGreatGreatGrandParent instanceof Call) {
enclosingMacroCall = (Call) greatGreatGreatGreatGrandParent;
}
}
}
} else if (greatGrandParent instanceof ElixirDoBlock) {
PsiElement greatGreatGrandParent = greatGrandParent.getParent();
if (greatGreatGrandParent instanceof Call) {
enclosingMacroCall = (Call) greatGreatGrandParent;
}
} else if (greatGrandParent instanceof ElixirParentheticalStab) {
PsiElement greatGreatGrandParent = greatGrandParent.getParent();
if (greatGreatGrandParent instanceof ElixirAccessExpression) {
enclosingMacroCall = enclosingMacroCall(greatGreatGrandParent);
}
}
} else if (grandParent instanceof ElixirStabOperation) {
PsiElement stabOperationParent = grandParent.getParent();
if (stabOperationParent instanceof ElixirStab) {
PsiElement stabParent = stabOperationParent.getParent();
if (stabParent instanceof ElixirAnonymousFunction) {
PsiElement anonymousFunctionParent = stabParent.getParent();
if (anonymousFunctionParent instanceof ElixirAccessExpression) {
PsiElement accessExpressionParent = anonymousFunctionParent.getParent();
if (accessExpressionParent instanceof Arguments) {
PsiElement argumentsParent = accessExpressionParent.getParent();
if (argumentsParent instanceof ElixirMatchedParenthesesArguments) {
PsiElement matchedParenthesesArgumentsParent = argumentsParent.getParent();
if (matchedParenthesesArgumentsParent instanceof Call) {
Call matchedParenthesesArgumentsParentCall = (Call) matchedParenthesesArgumentsParent;
if (matchedParenthesesArgumentsParentCall.isCalling("Enum", "map") || matchedParenthesesArgumentsParentCall.isCalling("Enum", "each")) {
enclosingMacroCall = enclosingMacroCall(matchedParenthesesArgumentsParentCall);
}
}
}
}
}
}
}
}
} else if (parent instanceof Arguments || parent instanceof Match || parent instanceof QualifiedAlias || parent instanceof QualifiedMultipleAliases) {
enclosingMacroCall = enclosingMacroCall(parent);
} else if (parent instanceof Call) {
Call parentCall = (Call) parent;
if (parentCall.isCalling(KERNEL, ALIAS)) {
enclosingMacroCall = parentCall;
}
} else if (parent instanceof QuotableKeywordPair) {
QuotableKeywordPair parentKeywordPair = (QuotableKeywordPair) parent;
if (hasKeywordKey(parentKeywordPair, "do")) {
PsiElement grandParent = parent.getParent();
if (grandParent instanceof QuotableKeywordList) {
PsiElement greatGrandParent = grandParent.getParent();
if (greatGrandParent instanceof ElixirNoParenthesesOneArgument) {
PsiElement greatGreatGrandParent = greatGrandParent.getParent();
if (greatGreatGrandParent instanceof Call) {
enclosingMacroCall = (Call) greatGreatGrandParent;
}
}
}
}
}
return enclosingMacroCall;
}
Aggregations