Search in sources :

Example 31 with Contract

use of org.jetbrains.annotations.Contract in project intellij-elixir by KronicDeth.

the class ElixirPsiImplUtil method resolvedSecondaryArity.

@Contract(pure = true)
@Nullable
public static Integer resolvedSecondaryArity(@NotNull final Call call) {
    Integer secondaryArity = call.secondaryArity();
    Integer resolvedSecondaryArity = secondaryArity;
    if (secondaryArity != null) {
        if (call.getDoBlock() != null) {
            resolvedSecondaryArity += 1;
        }
    // TODO handle piping
    }
    return resolvedSecondaryArity;
}
Also used : BigInteger(java.math.BigInteger) Contract(org.jetbrains.annotations.Contract) Nullable(org.jetbrains.annotations.Nullable)

Example 32 with Contract

use of org.jetbrains.annotations.Contract in project intellij-elixir by KronicDeth.

the class ElixirPsiImplUtil method macroDefinitionClauseForArgument.

@Contract(pure = true)
@Nullable
private static Call macroDefinitionClauseForArgument(Call callDefinitionClause) {
    Call macroDefinitionClause = null;
    PsiElement parent = callDefinitionClause.getParent();
    if (parent instanceof ElixirMatchedWhenOperation) {
        PsiElement grandParent = parent.getParent();
        if (grandParent instanceof ElixirNoParenthesesOneArgument) {
            PsiElement greatGrandParent = grandParent.getParent();
            if (greatGrandParent instanceof Call) {
                Call greatGrandParentCall = (Call) greatGrandParent;
                if (CallDefinitionClause.isMacro(greatGrandParentCall)) {
                    macroDefinitionClause = greatGrandParentCall;
                }
            }
        }
    }
    return macroDefinitionClause;
}
Also used : Call(org.elixir_lang.psi.call.Call) CallDefinitionClause.enclosingModularMacroCall(org.elixir_lang.structure_view.element.CallDefinitionClause.enclosingModularMacroCall) LeafPsiElement(com.intellij.psi.impl.source.tree.LeafPsiElement) Contract(org.jetbrains.annotations.Contract) Nullable(org.jetbrains.annotations.Nullable)

Example 33 with Contract

use of org.jetbrains.annotations.Contract in project intellij-elixir by KronicDeth.

the class Module method childCallTreeElements.

/*
     * Private Static Methods
     */
@Contract(pure = true)
@Nullable
private static TreeElement[] childCallTreeElements(@NotNull Modular modular, Call[] childCalls) {
    TreeElement[] treeElements = null;
    if (childCalls != null) {
        int length = childCalls.length;
        final List<TreeElement> treeElementList = new ArrayList<TreeElement>(length);
        FunctionByNameArity functionByNameArity = new FunctionByNameArity(length, treeElementList, modular);
        MacroByNameArity macroByNameArity = new MacroByNameArity(length, treeElementList, modular);
        Set<Overridable> overridableSet = new HashSet<Overridable>();
        Set<org.elixir_lang.structure_view.element.Use> useSet = new HashSet<org.elixir_lang.structure_view.element.Use>();
        for (Call childCall : childCalls) {
            if (Callback.is(childCall)) {
                treeElementList.add(new Callback(modular, childCall));
            } else if (Delegation.is(childCall)) {
                functionByNameArity.addDelegationToTreeElementList(childCall);
            } else if (Exception.is(childCall)) {
                functionByNameArity.setException(new Exception(modular, childCall));
            } else if (CallDefinitionClause.isFunction(childCall)) {
                functionByNameArity.addClausesToCallDefinition(childCall);
            } else if (CallDefinitionSpecification.is(childCall)) {
                functionByNameArity.addSpecificationToCallDefinition(childCall);
            } else if (Implementation.is(childCall)) {
                treeElementList.add(new Implementation(modular, childCall));
            } else if (CallDefinitionClause.isMacro(childCall)) {
                macroByNameArity.addClausesToCallDefinition(childCall);
            } else if (Module.is(childCall)) {
                treeElementList.add(new Module(modular, childCall));
            } else if (Overridable.is(childCall)) {
                Overridable overridable = new Overridable(modular, childCall);
                overridableSet.add(overridable);
                treeElementList.add(overridable);
            } else if (Protocol.is(childCall)) {
                treeElementList.add(new Protocol(modular, childCall));
            } else if (org.elixir_lang.structure_view.element.Quote.is(childCall)) {
                treeElementList.add(new Quote(modular, childCall));
            } else if (Structure.is(childCall)) {
                treeElementList.add(new Structure(modular, childCall));
            } else if (Type.is(childCall)) {
                treeElementList.add(Type.fromCall(modular, childCall));
            } else if (org.elixir_lang.structure_view.element.Use.is(childCall)) {
                org.elixir_lang.structure_view.element.Use use = new org.elixir_lang.structure_view.element.Use(modular, childCall);
                useSet.add(use);
                treeElementList.add(use);
            } else if (Unknown.is(childCall)) {
                // Should always be last since it will match all macro calls
                treeElementList.add(new Unknown(modular, childCall));
            }
        }
        for (Overridable overridable : overridableSet) {
            for (TreeElement treeElement : overridable.getChildren()) {
                CallReference callReference = (CallReference) treeElement;
                Integer arity = callReference.arity();
                if (arity != null) {
                    String name = callReference.name();
                    CallDefinition function = functionByNameArity.get(pair(name, arity));
                    if (function != null) {
                        function.setOverridable(true);
                    }
                }
            }
        }
        Collection<TreeElement> useCollection = new HashSet<TreeElement>(useSet.size());
        useCollection.addAll(useSet);
        Collection<TreeElement> nodesFromUses = Used.provideNodesFromChildren(useCollection);
        Map<Pair<String, Integer>, CallDefinition> useFunctionByNameArity = Used.functionByNameArity(nodesFromUses);
        for (Map.Entry<Pair<String, Integer>, CallDefinition> useNameArityFunction : useFunctionByNameArity.entrySet()) {
            CallDefinition useFunction = useNameArityFunction.getValue();
            if (useFunction.isOverridable()) {
                Pair<String, Integer> useNameArity = useNameArityFunction.getKey();
                CallDefinition function = functionByNameArity.get(useNameArity);
                if (function != null) {
                    function.setOverride(true);
                }
            }
        }
        treeElements = treeElementList.toArray(new TreeElement[treeElementList.size()]);
    }
    return treeElements;
}
Also used : MacroByNameArity(org.elixir_lang.structure_view.element.call_definition_by_name_arity.MacroByNameArity) CallDefinition(org.elixir_lang.structure_view.element.CallDefinition) FunctionByNameArity(org.elixir_lang.structure_view.element.call_definition_by_name_arity.FunctionByNameArity) Structure(org.elixir_lang.structure_view.element.structure.Structure) org.elixir_lang.structure_view.element(org.elixir_lang.structure_view.element) Pair(com.intellij.openapi.util.Pair) Call(org.elixir_lang.psi.call.Call) ElixirPsiImplUtil.enclosingMacroCall(org.elixir_lang.psi.impl.ElixirPsiImplUtil.enclosingMacroCall) Overridable(org.elixir_lang.structure_view.element.Overridable) Exception(org.elixir_lang.structure_view.element.Exception) TreeElement(com.intellij.ide.util.treeView.smartTree.TreeElement) Quote(org.elixir_lang.structure_view.element.Quote) Contract(org.jetbrains.annotations.Contract) Nullable(org.jetbrains.annotations.Nullable)

Example 34 with Contract

use of org.jetbrains.annotations.Contract in project intellij-community by JetBrains.

the class ActionManagerImpl method error.

@NotNull
@Contract(pure = true)
private static RuntimeException error(@NotNull ActionStub stub, @NotNull Throwable original, @NotNull String template, @NotNull String className) {
    PluginId pluginId = stub.getPluginId();
    String text = MessageFormat.format(template, className);
    if (pluginId == null) {
        return new IllegalStateException(text);
    }
    return new PluginException(text, original, pluginId);
}
Also used : PluginException(com.intellij.diagnostic.PluginException) PluginId(com.intellij.openapi.extensions.PluginId) NotNull(org.jetbrains.annotations.NotNull) Contract(org.jetbrains.annotations.Contract)

Example 35 with Contract

use of org.jetbrains.annotations.Contract in project intellij-community by JetBrains.

the class JavaLightTreeUtil method getArgList.

@Nullable
@Contract("_,null->null")
public static List<LighterASTNode> getArgList(@NotNull LighterAST tree, @Nullable LighterASTNode call) {
    LighterASTNode anonClass = LightTreeUtil.firstChildOfType(tree, call, ANONYMOUS_CLASS);
    LighterASTNode exprList = LightTreeUtil.firstChildOfType(tree, anonClass != null ? anonClass : call, EXPRESSION_LIST);
    return exprList == null ? null : getExpressionChildren(tree, exprList);
}
Also used : LighterASTNode(com.intellij.lang.LighterASTNode) Contract(org.jetbrains.annotations.Contract) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

Contract (org.jetbrains.annotations.Contract)111 NotNull (org.jetbrains.annotations.NotNull)48 Nullable (org.jetbrains.annotations.Nullable)40 LeafPsiElement (com.intellij.psi.impl.source.tree.LeafPsiElement)29 PsiElement (com.intellij.psi.PsiElement)19 Call (org.elixir_lang.psi.call.Call)17 ASTNode (com.intellij.lang.ASTNode)14 CallDefinitionClause.enclosingModularMacroCall (org.elixir_lang.structure_view.element.CallDefinitionClause.enclosingModularMacroCall)9 PsiFile (com.intellij.psi.PsiFile)6 IElementType (com.intellij.psi.tree.IElementType)6 BigInteger (java.math.BigInteger)6 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 Quotable (org.elixir_lang.psi.Quotable)5 Project (com.intellij.openapi.project.Project)4 NavigatablePsiElement (com.intellij.psi.NavigatablePsiElement)3 Matcher (java.util.regex.Matcher)3 TreeElement (com.intellij.ide.util.treeView.smartTree.TreeElement)2 SdkModificator (com.intellij.openapi.projectRoots.SdkModificator)2 TextRange (com.intellij.openapi.util.TextRange)2 File (java.io.File)2