Search in sources :

Example 1 with Exact

use of org.elixir_lang.reference.resolver.atom.resolvable.Exact in project intellij-elixir by KronicDeth.

the class Resolvable method resolvable.

@NotNull
public static Resolvable resolvable(@NotNull ElixirAtom atom) {
    ElixirLine line = atom.getLine();
    Resolvable resolvable;
    if (line != null) {
        resolvable = resolvable(line);
    } else {
        ASTNode atomNode = atom.getNode();
        ASTNode atomFragmentNode = atomNode.getLastChildNode();
        assert atomFragmentNode.getElementType() == ElixirTypes.ATOM_FRAGMENT;
        resolvable = new Exact(":" + atomFragmentNode.getText());
    }
    return resolvable;
}
Also used : ASTNode(com.intellij.lang.ASTNode) Exact(org.elixir_lang.reference.resolver.atom.resolvable.Exact) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with Exact

use of org.elixir_lang.reference.resolver.atom.resolvable.Exact in project intellij-elixir by KronicDeth.

the class Resolvable method resolvable.

@NotNull
private static Resolvable resolvable(@NotNull Parent parent, @NotNull ASTNode[] children) {
    Resolvable resolvable;
    if (children.length == 0) {
        resolvable = new Exact(":\"\"");
    } else {
        List<String> regexList = new LinkedList<>();
        List<Integer> codePointList = null;
        for (ASTNode child : children) {
            IElementType elementType = child.getElementType();
            if (elementType == ElixirTypes.FRAGMENT) {
                codePointList = parent.addFragmentCodePoints(codePointList, child);
            } else if (elementType == ElixirTypes.ESCAPED_CHARACTER) {
                codePointList = parent.addEscapedCharacterCodePoints(codePointList, child);
            } else if (elementType == ElixirTypes.ESCAPED_EOL) {
                codePointList = parent.addEscapedEOL(codePointList, child);
            } else if (elementType == ElixirTypes.HEXADECIMAL_ESCAPE_PREFIX) {
                codePointList = addChildTextCodePoints(codePointList, child);
            } else if (elementType == ElixirTypes.INTERPOLATION) {
                if (codePointList != null) {
                    regexList.add(codePointListToString(codePointList));
                    codePointList = null;
                }
                regexList.add(interpolation());
            } else if (elementType == ElixirTypes.QUOTE_HEXADECIMAL_ESCAPE_SEQUENCE || elementType == ElixirTypes.SIGIL_HEXADECIMAL_ESCAPE_SEQUENCE) {
                codePointList = parent.addHexadecimalEscapeSequenceCodePoints(codePointList, child);
            } else {
                throw new NotImplementedException("Can't convert to Resolvable " + child);
            }
        }
        if (codePointList != null && regexList.isEmpty()) {
            resolvable = resolvableLiteral(codePointList);
        } else {
            if (codePointList != null) {
                regexList.add(codePointListToRegex(codePointList));
            }
            resolvable = new Pattern(join(regexList));
        }
    }
    return resolvable;
}
Also used : IElementType(com.intellij.psi.tree.IElementType) Pattern(org.elixir_lang.reference.resolver.atom.resolvable.Pattern) NotImplementedException(org.apache.commons.lang.NotImplementedException) ASTNode(com.intellij.lang.ASTNode) Exact(org.elixir_lang.reference.resolver.atom.resolvable.Exact) LinkedList(java.util.LinkedList) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ASTNode (com.intellij.lang.ASTNode)2 Exact (org.elixir_lang.reference.resolver.atom.resolvable.Exact)2 NotNull (org.jetbrains.annotations.NotNull)2 IElementType (com.intellij.psi.tree.IElementType)1 LinkedList (java.util.LinkedList)1 NotImplementedException (org.apache.commons.lang.NotImplementedException)1 Pattern (org.elixir_lang.reference.resolver.atom.resolvable.Pattern)1