Skip to content

Instantly share code, notes, and snippets.

@enebo
Last active August 29, 2015 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save enebo/8300d2f1dea826665ccc to your computer and use it in GitHub Desktop.
Save enebo/8300d2f1dea826665ccc to your computer and use it in GitHub Desktop.
/**
* Best attempt and breaking the code of arity values! we figure out how many fixed/required parameters
* must be supplied. Then we figure out if we need to mark the value as optional. Optional is indicated
* by multiplying -1 * (fixed + 1). Keyword args optional and rest values can indicate this optional
* condition but only if not required keyword arguments are present.
*/
public int arityValue() {
int oneForKeywords = requiredKwargs > 0 ? 1 : 0;
int fixedValue = pre() + post() + oneForKeywords;
boolean hasOptionalKeywords = kwargs - requiredKwargs > 0;
if (opt() > 0 || rest() != Rest.NONE || (hasOptionalKeywords || restKwargs()) && oneForKeywords == 0) {
return -1 * (fixedValue + 1);
}
return fixedValue;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment