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 ElixirCharToken charToken) {
ASTNode[] children = charToken.getNode().getChildren(null);
if (children.length != 2) {
throw new NotImplementedException("CharToken expected to be ?(<character>|<escape sequence>)");
}
final ASTNode tokenized = children[1];
IElementType tokenizedElementType = tokenized.getElementType();
int codePoint;
if (tokenizedElementType == ElixirTypes.CHAR_LIST_FRAGMENT) {
if (tokenized.getTextLength() != 1) {
throw new NotImplementedException("Tokenized character expected to only be one character long");
}
String tokenizedString = tokenized.getText();
codePoint = tokenizedString.codePointAt(0);
} else {
EscapeSequence escapeSequence = (EscapeSequence) tokenized.getPsi();
codePoint = escapeSequence.codePoint();
}
return new OtpErlangLong(codePoint);
}
use of org.jetbrains.annotations.Contract in project intellij-elixir by KronicDeth.
the class ElixirPsiImplUtil method primaryArity.
@Contract(pure = true)
@Nullable
public static Integer primaryArity(@NotNull final Call call) {
PsiElement[] primaryArguments = call.primaryArguments();
Integer primaryArity = null;
if (primaryArguments != null) {
primaryArity = primaryArguments.length;
}
return primaryArity;
}
use of org.jetbrains.annotations.Contract in project intellij-elixir by KronicDeth.
the class ElixirPsiImplUtil method mergeFragments.
@NotNull
@Contract(pure = true)
private static Queue<ASTNode> mergeFragments(@NotNull Deque<ASTNode> unmergedNodes, IElementType fragmentType, @NotNull PsiManager manager) {
Queue<ASTNode> mergedNodes = new LinkedList<ASTNode>();
StringBuilder fragmentStringBuilder = null;
for (ASTNode unmergedNode : unmergedNodes) {
if (unmergedNode.getElementType() == fragmentType) {
if (fragmentStringBuilder == null) {
fragmentStringBuilder = new StringBuilder();
}
String fragment = unmergedNode.getText();
fragmentStringBuilder.append(fragment);
} else {
addMergedFragments(mergedNodes, fragmentType, fragmentStringBuilder, manager);
fragmentStringBuilder = null;
mergedNodes.add(unmergedNode);
}
}
addMergedFragments(mergedNodes, fragmentType, fragmentStringBuilder, manager);
return mergedNodes;
}
use of org.jetbrains.annotations.Contract in project intellij-elixir by KronicDeth.
the class ElixirPsiImplUtil method secondaryArity.
@Contract(pure = true)
@Nullable
public static Integer secondaryArity(@NotNull final Call call) {
PsiElement[] secondaryArguments = call.secondaryArguments();
Integer secondaryArity = null;
if (secondaryArguments != null) {
secondaryArity = secondaryArguments.length;
}
return secondaryArity;
}
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 Digits digits) {
final String text = digits.getText();
final int base = digits.base();
OtpErlangLong quoted;
try {
long value = Long.parseLong(text, base);
quoted = new OtpErlangLong(value);
} catch (NumberFormatException exception) {
BigInteger value = new BigInteger(text, base);
quoted = new OtpErlangLong(value);
}
return quoted;
}
Aggregations