use of org.jetbrains.annotations.Contract in project intellij-elixir by KronicDeth.
the class ElixirPsiImplUtil method getName.
@Contract(pure = true)
@Nullable
public static String getName(@NotNull NamedElement namedElement) {
PsiElement nameIdentifier = namedElement.getNameIdentifier();
String name = null;
if (nameIdentifier != null) {
name = nameIdentifier.getText();
} else {
if (namedElement instanceof Call) {
Call call = (Call) namedElement;
/* The name of the module defined by {@code defimpl PROTOCOL[ for: MODULE]} is derived by combining the
PROTOCOL and MODULE name into PROTOCOL.MODULE. Neither piece is really the "name" or
"nameIdentifier" element of the implementation because changing the PROTOCOL make the implementation
just for that different Protocol and changing the MODULE makes the implementation for a different
MODULE. If `for:` isn't given, it's really the enclosing {@code defmodule MODULE} whose name should
be changed. */
if (Implementation.is(call)) {
name = Implementation.name(call);
}
}
}
return name;
}
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 ElixirBitString bitString) {
ASTNode node = bitString.getNode();
ASTNode[] openingBits = node.getChildren(TokenSet.create(ElixirTypes.OPENING_BIT));
assert openingBits.length == 1;
ASTNode openingBit = openingBits[0];
PsiElement[] children = bitString.getChildren();
OtpErlangObject[] quotedChildren = new OtpErlangObject[children.length];
int i = 0;
for (PsiElement child : children) {
Quotable quotableChild = (Quotable) child;
quotedChildren[i++] = quotableChild.quote();
}
return quotedFunctionCall("<<>>", metadata(openingBit), quotedChildren);
}
use of org.jetbrains.annotations.Contract in project intellij-elixir by KronicDeth.
the class ElixirPsiImplUtil method isOutermostQualifiableAlias.
@Contract(pure = true)
public static boolean isOutermostQualifiableAlias(@NotNull QualifiableAlias qualifiableAlias) {
PsiElement parent = qualifiableAlias.getParent();
boolean outermost = false;
/* prevents individual Aliases or tail qualified aliases of qualified chain from having reference separate
reference from overall chain */
if (!(parent instanceof QualifiableAlias)) {
PsiElement grandParent = parent.getParent();
// prevents first Alias of a qualified chain from having a separate reference from overall chain
if (!(grandParent instanceof QualifiableAlias)) {
outermost = true;
}
}
return outermost;
}
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 Heredoc heredoc) {
ElixirHeredocPrefix heredocPrefix = heredoc.getHeredocPrefix();
int prefixLength = heredocPrefix.getTextLength();
Deque<ASTNode> alignedNodeQueue = new LinkedList<ASTNode>();
List<HeredocLine> heredocLineList = heredoc.getHeredocLineList();
IElementType fragmentType = heredoc.getFragmentType();
for (HeredocLine line : heredocLineList) {
queueChildNodes(line, fragmentType, prefixLength, alignedNodeQueue);
}
Queue<ASTNode> mergedNodeQueue = mergeFragments(alignedNodeQueue, heredoc.getFragmentType(), heredoc.getManager());
ASTNode[] mergedNodes = new ASTNode[mergedNodeQueue.size()];
mergedNodeQueue.toArray(mergedNodes);
return quotedChildNodes(heredoc, mergedNodes);
}
use of org.jetbrains.annotations.Contract in project intellij-elixir by KronicDeth.
the class ElixirPsiImplUtil method stripOnlyChildParent.
@Contract(pure = true)
@NotNull
public static PsiElement stripOnlyChildParent(@NotNull PsiElement parent) {
PsiElement unwrapped = parent;
PsiElement[] children = parent.getChildren();
if (children.length == 1) {
unwrapped = children[0];
}
return unwrapped;
}
Aggregations