use of org.jetbrains.annotations.Contract in project intellij-elixir by KronicDeth.
the class ElixirPsiImplUtil method getPresentation.
@Contract(pure = true)
@Nullable
public static ItemPresentation getPresentation(@NotNull final ElixirIdentifier identifier) {
Parameter parameter = new Parameter(identifier);
Parameter parameterizedParameter = Parameter.putParameterized(parameter);
ItemPresentation itemPresentation = null;
if ((parameterizedParameter.type == Parameter.Type.FUNCTION_NAME || parameterizedParameter.type == Parameter.Type.MACRO_NAME) && parameterizedParameter.parameterized != null) {
final NavigatablePsiElement parameterized = parameterizedParameter.parameterized;
if (parameterized instanceof Call) {
CallDefinitionClause callDefinitionClause = CallDefinitionClause.fromCall((Call) parameterized);
if (callDefinitionClause != null) {
itemPresentation = callDefinitionClause.getPresentation();
}
}
}
return itemPresentation;
}
use of org.jetbrains.annotations.Contract in project intellij-elixir by KronicDeth.
the class ElixirPsiImplUtil method resolvedPrimaryArity.
@Contract(pure = true)
@Nullable
public static Integer resolvedPrimaryArity(@NotNull final Call call) {
Integer primaryArity = call.primaryArity();
Integer resolvedPrimaryArity = primaryArity;
/* do block and piping attach to the outer most parentheses, only count do block and piping for primary if there
are no secondary. */
if (call.secondaryArity() == null) {
if (call.getDoBlock() != null) {
if (primaryArity == null) {
resolvedPrimaryArity = 1;
} else {
resolvedPrimaryArity += 1;
}
}
PsiElement parent = call.getParent();
if (isPipe(parent)) {
Arrow parentPipeOperation = (Arrow) parent;
PsiElement pipedInto = parentPipeOperation.rightOperand();
/* only the right operand has its arity increased because it is the operand that has the output of the
left operand prepended to its arguments */
if (pipedInto != null && call.isEquivalentTo(pipedInto)) {
if (primaryArity == null) {
resolvedPrimaryArity = 1;
} else {
resolvedPrimaryArity += 1;
}
}
}
}
return resolvedPrimaryArity;
}
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 ElixirAssociationsBase associationsBase) {
PsiElement[] children = associationsBase.getChildren();
OtpErlangObject[] quotedChildren = new OtpErlangObject[children.length];
int i = 0;
for (PsiElement child : children) {
Quotable quotableChild = (Quotable) child;
quotedChildren[i++] = quotableChild.quote();
}
return new OtpErlangList(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 AssociationOperation associationOperation) {
PsiElement[] children = associationOperation.getChildren();
// associationInfixOperator is private so not a PsiElement
assert children.length == 2;
OtpErlangObject[] quotedChildren = new OtpErlangObject[children.length];
int i = 0;
for (PsiElement child : children) {
Quotable quotableChild = (Quotable) child;
quotedChildren[i++] = quotableChild.quote();
}
return new OtpErlangTuple(quotedChildren);
}
use of org.jetbrains.annotations.Contract in project intellij-elixir by KronicDeth.
the class ElixirPsiImplUtil method quoteArguments.
@Contract(pure = true)
@NotNull
public static OtpErlangObject[] quoteArguments(@NotNull final ElixirMapConstructionArguments mapConstructionArguments) {
PsiElement[] arguments = mapConstructionArguments.arguments();
List<OtpErlangObject> quotedArgumentList = new ArrayList<OtpErlangObject>();
for (PsiElement argument : arguments) {
Quotable quotableArgument = (Quotable) argument;
OtpErlangList quotedArgument = (OtpErlangList) quotableArgument.quote();
for (OtpErlangObject element : quotedArgument.elements()) {
quotedArgumentList.add(element);
}
}
OtpErlangObject[] quotedArguments = new OtpErlangObject[quotedArgumentList.size()];
return quotedArgumentList.toArray(quotedArguments);
}
Aggregations