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