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 AtUnqualifiedNoParenthesesCall atUnqualifiedNoParenthesesCall) {
ElixirAtIdentifier atIdentifier = atUnqualifiedNoParenthesesCall.getAtIdentifier();
Quotable operator = atIdentifier.getAtPrefixOperator();
OtpErlangObject quotedOperator = operator.quote();
ASTNode node = atIdentifier.getNode();
ASTNode[] identifierNodes = node.getChildren(IDENTIFIER_TOKEN_SET);
assert identifierNodes.length == 1;
ASTNode identifierNode = identifierNodes[0];
String identifier = identifierNode.getText();
OtpErlangObject quotedIdentifier = new OtpErlangAtom(identifier);
QuotableArguments noParenthesesOneArgument = atUnqualifiedNoParenthesesCall.getNoParenthesesOneArgument();
OtpErlangObject[] quotedArguments = noParenthesesOneArgument.quoteArguments();
ElixirDoBlock doBlock = atUnqualifiedNoParenthesesCall.getDoBlock();
OtpErlangObject quotedOperand = quotedBlockCall(quotedIdentifier, metadata(operator), quotedArguments, doBlock);
return quotedFunctionCall(quotedOperator, metadata(operator), quotedOperand);
}
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 UnqualifiedParenthesesCall unqualifiedParenthesesCall) {
ASTNode identifierNode = unqualifiedParenthesesCall.getNode().getFirstChildNode();
OtpErlangList metadata = metadata(unqualifiedParenthesesCall);
OtpErlangObject quotedIdentifier = new OtpErlangAtom(identifierNode.getText());
ElixirMatchedParenthesesArguments matchedParenthesesArguments = unqualifiedParenthesesCall.getMatchedParenthesesArguments();
List<ElixirParenthesesArguments> parenthesesArgumentsList = matchedParenthesesArguments.getParenthesesArgumentsList();
ElixirDoBlock doBlock = unqualifiedParenthesesCall.getDoBlock();
return quotedParenthesesCall(quotedIdentifier, metadata, parenthesesArgumentsList, doBlock);
}
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 Infix infix) {
Quotable leftOperand = infix.leftOperand();
OtpErlangObject quotedLeftOperand = leftOperand.quote();
Operator operator = infix.operator();
OtpErlangObject quotedOperator = operator.quote();
PsiElement rightOperand = infix.rightOperand();
OtpErlangObject quotedRightOperand;
if (rightOperand != null && rightOperand instanceof Quotable) {
Quotable quotableRightOperand = (Quotable) rightOperand;
quotedRightOperand = quotableRightOperand.quote();
} else {
// this is not valid Elixir quoting, but something needs to be there for quoting to work
quotedRightOperand = NIL;
}
return quotedFunctionCall(quotedOperator, metadata(operator), quotedLeftOperand, quotedRightOperand);
}
use of org.jetbrains.annotations.Contract in project intellij-elixir by KronicDeth.
the class ElixirPsiImplUtil method resolvedFunctionName.
@Contract(pure = true)
@NotNull
public static String resolvedFunctionName(@NotNull final org.elixir_lang.psi.call.StubBased<Stub> stubBased) {
Stub stub = stubBased.getStub();
String resolvedFunctionName;
if (stub != null) {
resolvedFunctionName = stub.resolvedFunctionName();
} else {
resolvedFunctionName = resolvedFunctionName((Call) stubBased);
}
//noinspection ConstantConditions
return resolvedFunctionName;
}
use of org.jetbrains.annotations.Contract in project intellij-elixir by KronicDeth.
the class ElixirPsiImplUtil method excessWhitespace.
/* Returns a virtual PsiElement representing the spaces at the end of charListHeredocLineWhitespace that are not
* consumed by prefixLength.
*
* @return null if prefixLength is greater than or equal to text length of charListHeredcoLineWhitespace.
*/
@Contract(pure = true)
@Nullable
public static ASTNode excessWhitespace(@NotNull final ElixirHeredocLinePrefix heredocLinePrefix, @NotNull final IElementType fragmentType, final int prefixLength) {
int availableLength = heredocLinePrefix.getTextLength();
int excessLength = availableLength - prefixLength;
ASTNode excessWhitespaceASTNode = null;
if (excessLength > 0) {
char[] excessWhitespaceChars = new char[excessLength];
Arrays.fill(excessWhitespaceChars, ' ');
String excessWhitespaceString = new String(excessWhitespaceChars);
excessWhitespaceASTNode = Factory.createSingleLeafElement(fragmentType, excessWhitespaceString, 0, excessLength, null, heredocLinePrefix.getManager());
}
return excessWhitespaceASTNode;
}
Aggregations