Search in sources :

Example 91 with Contract

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(PsiElement[] children) {
    List<Quotable> quotableList = new LinkedList<Quotable>();
    for (int i = 0; i < children.length; i++) {
        PsiElement child = children[i];
        if (child instanceof Quotable) {
            quotableList.add((Quotable) child);
        } else if (child instanceof Unquoted) {
            continue;
        } else {
            throw new NotImplementedException("Child, " + child + ", must be Quotable or Unquoted");
        }
    }
    Quotable[] quotableChildren = new Quotable[quotableList.size()];
    quotableList.toArray(quotableChildren);
    return quote(quotableChildren);
}
Also used : NotImplementedException(org.apache.commons.lang.NotImplementedException) LeafPsiElement(com.intellij.psi.impl.source.tree.LeafPsiElement) Contract(org.jetbrains.annotations.Contract) NotNull(org.jetbrains.annotations.NotNull)

Example 92 with Contract

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

the class Parameter method putParameterized.

@Contract(pure = true)
@NotNull
private static Parameter putParameterized(@NotNull final Parameter parameter, @NotNull final Call ancestor) {
    Parameter parameterizedParameter;
    if (CallDefinitionClause.isFunction(ancestor) || Delegation.is(ancestor)) {
        parameterizedParameter = new Parameter(parameter.defaultValue, parameter.entrance, notNullize(parameter.parameterized, ancestor), notNullize(parameter.type, Type.FUNCTION_NAME));
    } else if (CallDefinitionClause.isMacro(ancestor)) {
        parameterizedParameter = new Parameter(parameter.defaultValue, parameter.entrance, notNullize(parameter.parameterized, ancestor), notNullize(parameter.type, Type.MACRO_NAME));
    } else if (ancestor.hasDoBlockOrKeyword()) {
        parameterizedParameter = new Parameter(parameter.defaultValue, parameter.entrance, ancestor, notNullize(parameter.type, Type.VARIABLE));
    } else {
        PsiElement element = ancestor.functionNameElement();
        Parameter updatedParameter = parameter;
        if (!PsiTreeUtil.isAncestor(element, parameter.entrance, false)) {
            updatedParameter = new Parameter(parameter.defaultValue, parameter.entrance, ancestor, notNullize(parameter.type, Type.VARIABLE));
        }
        // use generic handling so that parent is checked
        parameterizedParameter = putParameterized(updatedParameter, (PsiElement) ancestor);
    }
    return parameterizedParameter;
}
Also used : NavigatablePsiElement(com.intellij.psi.NavigatablePsiElement) PsiElement(com.intellij.psi.PsiElement) Contract(org.jetbrains.annotations.Contract) NotNull(org.jetbrains.annotations.NotNull)

Example 93 with Contract

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

the class ModuleImpl method exports.

@Contract(pure = true)
@NotNull
public static MaybeExported[] exports(@NotNull TreeElement mirror) {
    PsiElement mirrorPsi = mirror.getPsi();
    MaybeExported[] exports;
    if (mirrorPsi instanceof Call) {
        Call mirrorCall = (Call) mirrorPsi;
        final List<MaybeExported> exportedList = new ArrayList<MaybeExported>();
        Modular.callDefinitionClauseCallWhile(mirrorCall, new Function<Call, Boolean>() {

            @Override
            public Boolean fun(Call call) {
                if (call instanceof MaybeExported) {
                    MaybeExported maybeExportedCall = (MaybeExported) call;
                    if (maybeExportedCall.isExported()) {
                        exportedList.add(maybeExportedCall);
                    }
                }
                return true;
            }
        });
        exports = exportedList.toArray(new MaybeExported[exportedList.size()]);
    } else {
        exports = new MaybeExported[0];
    }
    return exports;
}
Also used : MaybeExported(org.elixir_lang.psi.call.MaybeExported) Call(org.elixir_lang.psi.call.Call) ArrayList(java.util.ArrayList) StubBasedPsiElement(com.intellij.psi.StubBasedPsiElement) PsiElement(com.intellij.psi.PsiElement) Contract(org.jetbrains.annotations.Contract) NotNull(org.jetbrains.annotations.NotNull)

Example 94 with Contract

use of org.jetbrains.annotations.Contract in project Railcraft by Railcraft.

the class InvTools method getItemDataRailcraft.

@Contract("null, _, _ -> null; !null, _, true -> !null; !null, _, false -> _")
@Nullable
public static NBTTagCompound getItemDataRailcraft(ItemStack stack, String tag, boolean create) {
    if (isEmpty(stack))
        return null;
    NBTTagCompound nbt = getItemDataRailcraft(stack, create);
    if (nbt != null && (create || nbt.hasKey(tag))) {
        NBTTagCompound subNBT = nbt.getCompoundTag(tag);
        nbt.setTag(tag, subNBT);
        return subNBT;
    }
    return null;
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Contract(org.jetbrains.annotations.Contract) Nullable(javax.annotation.Nullable)

Example 95 with Contract

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

the class Parameter method putParameterized.

@Contract(pure = true)
@NotNull
private static Parameter putParameterized(@NotNull final Parameter parameter, @NotNull final PsiElement ancestor) {
    Parameter parameterizedParameter;
    PsiElement parent = ancestor.getParent();
    /* MUST be before `Call` because `When` operations are `Call` implementations too in all cases even though
           `When` is not a subinterface. */
    if (parent instanceof When) {
        parameterizedParameter = putParameterized(parameter, parent);
    } else if (parent instanceof Call) {
        parameterizedParameter = putParameterized(parameter, (Call) parent);
    } else if (parent instanceof AtNonNumericOperation || parent instanceof ElixirAccessExpression || parent instanceof ElixirAssociations || parent instanceof ElixirAssociationsBase || parent instanceof ElixirBitString || parent instanceof ElixirBracketArguments || parent instanceof ElixirContainerAssociationOperation || parent instanceof ElixirKeywordPair || parent instanceof ElixirKeywords || parent instanceof ElixirList || parent instanceof ElixirMapArguments || parent instanceof ElixirMapConstructionArguments || parent instanceof ElixirMapOperation || parent instanceof ElixirMatchedParenthesesArguments || parent instanceof ElixirNoParenthesesArguments || parent instanceof ElixirNoParenthesesKeywordPair || parent instanceof ElixirNoParenthesesKeywords || /* ElixirNoParenthesesManyStrictNoParenthesesExpression indicates a syntax error where no parentheses
                   calls are nested, so it's invalid, but try to still resolve parameters to have highlighting */
    parent instanceof ElixirNoParenthesesManyStrictNoParenthesesExpression || parent instanceof ElixirNoParenthesesOneArgument || /* handles `(conn, %{})` in `def (conn, %{})`, which can occur in def templates.
                   See https://github.com/KronicDeth/intellij-elixir/issues/367#issuecomment-244214975 */
    parent instanceof ElixirNoParenthesesStrict || parent instanceof ElixirParenthesesArguments || parent instanceof ElixirParentheticalStab || parent instanceof ElixirStab || parent instanceof ElixirStabNoParenthesesSignature || parent instanceof ElixirStabBody || parent instanceof ElixirStabOperation || parent instanceof ElixirStabParenthesesSignature || parent instanceof ElixirStructOperation || parent instanceof ElixirTuple) {
        parameterizedParameter = putParameterized(parameter, parent);
    } else if (parent instanceof ElixirAnonymousFunction) {
        parameterizedParameter = putParameterized(parameter, (ElixirAnonymousFunction) parent);
    } else if (parent instanceof InMatch) {
        parameterizedParameter = putParameterized(parameter, (InMatch) parent);
    } else if (parent instanceof BracketOperation || parent instanceof ElixirBlockItem || parent instanceof ElixirDoBlock || parent instanceof ElixirInterpolation || parent instanceof ElixirMapUpdateArguments || parent instanceof ElixirMultipleAliases || parent instanceof ElixirQuoteStringBody || parent instanceof PsiFile || parent instanceof QualifiedAlias || parent instanceof QualifiedMultipleAliases) {
        parameterizedParameter = new Parameter(parameter.entrance);
    } else {
        error("Don't know how to check if parameter", parent);
        parameterizedParameter = new Parameter(parameter.entrance);
    }
    return parameterizedParameter;
}
Also used : InMatch(org.elixir_lang.psi.operation.InMatch) PsiFile(com.intellij.psi.PsiFile) NavigatablePsiElement(com.intellij.psi.NavigatablePsiElement) PsiElement(com.intellij.psi.PsiElement) Call(org.elixir_lang.psi.call.Call) When(org.elixir_lang.psi.operation.When) Contract(org.jetbrains.annotations.Contract) NotNull(org.jetbrains.annotations.NotNull)

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