Search in sources :

Example 1 with StubBased

use of org.elixir_lang.psi.call.StubBased in project intellij-elixir by KronicDeth.

the class ResolvableName method down.

/*
     * Private Static Methods
     */
@Nullable
private static List<String> down(@NotNull Call qualifier) {
    List<String> nameList = null;
    if (qualifier.isCalling(KERNEL, __MODULE__, 0)) {
        Call enclosingCall = enclosingModularMacroCall(qualifier);
        if (enclosingCall != null && enclosingCall instanceof StubBased) {
            StubBased enclosingStubBasedCall = (StubBased) enclosingCall;
            String canonicalName = enclosingStubBasedCall.canonicalName();
            if (canonicalName != null) {
                nameList = new ArrayList<String>();
                nameList.add(canonicalName);
            }
        }
    }
    return nameList;
}
Also used : Call(org.elixir_lang.psi.call.Call) CallDefinitionClause.enclosingModularMacroCall(org.elixir_lang.structure_view.element.CallDefinitionClause.enclosingModularMacroCall) StubBased(org.elixir_lang.psi.call.StubBased) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with StubBased

use of org.elixir_lang.psi.call.StubBased in project intellij-elixir by KronicDeth.

the class TestFinder method isTest.

@Override
public boolean isTest(@NotNull PsiElement element) {
    Call sourceElement = findSourceElement(element);
    boolean isTest = false;
    if (sourceElement != null && sourceElement instanceof StubBased) {
        StubBased sourceStubBased = (StubBased) sourceElement;
        @SuppressWarnings("unchecked") Set<String> canonicalNameSet = sourceStubBased.canonicalNameSet();
        if (!canonicalNameSet.isEmpty()) {
            for (String canonicalName : canonicalNameSet) {
                if (canonicalName.endsWith("Test")) {
                    isTest = true;
                    break;
                }
            }
        }
    }
    return isTest;
}
Also used : Call(org.elixir_lang.psi.call.Call) StubBased(org.elixir_lang.psi.call.StubBased)

Example 3 with StubBased

use of org.elixir_lang.psi.call.StubBased in project intellij-elixir by KronicDeth.

the class ElixirPsiImplUtil method fullyQualifiedName.

@Contract(pure = true)
@Nullable
public static String fullyQualifiedName(@NotNull final QualifiableAlias qualifiableAlias) {
    String fullyQualifiedName = null;
    PsiElement[] children = qualifiableAlias.getChildren();
    int operatorIndex = Normalized.operatorIndex(children);
    Quotable qualifier = org.elixir_lang.psi.operation.infix.Normalized.leftOperand(children, operatorIndex);
    String qualifierName = null;
    if (qualifier instanceof Call) {
        Call qualifierCall = (Call) qualifier;
        if (qualifierCall.isCalling(KERNEL, __MODULE__, 0)) {
            Call enclosingCall = enclosingModularMacroCall(qualifierCall);
            if (enclosingCall != null && enclosingCall instanceof StubBased) {
                StubBased enclosingStubBasedCall = (StubBased) enclosingCall;
                qualifierName = enclosingStubBasedCall.canonicalName();
            }
        }
    } else if (qualifier instanceof QualifiableAlias) {
        QualifiableAlias qualifiableQualifier = (QualifiableAlias) qualifier;
        qualifierName = qualifiableQualifier.fullyQualifiedName();
    } else if (qualifier instanceof ElixirAccessExpression) {
        PsiElement qualifierChild = stripAccessExpression(qualifier);
        if (qualifierChild instanceof ElixirAlias) {
            ElixirAlias childAlias = (ElixirAlias) qualifierChild;
            qualifierName = childAlias.getName();
        }
    }
    if (qualifierName != null) {
        Quotable rightOperand = org.elixir_lang.psi.operation.infix.Normalized.rightOperand(children, operatorIndex);
        if (rightOperand instanceof ElixirAlias) {
            ElixirAlias relativeAlias = (ElixirAlias) rightOperand;
            fullyQualifiedName = qualifierName + "." + relativeAlias.getName();
        }
    }
    return fullyQualifiedName;
}
Also used : Call(org.elixir_lang.psi.call.Call) CallDefinitionClause.enclosingModularMacroCall(org.elixir_lang.structure_view.element.CallDefinitionClause.enclosingModularMacroCall) StubBased(org.elixir_lang.psi.call.StubBased) LeafPsiElement(com.intellij.psi.impl.source.tree.LeafPsiElement) Contract(org.jetbrains.annotations.Contract) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with StubBased

use of org.elixir_lang.psi.call.StubBased in project intellij-elixir by KronicDeth.

the class ElixirFile method modulars.

/**
     * @return modulars owned (declared) by this element.
     */
@NotNull
@Override
public StubBased[] modulars() {
    StubBased[] stubBaseds = PsiTreeUtil.getChildrenOfType(this, StubBased.class);
    List<StubBased> modularList = new ArrayList<StubBased>();
    if (stubBaseds != null) {
        for (StubBased stubBased : stubBaseds) {
            if (Implementation.is(stubBased) || Module.is(stubBased) || Protocol.is(stubBased)) {
                modularList.add(stubBased);
            }
        }
    }
    return modularList.toArray(new StubBased[modularList.size()]);
}
Also used : ArrayList(java.util.ArrayList) StubBased(org.elixir_lang.psi.call.StubBased) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with StubBased

use of org.elixir_lang.psi.call.StubBased in project intellij-elixir by KronicDeth.

the class TestFinder method isTestElement.

/**
 * Check if the given element is a test or not.
 */
public static boolean isTestElement(@NotNull PsiElement element) {
    Call sourceElement = sourceElement(element);
    boolean isTest = false;
    if (sourceElement instanceof StubBased) {
        @SuppressWarnings("rawtypes") StubBased sourceStubBased = (StubBased) sourceElement;
        Set<String> canonicalNameSet = sourceStubBased.canonicalNameSet();
        if (!canonicalNameSet.isEmpty()) {
            for (String canonicalName : canonicalNameSet) {
                if (canonicalName.endsWith("Test")) {
                    isTest = true;
                    break;
                }
            }
        }
    }
    return isTest;
}
Also used : Call(org.elixir_lang.psi.call.Call) StubBased(org.elixir_lang.psi.call.StubBased)

Aggregations

StubBased (org.elixir_lang.psi.call.StubBased)9 Call (org.elixir_lang.psi.call.Call)7 CallDefinitionClause.enclosingModularMacroCall (org.elixir_lang.structure_view.element.CallDefinitionClause.enclosingModularMacroCall)4 Nullable (org.jetbrains.annotations.Nullable)4 LeafPsiElement (com.intellij.psi.impl.source.tree.LeafPsiElement)3 NotNull (org.jetbrains.annotations.NotNull)3 ArrayList (java.util.ArrayList)2 Project (com.intellij.openapi.project.Project)1 PsiElement (com.intellij.psi.PsiElement)1 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)1 NamedElement (org.elixir_lang.psi.NamedElement)1 Contract (org.jetbrains.annotations.Contract)1