Last active
August 29, 2015 14:19
-
-
Save enebo/8300d2f1dea826665ccc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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