Search in sources :

Example 46 with Contract

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

the class ElixirPsiImplUtil method quotedRightOperand.

@Contract(pure = true)
@NotNull
public static OtpErlangObject quotedRightOperand(@NotNull final ElixirStabOperation stabOperation) {
    PsiElement rightOperand = stabOperation.rightOperand();
    OtpErlangObject quotedRightOperand;
    if (rightOperand != null && rightOperand instanceof Quotable) {
        Quotable quotableRightOperand = (Quotable) rightOperand;
        quotedRightOperand = quotableRightOperand.quote();
    } else {
        quotedRightOperand = NIL;
    }
    return quotedRightOperand;
}
Also used : LeafPsiElement(com.intellij.psi.impl.source.tree.LeafPsiElement) Contract(org.jetbrains.annotations.Contract) NotNull(org.jetbrains.annotations.NotNull)

Example 47 with Contract

use of org.jetbrains.annotations.Contract in project Perl5-IDEA by Camelcade.

the class PerlPackageUtil method getContextPackageName.

/**
 * Searching of namespace element is in. If no explicit namespaces defined, main is returned
 *
 * @param element psi element to find definition for
 * @return canonical package name
 */
@Contract("null -> null")
public static String getContextPackageName(@Nullable PsiElement element) {
    if (element == null) {
        return null;
    }
    PerlNamespaceDefinitionElement namespaceDefinition = getContainingNamespace(element);
    if (// checking that definition is valid and got namespace
    namespaceDefinition != null && namespaceDefinition.getPackageName() != null) {
        String name = namespaceDefinition.getPackageName();
        assert name != null;
        return name;
    }
    // default value
    PsiFile file = element.getContainingFile();
    if (file instanceof PerlFileImpl) {
        PsiElement contextParent = file.getContext();
        PsiElement realParent = file.getParent();
        if (contextParent != null && !contextParent.equals(realParent)) {
            return getContextPackageName(contextParent);
        }
        return ((PerlFileImpl) file).getPackageName();
    } else {
        return MAIN_PACKAGE;
    }
}
Also used : PerlFileImpl(com.perl5.lang.perl.psi.impl.PerlFileImpl) PerlNamespaceDefinitionElement(com.perl5.lang.perl.psi.PerlNamespaceDefinitionElement) PsiFile(com.intellij.psi.PsiFile) PsiElement(com.intellij.psi.PsiElement) Contract(org.jetbrains.annotations.Contract)

Example 48 with Contract

use of org.jetbrains.annotations.Contract in project Perl5-IDEA by Camelcade.

the class TemplateToolkitPsiUtil method getLastOpenMarker.

@Nullable
@Contract("null -> null")
public static IElementType getLastOpenMarker(@Nullable Editor editor) {
    if (editor == null) {
        return null;
    }
    int offset = editor.getCaretModel().getOffset();
    HighlighterIterator iterator = ((EditorEx) editor).getHighlighter().createIterator(offset);
    while (!iterator.atEnd()) {
        IElementType tokenType = iterator.getTokenType();
        if (TemplateToolkitSyntaxElements.OPEN_TAGS.contains(tokenType)) {
            return tokenType;
        }
        iterator.retreat();
    }
    return null;
}
Also used : IElementType(com.intellij.psi.tree.IElementType) HighlighterIterator(com.intellij.openapi.editor.highlighter.HighlighterIterator) Contract(org.jetbrains.annotations.Contract) Nullable(org.jetbrains.annotations.Nullable)

Example 49 with Contract

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

the class InvToolsAPI 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 50 with Contract

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

the class EntityTunnelBore method canHeadHarvestBlock.

@Contract("null, _ -> false")
public boolean canHeadHarvestBlock(ItemStack head, IBlockState targetState) {
    if (InvTools.isEmpty(head))
        return false;
    if (head.getItem() instanceof IBoreHead) {
        /*
            boolean mappingExists = false;

            int blockHarvestLevel = HarvestPlugin.getHarvestLevel(targetState, "pickaxe");
            if (blockHarvestLevel > -1) {
                if (boreHead.getHarvestLevel() >= blockHarvestLevel)
                    return true;
                mappingExists = true;
            }

            blockHarvestLevel = HarvestPlugin.getHarvestLevel(targetState, "axe");
            if (blockHarvestLevel > -1) {
                if (boreHead.getHarvestLevel() >= blockHarvestLevel)
                    return true;
                mappingExists = true;
            }

            blockHarvestLevel = HarvestPlugin.getHarvestLevel(targetState, "shovel");
            if (blockHarvestLevel > -1) {
                if (boreHead.getHarvestLevel() >= blockHarvestLevel)
                    return true;
                mappingExists = true;
            }

            if (mappingExists)
                return false;
            */
        Item item = head.getItem();
        Set<String> toolClasses = item.getToolClasses(head);
        EntityPlayer fakePlayer = RailcraftFakePlayer.get((WorldServer) world, posX, posY, posZ);
        return toolClasses.stream().anyMatch(tool -> item.getHarvestLevel(head, tool, fakePlayer, targetState) >= HarvestPlugin.getHarvestLevel(targetState, tool));
    }
    return false;
}
Also used : Item(net.minecraft.item.Item) EntityItem(net.minecraft.entity.item.EntityItem) IBoreHead(mods.railcraft.api.carts.IBoreHead) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Contract(org.jetbrains.annotations.Contract)

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