-
-
Save headius/23a3305aad925d48e1c8 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 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