Skip to content

Instantly share code, notes, and snippets.

@headius
Forked from enebo/Fuuuuuu.java
Created April 15, 2015 22:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save headius/23a3305aad925d48e1c8 to your computer and use it in GitHub Desktop.
Save headius/23a3305aad925d48e1c8 to your computer and use it in GitHub Desktop.
/**
* Best attempt at 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 no 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