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;
}
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;
}
}
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;
}
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;
}
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;
}
Aggregations