use of org.jetbrains.annotations.Contract in project Railcraft by Railcraft.
the class InvTools method acceptsItemStack.
/**
* Checks if inventory will accept the ItemStack.
*
* @param stack The ItemStack
* @param dest The IInventory
* @return true if room for stack
*/
@Contract("null,_ -> false;")
public static boolean acceptsItemStack(@Nullable ItemStack stack, IInventoryComposite dest) {
if (isEmpty(stack))
return false;
ItemStack newStack = stack.copy();
newStack.stackSize = 1;
for (IInventoryObject inv : dest) {
for (IInvSlot slot : InventoryIterator.getRailcraft(inv)) {
if (slot.canPutStackInSlot(stack))
return true;
}
}
return false;
}
use of org.jetbrains.annotations.Contract in project kotlin by JetBrains.
the class KtPsiUtil method getTopmostParentOfTypes.
@Nullable
@Contract("null, _ -> null")
public static PsiElement getTopmostParentOfTypes(@Nullable PsiElement element, @NotNull Class<? extends PsiElement>... parentTypes) {
if (element instanceof PsiFile)
return null;
PsiElement answer = PsiTreeUtil.getParentOfType(element, parentTypes);
if (answer instanceof PsiFile)
return answer;
do {
PsiElement next = PsiTreeUtil.getParentOfType(answer, parentTypes);
if (next == null)
break;
answer = next;
} while (true);
return answer;
}
use of org.jetbrains.annotations.Contract in project kotlin by JetBrains.
the class KotlinParsing method parseFunction.
/*
* function
* : modifiers "fun" typeParameters?
* (type ".")?
* SimpleName
* typeParameters? functionParameters (":" type)?
* typeConstraints
* functionBody?
* ;
*/
@Contract("false -> !null")
IElementType parseFunction(boolean failIfIdentifierExists) {
assert _at(FUN_KEYWORD);
// FUN_KEYWORD
advance();
// Recovery for the case of class A { fun| }
if (at(RBRACE)) {
error("Function body expected");
return FUN;
}
boolean typeParameterListOccurred = false;
if (at(LT)) {
parseTypeParameterList(TokenSet.create(LBRACKET, LBRACE, RBRACE, LPAR));
typeParameterListOccurred = true;
}
myBuilder.disableJoiningComplexTokens();
TokenSet functionNameFollow = TokenSet.create(LT, LPAR, RPAR, COLON, EQ);
boolean receiverFound = parseReceiverType("function", functionNameFollow);
if (at(IDENTIFIER) && failIfIdentifierExists) {
myBuilder.restoreJoiningComplexTokensState();
return null;
}
// function as expression has no name
parseFunctionOrPropertyName(receiverFound, "function", functionNameFollow, /*nameRequired = */
false);
myBuilder.restoreJoiningComplexTokensState();
TokenSet valueParametersFollow = TokenSet.create(EQ, LBRACE, RBRACE, SEMICOLON, RPAR);
if (at(LT)) {
PsiBuilder.Marker error = mark();
parseTypeParameterList(TokenSet.orSet(TokenSet.create(LPAR), valueParametersFollow));
if (typeParameterListOccurred) {
int offset = myBuilder.getCurrentOffset();
error.rollbackTo();
error = mark();
advance(offset - myBuilder.getCurrentOffset());
error.error("Only one type parameter list is allowed for a function");
} else {
error.drop();
}
typeParameterListOccurred = true;
}
if (at(LPAR)) {
parseValueParameterList(false, /* typeRequired = */
false, valueParametersFollow);
} else {
error("Expecting '('");
}
if (at(COLON)) {
// COLON
advance();
parseTypeRef();
}
parseTypeConstraintsGuarded(typeParameterListOccurred);
if (at(SEMICOLON)) {
// SEMICOLON
advance();
} else if (at(EQ) || at(LBRACE)) {
parseFunctionBody();
}
return FUN;
}
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(@NotNull final ElixirMapArguments mapArguments) {
ASTNode node = mapArguments.getNode();
ASTNode[] openingCurlies = node.getChildren(TokenSet.create(ElixirTypes.OPENING_CURLY));
assert openingCurlies.length == 1;
ASTNode openingCurly = openingCurlies[0];
OtpErlangObject[] quotedArguments;
ElixirMapUpdateArguments mapUpdateArguments = mapArguments.getMapUpdateArguments();
if (mapUpdateArguments != null) {
quotedArguments = new OtpErlangObject[] { mapUpdateArguments.quote() };
} else {
ElixirMapConstructionArguments mapConstructionArguments = mapArguments.getMapConstructionArguments();
if (mapConstructionArguments != null) {
quotedArguments = mapConstructionArguments.quoteArguments();
} else {
quotedArguments = new OtpErlangObject[0];
}
}
return quotedFunctionCall("%{}", metadata(openingCurly), quotedArguments);
}
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(@NotNull final AtUnqualifiedBracketOperation atUnqualifiedBracketOperation) {
Quotable operator = atUnqualifiedBracketOperation.getAtPrefixOperator();
OtpErlangObject quotedOperator = operator.quote();
ASTNode node = atUnqualifiedBracketOperation.getNode();
ASTNode[] identifierNodes = node.getChildren(IDENTIFIER_TOKEN_SET);
assert identifierNodes.length == 1;
ASTNode identifierNode = identifierNodes[0];
String identifier = identifierNode.getText();
OtpErlangList metadata = metadata(atUnqualifiedBracketOperation);
OtpErlangObject quotedOperand = quotedVariable(identifier, metadata);
OtpErlangTuple quotedContainer = quotedFunctionCall(quotedOperator, metadata, quotedOperand);
Quotable bracketArguments = atUnqualifiedBracketOperation.getBracketArguments();
OtpErlangObject quotedBracketArguments = bracketArguments.quote();
return quotedFunctionCall("Elixir.Access", "get", metadata(bracketArguments), quotedContainer, quotedBracketArguments);
}
Aggregations