Search in sources :

Example 51 with Contract

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

the class JsonTools method getFromRegistryWhenPresent.

@Contract("_, _, _, !null -> !null")
@Nullable
public static <T extends IForgeRegistryEntry<T>> T getFromRegistryWhenPresent(JsonObject object, String tag, IForgeRegistry<T> registry, @Nullable T fallback) {
    if (object.has(tag)) {
        String string = object.get(tag).getAsString();
        T ret = registry.getValue(new ResourceLocation(string));
        return ret == null ? fallback : ret;
    }
    return fallback;
}
Also used : ResourceLocation(net.minecraft.util.ResourceLocation) Contract(org.jetbrains.annotations.Contract) Nullable(org.jetbrains.annotations.Nullable)

Example 52 with Contract

use of org.jetbrains.annotations.Contract in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoMoveToStructInitializationIntention method isUninitializedFieldReferenceExpression.

@Contract("null, _-> false")
private static boolean isUninitializedFieldReferenceExpression(@Nullable GoReferenceExpression fieldReferenceExpression, @NotNull GoCompositeLit structLiteral) {
    if (fieldReferenceExpression == null)
        return false;
    GoLiteralValue literalValue = structLiteral.getLiteralValue();
    PsiElement resolve = fieldReferenceExpression.resolve();
    return literalValue != null && isFieldDefinition(resolve) && !exists(literalValue.getElementList(), element -> isFieldInitialization(element, resolve));
}
Also used : PsiElement(com.intellij.psi.PsiElement) Contract(org.jetbrains.annotations.Contract)

Example 53 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 54 with Contract

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

the class Normalized method operand.

@Contract(pure = true)
@Nullable
private static Quotable operand(@NotNull PsiElement[] children, int operatorIndex) {
    int operandCount = children.length - 1 - operatorIndex;
    Quotable operand = null;
    // ensure operand is there and there isn't more than one
    if (operandCount == 1) {
        PsiElement child = children[operatorIndex + 1];
        if (child instanceof Quotable) {
            operand = (Quotable) child;
        }
    }
    return operand;
}
Also used : Quotable(org.elixir_lang.psi.Quotable) PsiElement(com.intellij.psi.PsiElement) Contract(org.jetbrains.annotations.Contract) Nullable(org.jetbrains.annotations.Nullable)

Example 55 with Contract

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

the class Normalized method leftOperand.

@Contract(pure = true)
@Nullable
public static Quotable leftOperand(@NotNull PsiElement[] children, int operatorIndex) {
    Quotable leftOperand = null;
    int leftOperandCount = operatorIndex;
    // ensures that {@code partialLeft PsiErrorElement} returns {@code null}
    if (leftOperandCount == 1) {
        PsiElement child = children[operatorIndex - 1];
        // prevents PsiErrorElement from being leftOperand
        if (child instanceof Quotable) {
            leftOperand = (Quotable) child;
        }
    }
    return leftOperand;
}
Also used : Quotable(org.elixir_lang.psi.Quotable) PsiElement(com.intellij.psi.PsiElement) 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