use of org.jetbrains.annotations.Contract in project intellij-elixir by KronicDeth.
the class ElixirPsiImplUtil method exportedArity.
@Contract(pure = true)
public static int exportedArity(@NotNull final UnqualifiedNoParenthesesCall unqualifiedNoParenthesesCall) {
int arity = MaybeExported.UNEXPORTED_ARITY;
if (isExported(unqualifiedNoParenthesesCall)) {
Pair<String, IntRange> nameArityRange = CallDefinitionClause.nameArityRange(unqualifiedNoParenthesesCall);
if (nameArityRange != null) {
IntRange arityRange = nameArityRange.second;
if (arityRange != null) {
int minimumArity = arityRange.getMinimumInteger();
int maximumArity = arityRange.getMaximumInteger();
if (minimumArity == maximumArity) {
arity = minimumArity;
}
}
}
}
return arity;
}
use of org.jetbrains.annotations.Contract in project intellij-elixir by KronicDeth.
the class ElixirPsiImplUtil method quote.
@Contract(pure = true)
@NotNull
public static OtpErlangObject quote(@NotNull final ElixirStabBody stabBody) {
PsiElement[] children = stabBody.getChildren();
Deque<OtpErlangObject> quotedChildren = new ArrayDeque<OtpErlangObject>();
for (PsiElement child : children) {
// skip endOfExpression
if (isUnquoted(child)) {
continue;
}
Quotable quotableChild = (Quotable) child;
OtpErlangObject quotedChild = quotableChild.quote();
quotedChildren.add(quotedChild);
}
return buildBlock(quotedChildren);
}
use of org.jetbrains.annotations.Contract in project intellij-elixir by KronicDeth.
the class ElixirPsiImplUtil method quote.
@Contract(pure = true)
@NotNull
public static OtpErlangObject quote(@NotNull final ElixirList list) {
PsiElement[] listArguments = list.getChildren();
List<OtpErlangObject> quotedListArgumentList = new ArrayList<OtpErlangObject>(listArguments.length);
if (listArguments.length > 0) {
for (int i = 0; i < listArguments.length - 1; i++) {
Quotable listArgument = (Quotable) listArguments[i];
quotedListArgumentList.add(listArgument.quote());
}
PsiElement lastListArgument = listArguments[listArguments.length - 1];
if (lastListArgument instanceof ElixirKeywords) {
QuotableKeywordList quotableKeywordList = (QuotableKeywordList) lastListArgument;
for (Quotable keywordPair : quotableKeywordList.quotableKeywordPairList()) {
quotedListArgumentList.add(keywordPair.quote());
}
} else {
Quotable quotable = (Quotable) lastListArgument;
quotedListArgumentList.add(quotable.quote());
}
}
OtpErlangObject[] quotedListArguments = new OtpErlangObject[quotedListArgumentList.size()];
quotedListArgumentList.toArray(quotedListArguments);
return elixirCharList(new OtpErlangList(quotedListArguments));
}
use of org.jetbrains.annotations.Contract in project intellij-elixir by KronicDeth.
the class ElixirPsiImplUtil method quote.
@Contract(pure = true)
@NotNull
public static OtpErlangObject quote(@NotNull final ElixirTuple tuple) {
ASTNode node = tuple.getNode();
ASTNode[] openingCurlies = node.getChildren(TokenSet.create(ElixirTypes.OPENING_CURLY));
assert openingCurlies.length == 1;
ASTNode openingCurly = openingCurlies[0];
PsiElement[] children = tuple.getChildren();
OtpErlangObject[] quotedChildren = new OtpErlangObject[children.length];
int i = 0;
for (PsiElement child : children) {
Quotable quotableChild = (Quotable) child;
quotedChildren[i++] = quotableChild.quote();
}
OtpErlangObject quoted;
// 2-tuples are literals in quoted form
if (quotedChildren.length == 2) {
quoted = new OtpErlangTuple(quotedChildren);
} else {
quoted = quotedFunctionCall("{}", metadata(openingCurly), quotedChildren);
}
return quoted;
}
use of org.jetbrains.annotations.Contract in project intellij-elixir by KronicDeth.
the class ElixirPsiImplUtil method functionName.
@Contract(pure = true)
@Nullable
public static String functionName(@NotNull final Call call) {
String functionName = null;
PsiElement element = call.functionNameElement();
if (element != null) {
functionName = element.getText();
}
return functionName;
}
Aggregations