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(PsiElement[] children) {
List<Quotable> quotableList = new LinkedList<Quotable>();
for (int i = 0; i < children.length; i++) {
PsiElement child = children[i];
if (child instanceof Quotable) {
quotableList.add((Quotable) child);
} else if (child instanceof Unquoted) {
continue;
} else {
throw new NotImplementedException("Child, " + child + ", must be Quotable or Unquoted");
}
}
Quotable[] quotableChildren = new Quotable[quotableList.size()];
quotableList.toArray(quotableChildren);
return quote(quotableChildren);
}
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 ModuleImpl method exports.
@Contract(pure = true)
@NotNull
public static MaybeExported[] exports(@NotNull TreeElement mirror) {
PsiElement mirrorPsi = mirror.getPsi();
MaybeExported[] exports;
if (mirrorPsi instanceof Call) {
Call mirrorCall = (Call) mirrorPsi;
final List<MaybeExported> exportedList = new ArrayList<MaybeExported>();
Modular.callDefinitionClauseCallWhile(mirrorCall, new Function<Call, Boolean>() {
@Override
public Boolean fun(Call call) {
if (call instanceof MaybeExported) {
MaybeExported maybeExportedCall = (MaybeExported) call;
if (maybeExportedCall.isExported()) {
exportedList.add(maybeExportedCall);
}
}
return true;
}
});
exports = exportedList.toArray(new MaybeExported[exportedList.size()]);
} else {
exports = new MaybeExported[0];
}
return exports;
}
use of org.jetbrains.annotations.Contract in project Railcraft by Railcraft.
the class InvTools 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 intellij-elixir by KronicDeth.
the class Parameter method putParameterized.
@Contract(pure = true)
@NotNull
private static Parameter putParameterized(@NotNull final Parameter parameter, @NotNull final PsiElement ancestor) {
Parameter parameterizedParameter;
PsiElement parent = ancestor.getParent();
/* MUST be before `Call` because `When` operations are `Call` implementations too in all cases even though
`When` is not a subinterface. */
if (parent instanceof When) {
parameterizedParameter = putParameterized(parameter, parent);
} else if (parent instanceof Call) {
parameterizedParameter = putParameterized(parameter, (Call) parent);
} else if (parent instanceof AtNonNumericOperation || parent instanceof ElixirAccessExpression || parent instanceof ElixirAssociations || parent instanceof ElixirAssociationsBase || parent instanceof ElixirBitString || parent instanceof ElixirBracketArguments || parent instanceof ElixirContainerAssociationOperation || parent instanceof ElixirKeywordPair || parent instanceof ElixirKeywords || parent instanceof ElixirList || parent instanceof ElixirMapArguments || parent instanceof ElixirMapConstructionArguments || parent instanceof ElixirMapOperation || parent instanceof ElixirMatchedParenthesesArguments || parent instanceof ElixirNoParenthesesArguments || parent instanceof ElixirNoParenthesesKeywordPair || parent instanceof ElixirNoParenthesesKeywords || /* ElixirNoParenthesesManyStrictNoParenthesesExpression indicates a syntax error where no parentheses
calls are nested, so it's invalid, but try to still resolve parameters to have highlighting */
parent instanceof ElixirNoParenthesesManyStrictNoParenthesesExpression || parent instanceof ElixirNoParenthesesOneArgument || /* handles `(conn, %{})` in `def (conn, %{})`, which can occur in def templates.
See https://github.com/KronicDeth/intellij-elixir/issues/367#issuecomment-244214975 */
parent instanceof ElixirNoParenthesesStrict || parent instanceof ElixirParenthesesArguments || parent instanceof ElixirParentheticalStab || parent instanceof ElixirStab || parent instanceof ElixirStabNoParenthesesSignature || parent instanceof ElixirStabBody || parent instanceof ElixirStabOperation || parent instanceof ElixirStabParenthesesSignature || parent instanceof ElixirStructOperation || parent instanceof ElixirTuple) {
parameterizedParameter = putParameterized(parameter, parent);
} else if (parent instanceof ElixirAnonymousFunction) {
parameterizedParameter = putParameterized(parameter, (ElixirAnonymousFunction) parent);
} else if (parent instanceof InMatch) {
parameterizedParameter = putParameterized(parameter, (InMatch) parent);
} else if (parent instanceof BracketOperation || parent instanceof ElixirBlockItem || parent instanceof ElixirDoBlock || parent instanceof ElixirInterpolation || parent instanceof ElixirMapUpdateArguments || parent instanceof ElixirMultipleAliases || parent instanceof ElixirQuoteStringBody || parent instanceof PsiFile || parent instanceof QualifiedAlias || parent instanceof QualifiedMultipleAliases) {
parameterizedParameter = new Parameter(parameter.entrance);
} else {
error("Don't know how to check if parameter", parent);
parameterizedParameter = new Parameter(parameter.entrance);
}
return parameterizedParameter;
}
Aggregations