Skip to content

Commit

Permalink
Change getMinArguments/getMaxArguments to getMinArity/getMaxArity.
Browse files Browse the repository at this point in the history
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=159298105
  • Loading branch information
dimvar authored and blickly committed Jun 19, 2017
1 parent 183c87f commit 92e8188
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 18 deletions.
Expand Up @@ -1109,7 +1109,7 @@ public void visitFunction(NodeTraversal t, Node n) {
positionalDisposedParameters.add(DISPOSE_ALL);
} else {
// Record index of parameters that are disposed.
for (int index = 0; index < funType.getMaxArguments(); ++index) {
for (int index = 0; index < funType.getMaxArity(); ++index) {
// Bail out if the paramNode is not there.
if (paramNode == null) {
break;
Expand Down
12 changes: 6 additions & 6 deletions src/com/google/javascript/jscomp/TypeCheck.java
Expand Up @@ -1910,14 +1910,14 @@ private void visitParameterList(NodeTraversal t, Node call,
}

int numArgs = call.getChildCount() - 1;
int minArgs = functionType.getMinArguments();
int maxArgs = functionType.getMaxArguments();
if (minArgs > numArgs || maxArgs < numArgs) {
int minArity = functionType.getMinArity();
int maxArity = functionType.getMaxArity();
if (minArity > numArgs || maxArity < numArgs) {
report(t, call, WRONG_ARGUMENT_COUNT,
typeRegistry.getReadableTypeNameNoDeref(call.getFirstChild()),
String.valueOf(numArgs), String.valueOf(minArgs),
maxArgs != Integer.MAX_VALUE ?
" and no more than " + maxArgs + " argument(s)" : "");
String.valueOf(numArgs), String.valueOf(minArity),
maxArity == Integer.MAX_VALUE ? ""
: " and no more than " + maxArity + " argument(s)");
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/com/google/javascript/jscomp/TypeInference.java
Expand Up @@ -1172,7 +1172,7 @@ private FunctionType matchFunction(
// For now, we just make sure the current type has enough
// arguments to match the expected type, and return the
// expected type if it does.
if (currentType.getMaxArguments() <= expectedType.getMaxArguments()) {
if (currentType.getMaxArity() <= expectedType.getMaxArity()) {
return expectedType;
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/com/google/javascript/jscomp/TypedCodeGenerator.java
Expand Up @@ -130,12 +130,12 @@ private String getFunctionAnnotation(Node fnNode) {
}

// Param types
int minArgs = funType.getMinArguments();
int maxArgs = funType.getMaxArguments();
int minArity = funType.getMinArity();
int maxArity = funType.getMaxArity();
List<TypeI> formals = ImmutableList.copyOf(funType.getParameterTypes());
for (int i = 0; i < formals.size(); i++) {
sb.append(" * ");
appendAnnotation(sb, "param", getParameterJSDocType(formals, i, minArgs, maxArgs));
appendAnnotation(sb, "param", getParameterJSDocType(formals, i, minArity, maxArity));
sb.append(" ")
.append(paramNode == null ? "p" + i : paramNode.getString())
.append("\n");
Expand Down
4 changes: 2 additions & 2 deletions src/com/google/javascript/jscomp/newtypes/JSType.java
Expand Up @@ -1865,13 +1865,13 @@ public final boolean acceptsArguments(List<? extends TypeI> argumentTypes) {
}

@Override
public final int getMinArguments() {
public final int getMinArity() {
Preconditions.checkState(this.isFunctionType());
return this.getFunTypeIfSingletonObj().getMinArity();
}

@Override
public final int getMaxArguments() {
public final int getMaxArity() {
Preconditions.checkState(this.isFunctionType());
return this.getFunTypeIfSingletonObj().getMaxArity();
}
Expand Down
4 changes: 2 additions & 2 deletions src/com/google/javascript/rhino/FunctionTypeI.java
Expand Up @@ -99,10 +99,10 @@ public interface FunctionTypeI extends TypeI {
Iterable<TypeI> getParameterTypes();

/** Returns the number of required arguments. */
int getMinArguments();
int getMinArity();

/** Returns the maximum number of allowed arguments, or Integer.MAX_VALUE if variadic. */
int getMaxArguments();
int getMaxArity();

/** Returns the names of all type parameters. */
Collection<String> getTypeParameters();
Expand Down
6 changes: 3 additions & 3 deletions src/com/google/javascript/rhino/jstype/FunctionType.java
Expand Up @@ -326,7 +326,7 @@ public Node getParametersNode() {

/** Gets the minimum number of arguments that this function requires. */
@Override
public int getMinArguments() {
public int getMinArity() {
// NOTE(nicksantos): There are some native functions that have optional
// parameters before required parameters. This algorithm finds the position
// of the last required parameter.
Expand All @@ -346,7 +346,7 @@ public int getMinArguments() {
* or Integer.MAX_VALUE if this is a variable argument function.
*/
@Override
public int getMaxArguments() {
public int getMaxArity() {
Node params = getParametersNode();
if (params != null) {
Node lastParam = params.getLastChild();
Expand Down Expand Up @@ -1563,6 +1563,6 @@ public boolean acceptsArguments(List<? extends TypeI> argumentTypes) {
}

int numArgs = argumentTypes.size();
return this.getMinArguments() <= numArgs && numArgs <= this.getMaxArguments();
return this.getMinArity() <= numArgs && numArgs <= this.getMaxArity();
}
}

0 comments on commit 92e8188

Please sign in to comment.