id int32 0 165k | repo stringlengths 7 58 | path stringlengths 12 218 | func_name stringlengths 3 140 | original_string stringlengths 73 34.1k | language stringclasses 1 value | code stringlengths 73 34.1k | code_tokens list | docstring stringlengths 3 16k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 105 339 |
|---|---|---|---|---|---|---|---|---|---|---|---|
24,000 | google/closure-compiler | src/com/google/javascript/jscomp/JSModule.java | JSModule.addAfter | public void addAfter(CompilerInput input, CompilerInput other) {
checkState(inputs.contains(other));
inputs.add(inputs.indexOf(other), input);
input.setModule(this);
} | java | public void addAfter(CompilerInput input, CompilerInput other) {
checkState(inputs.contains(other));
inputs.add(inputs.indexOf(other), input);
input.setModule(this);
} | [
"public",
"void",
"addAfter",
"(",
"CompilerInput",
"input",
",",
"CompilerInput",
"other",
")",
"{",
"checkState",
"(",
"inputs",
".",
"contains",
"(",
"other",
")",
")",
";",
"inputs",
".",
"add",
"(",
"inputs",
".",
"indexOf",
"(",
"other",
")",
",",
"input",
")",
";",
"input",
".",
"setModule",
"(",
"this",
")",
";",
"}"
] | Adds a source code input to this module directly after other. | [
"Adds",
"a",
"source",
"code",
"input",
"to",
"this",
"module",
"directly",
"after",
"other",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/JSModule.java#L165-L169 |
24,001 | google/closure-compiler | src/com/google/javascript/jscomp/JSModule.java | JSModule.addDependency | public void addDependency(JSModule dep) {
checkNotNull(dep);
Preconditions.checkState(dep != this, "Cannot add dependency on self", this);
deps.add(dep);
} | java | public void addDependency(JSModule dep) {
checkNotNull(dep);
Preconditions.checkState(dep != this, "Cannot add dependency on self", this);
deps.add(dep);
} | [
"public",
"void",
"addDependency",
"(",
"JSModule",
"dep",
")",
"{",
"checkNotNull",
"(",
"dep",
")",
";",
"Preconditions",
".",
"checkState",
"(",
"dep",
"!=",
"this",
",",
"\"Cannot add dependency on self\"",
",",
"this",
")",
";",
"deps",
".",
"add",
"(",
"dep",
")",
";",
"}"
] | Adds a dependency on another module. | [
"Adds",
"a",
"dependency",
"on",
"another",
"module",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/JSModule.java#L172-L176 |
24,002 | google/closure-compiler | src/com/google/javascript/jscomp/JSModule.java | JSModule.getSortedDependencyNames | List<String> getSortedDependencyNames() {
List<String> names = new ArrayList<>();
for (JSModule module : getDependencies()) {
names.add(module.getName());
}
Collections.sort(names);
return names;
} | java | List<String> getSortedDependencyNames() {
List<String> names = new ArrayList<>();
for (JSModule module : getDependencies()) {
names.add(module.getName());
}
Collections.sort(names);
return names;
} | [
"List",
"<",
"String",
">",
"getSortedDependencyNames",
"(",
")",
"{",
"List",
"<",
"String",
">",
"names",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"for",
"(",
"JSModule",
"module",
":",
"getDependencies",
"(",
")",
")",
"{",
"names",
".",
"add",
"(",
"module",
".",
"getName",
"(",
")",
")",
";",
"}",
"Collections",
".",
"sort",
"(",
"names",
")",
";",
"return",
"names",
";",
"}"
] | Gets the names of the modules that this module depends on,
sorted alphabetically. | [
"Gets",
"the",
"names",
"of",
"the",
"modules",
"that",
"this",
"module",
"depends",
"on",
"sorted",
"alphabetically",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/JSModule.java#L205-L212 |
24,003 | google/closure-compiler | src/com/google/javascript/jscomp/JSModule.java | JSModule.getAllDependencies | public Set<JSModule> getAllDependencies() {
// JSModule uses identity semantics
Set<JSModule> allDeps = Sets.newIdentityHashSet();
allDeps.addAll(deps);
ArrayDeque<JSModule> stack = new ArrayDeque<>(deps);
while (!stack.isEmpty()) {
JSModule module = stack.pop();
List<JSModule> moduleDeps = module.deps;
for (JSModule dep : moduleDeps) {
if (allDeps.add(dep)) {
stack.push(dep);
}
}
}
return allDeps;
} | java | public Set<JSModule> getAllDependencies() {
// JSModule uses identity semantics
Set<JSModule> allDeps = Sets.newIdentityHashSet();
allDeps.addAll(deps);
ArrayDeque<JSModule> stack = new ArrayDeque<>(deps);
while (!stack.isEmpty()) {
JSModule module = stack.pop();
List<JSModule> moduleDeps = module.deps;
for (JSModule dep : moduleDeps) {
if (allDeps.add(dep)) {
stack.push(dep);
}
}
}
return allDeps;
} | [
"public",
"Set",
"<",
"JSModule",
">",
"getAllDependencies",
"(",
")",
"{",
"// JSModule uses identity semantics",
"Set",
"<",
"JSModule",
">",
"allDeps",
"=",
"Sets",
".",
"newIdentityHashSet",
"(",
")",
";",
"allDeps",
".",
"addAll",
"(",
"deps",
")",
";",
"ArrayDeque",
"<",
"JSModule",
">",
"stack",
"=",
"new",
"ArrayDeque",
"<>",
"(",
"deps",
")",
";",
"while",
"(",
"!",
"stack",
".",
"isEmpty",
"(",
")",
")",
"{",
"JSModule",
"module",
"=",
"stack",
".",
"pop",
"(",
")",
";",
"List",
"<",
"JSModule",
">",
"moduleDeps",
"=",
"module",
".",
"deps",
";",
"for",
"(",
"JSModule",
"dep",
":",
"moduleDeps",
")",
"{",
"if",
"(",
"allDeps",
".",
"add",
"(",
"dep",
")",
")",
"{",
"stack",
".",
"push",
"(",
"dep",
")",
";",
"}",
"}",
"}",
"return",
"allDeps",
";",
"}"
] | Returns the transitive closure of dependencies starting from the
dependencies of this module. | [
"Returns",
"the",
"transitive",
"closure",
"of",
"dependencies",
"starting",
"from",
"the",
"dependencies",
"of",
"this",
"module",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/JSModule.java#L218-L234 |
24,004 | google/closure-compiler | src/com/google/javascript/jscomp/JSModule.java | JSModule.getThisAndAllDependencies | public Set<JSModule> getThisAndAllDependencies() {
Set<JSModule> deps = getAllDependencies();
deps.add(this);
return deps;
} | java | public Set<JSModule> getThisAndAllDependencies() {
Set<JSModule> deps = getAllDependencies();
deps.add(this);
return deps;
} | [
"public",
"Set",
"<",
"JSModule",
">",
"getThisAndAllDependencies",
"(",
")",
"{",
"Set",
"<",
"JSModule",
">",
"deps",
"=",
"getAllDependencies",
"(",
")",
";",
"deps",
".",
"add",
"(",
"this",
")",
";",
"return",
"deps",
";",
"}"
] | Returns this module and all of its dependencies in one list. | [
"Returns",
"this",
"module",
"and",
"all",
"of",
"its",
"dependencies",
"in",
"one",
"list",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/JSModule.java#L237-L241 |
24,005 | google/closure-compiler | src/com/google/javascript/jscomp/JSModule.java | JSModule.getByName | public CompilerInput getByName(String name) {
for (CompilerInput input : inputs) {
if (name.equals(input.getName())) {
return input;
}
}
return null;
} | java | public CompilerInput getByName(String name) {
for (CompilerInput input : inputs) {
if (name.equals(input.getName())) {
return input;
}
}
return null;
} | [
"public",
"CompilerInput",
"getByName",
"(",
"String",
"name",
")",
"{",
"for",
"(",
"CompilerInput",
"input",
":",
"inputs",
")",
"{",
"if",
"(",
"name",
".",
"equals",
"(",
"input",
".",
"getName",
"(",
")",
")",
")",
"{",
"return",
"input",
";",
"}",
"}",
"return",
"null",
";",
"}"
] | Returns the input with the given name or null if none. | [
"Returns",
"the",
"input",
"with",
"the",
"given",
"name",
"or",
"null",
"if",
"none",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/JSModule.java#L263-L270 |
24,006 | google/closure-compiler | src/com/google/javascript/jscomp/JSModule.java | JSModule.removeByName | public boolean removeByName(String name) {
boolean found = false;
Iterator<CompilerInput> iter = inputs.iterator();
while (iter.hasNext()) {
CompilerInput file = iter.next();
if (name.equals(file.getName())) {
iter.remove();
file.setModule(null);
found = true;
}
}
return found;
} | java | public boolean removeByName(String name) {
boolean found = false;
Iterator<CompilerInput> iter = inputs.iterator();
while (iter.hasNext()) {
CompilerInput file = iter.next();
if (name.equals(file.getName())) {
iter.remove();
file.setModule(null);
found = true;
}
}
return found;
} | [
"public",
"boolean",
"removeByName",
"(",
"String",
"name",
")",
"{",
"boolean",
"found",
"=",
"false",
";",
"Iterator",
"<",
"CompilerInput",
">",
"iter",
"=",
"inputs",
".",
"iterator",
"(",
")",
";",
"while",
"(",
"iter",
".",
"hasNext",
"(",
")",
")",
"{",
"CompilerInput",
"file",
"=",
"iter",
".",
"next",
"(",
")",
";",
"if",
"(",
"name",
".",
"equals",
"(",
"file",
".",
"getName",
"(",
")",
")",
")",
"{",
"iter",
".",
"remove",
"(",
")",
";",
"file",
".",
"setModule",
"(",
"null",
")",
";",
"found",
"=",
"true",
";",
"}",
"}",
"return",
"found",
";",
"}"
] | Removes any input with the given name. Returns whether any were removed. | [
"Removes",
"any",
"input",
"with",
"the",
"given",
"name",
".",
"Returns",
"whether",
"any",
"were",
"removed",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/JSModule.java#L275-L287 |
24,007 | google/closure-compiler | src/com/google/javascript/jscomp/JSModule.java | JSModule.sortInputsByDeps | public void sortInputsByDeps(AbstractCompiler compiler) {
// Set the compiler, so that we can parse requires/provides and report
// errors properly.
for (CompilerInput input : inputs) {
input.setCompiler(compiler);
}
// Sort the JSModule in this order.
List<CompilerInput> sortedList = new Es6SortedDependencies<>(inputs).getSortedList();
inputs.clear();
inputs.addAll(sortedList);
} | java | public void sortInputsByDeps(AbstractCompiler compiler) {
// Set the compiler, so that we can parse requires/provides and report
// errors properly.
for (CompilerInput input : inputs) {
input.setCompiler(compiler);
}
// Sort the JSModule in this order.
List<CompilerInput> sortedList = new Es6SortedDependencies<>(inputs).getSortedList();
inputs.clear();
inputs.addAll(sortedList);
} | [
"public",
"void",
"sortInputsByDeps",
"(",
"AbstractCompiler",
"compiler",
")",
"{",
"// Set the compiler, so that we can parse requires/provides and report",
"// errors properly.",
"for",
"(",
"CompilerInput",
"input",
":",
"inputs",
")",
"{",
"input",
".",
"setCompiler",
"(",
"compiler",
")",
";",
"}",
"// Sort the JSModule in this order.",
"List",
"<",
"CompilerInput",
">",
"sortedList",
"=",
"new",
"Es6SortedDependencies",
"<>",
"(",
"inputs",
")",
".",
"getSortedList",
"(",
")",
";",
"inputs",
".",
"clear",
"(",
")",
";",
"inputs",
".",
"addAll",
"(",
"sortedList",
")",
";",
"}"
] | Puts the JS files into a topologically sorted order by their dependencies. | [
"Puts",
"the",
"JS",
"files",
"into",
"a",
"topologically",
"sorted",
"order",
"by",
"their",
"dependencies",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/JSModule.java#L306-L317 |
24,008 | google/closure-compiler | src/com/google/javascript/jscomp/OptimizeArgumentsArray.java | OptimizeArgumentsArray.tryReplaceArguments | private void tryReplaceArguments(Scope scope) {
// Find the number of parameters that can be accessed without using `arguments`.
Node parametersList = NodeUtil.getFunctionParameters(scope.getRootNode());
checkState(parametersList.isParamList(), parametersList);
int numParameters = parametersList.getChildCount();
// Determine the highest index that is used to make an access on `arguments`. By default, assume
// that the value is the number of parameters to the function.
int highestIndex = getHighestIndex(numParameters - 1);
if (highestIndex < 0) {
return;
}
ImmutableSortedMap<Integer, String> argNames =
assembleParamNames(parametersList, highestIndex + 1);
changeMethodSignature(argNames, parametersList);
changeBody(argNames);
} | java | private void tryReplaceArguments(Scope scope) {
// Find the number of parameters that can be accessed without using `arguments`.
Node parametersList = NodeUtil.getFunctionParameters(scope.getRootNode());
checkState(parametersList.isParamList(), parametersList);
int numParameters = parametersList.getChildCount();
// Determine the highest index that is used to make an access on `arguments`. By default, assume
// that the value is the number of parameters to the function.
int highestIndex = getHighestIndex(numParameters - 1);
if (highestIndex < 0) {
return;
}
ImmutableSortedMap<Integer, String> argNames =
assembleParamNames(parametersList, highestIndex + 1);
changeMethodSignature(argNames, parametersList);
changeBody(argNames);
} | [
"private",
"void",
"tryReplaceArguments",
"(",
"Scope",
"scope",
")",
"{",
"// Find the number of parameters that can be accessed without using `arguments`.",
"Node",
"parametersList",
"=",
"NodeUtil",
".",
"getFunctionParameters",
"(",
"scope",
".",
"getRootNode",
"(",
")",
")",
";",
"checkState",
"(",
"parametersList",
".",
"isParamList",
"(",
")",
",",
"parametersList",
")",
";",
"int",
"numParameters",
"=",
"parametersList",
".",
"getChildCount",
"(",
")",
";",
"// Determine the highest index that is used to make an access on `arguments`. By default, assume",
"// that the value is the number of parameters to the function.",
"int",
"highestIndex",
"=",
"getHighestIndex",
"(",
"numParameters",
"-",
"1",
")",
";",
"if",
"(",
"highestIndex",
"<",
"0",
")",
"{",
"return",
";",
"}",
"ImmutableSortedMap",
"<",
"Integer",
",",
"String",
">",
"argNames",
"=",
"assembleParamNames",
"(",
"parametersList",
",",
"highestIndex",
"+",
"1",
")",
";",
"changeMethodSignature",
"(",
"argNames",
",",
"parametersList",
")",
";",
"changeBody",
"(",
"argNames",
")",
";",
"}"
] | Tries to optimize all the arguments array access in this scope by assigning a name to each
element.
@param scope scope of the function | [
"Tries",
"to",
"optimize",
"all",
"the",
"arguments",
"array",
"access",
"in",
"this",
"scope",
"by",
"assigning",
"a",
"name",
"to",
"each",
"element",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/OptimizeArgumentsArray.java#L151-L168 |
24,009 | google/closure-compiler | src/com/google/javascript/jscomp/OptimizeArgumentsArray.java | OptimizeArgumentsArray.getHighestIndex | private int getHighestIndex(int highestIndex) {
for (Node ref : currentArgumentsAccesses) {
Node getElem = ref.getParent();
// Bail on anything but argument[c] access where c is a constant.
// TODO(user): We might not need to bail out all the time, there might
// be more cases that we can cover.
if (!getElem.isGetElem() || ref != getElem.getFirstChild()) {
return -1;
}
Node index = ref.getNext();
// We have something like arguments[x] where x is not a constant. That
// means at least one of the access is not known.
if (!index.isNumber() || index.getDouble() < 0) {
// TODO(user): Its possible not to give up just yet. The type
// inference did a 'semi value propagation'. If we know that string
// is never a subclass of the type of the index. We'd know that
// it is never 'callee'.
return -1; // Give up.
}
//We want to bail out if someone tries to access arguments[0.5] for example
if (index.getDouble() != Math.floor(index.getDouble())){
return -1;
}
Node getElemParent = getElem.getParent();
// When we have argument[0](), replacing it with a() is semantically
// different if argument[0] is a function call that refers to 'this'
if (getElemParent.isCall() && getElemParent.getFirstChild() == getElem) {
// TODO(user): We can consider using .call() if aliasing that
// argument allows shorter alias for other arguments.
return -1;
}
// Replace the highest index if we see an access that has a higher index
// than all the one we saw before.
int value = (int) index.getDouble();
if (value > highestIndex) {
highestIndex = value;
}
}
return highestIndex;
} | java | private int getHighestIndex(int highestIndex) {
for (Node ref : currentArgumentsAccesses) {
Node getElem = ref.getParent();
// Bail on anything but argument[c] access where c is a constant.
// TODO(user): We might not need to bail out all the time, there might
// be more cases that we can cover.
if (!getElem.isGetElem() || ref != getElem.getFirstChild()) {
return -1;
}
Node index = ref.getNext();
// We have something like arguments[x] where x is not a constant. That
// means at least one of the access is not known.
if (!index.isNumber() || index.getDouble() < 0) {
// TODO(user): Its possible not to give up just yet. The type
// inference did a 'semi value propagation'. If we know that string
// is never a subclass of the type of the index. We'd know that
// it is never 'callee'.
return -1; // Give up.
}
//We want to bail out if someone tries to access arguments[0.5] for example
if (index.getDouble() != Math.floor(index.getDouble())){
return -1;
}
Node getElemParent = getElem.getParent();
// When we have argument[0](), replacing it with a() is semantically
// different if argument[0] is a function call that refers to 'this'
if (getElemParent.isCall() && getElemParent.getFirstChild() == getElem) {
// TODO(user): We can consider using .call() if aliasing that
// argument allows shorter alias for other arguments.
return -1;
}
// Replace the highest index if we see an access that has a higher index
// than all the one we saw before.
int value = (int) index.getDouble();
if (value > highestIndex) {
highestIndex = value;
}
}
return highestIndex;
} | [
"private",
"int",
"getHighestIndex",
"(",
"int",
"highestIndex",
")",
"{",
"for",
"(",
"Node",
"ref",
":",
"currentArgumentsAccesses",
")",
"{",
"Node",
"getElem",
"=",
"ref",
".",
"getParent",
"(",
")",
";",
"// Bail on anything but argument[c] access where c is a constant.",
"// TODO(user): We might not need to bail out all the time, there might",
"// be more cases that we can cover.",
"if",
"(",
"!",
"getElem",
".",
"isGetElem",
"(",
")",
"||",
"ref",
"!=",
"getElem",
".",
"getFirstChild",
"(",
")",
")",
"{",
"return",
"-",
"1",
";",
"}",
"Node",
"index",
"=",
"ref",
".",
"getNext",
"(",
")",
";",
"// We have something like arguments[x] where x is not a constant. That",
"// means at least one of the access is not known.",
"if",
"(",
"!",
"index",
".",
"isNumber",
"(",
")",
"||",
"index",
".",
"getDouble",
"(",
")",
"<",
"0",
")",
"{",
"// TODO(user): Its possible not to give up just yet. The type",
"// inference did a 'semi value propagation'. If we know that string",
"// is never a subclass of the type of the index. We'd know that",
"// it is never 'callee'.",
"return",
"-",
"1",
";",
"// Give up.",
"}",
"//We want to bail out if someone tries to access arguments[0.5] for example",
"if",
"(",
"index",
".",
"getDouble",
"(",
")",
"!=",
"Math",
".",
"floor",
"(",
"index",
".",
"getDouble",
"(",
")",
")",
")",
"{",
"return",
"-",
"1",
";",
"}",
"Node",
"getElemParent",
"=",
"getElem",
".",
"getParent",
"(",
")",
";",
"// When we have argument[0](), replacing it with a() is semantically",
"// different if argument[0] is a function call that refers to 'this'",
"if",
"(",
"getElemParent",
".",
"isCall",
"(",
")",
"&&",
"getElemParent",
".",
"getFirstChild",
"(",
")",
"==",
"getElem",
")",
"{",
"// TODO(user): We can consider using .call() if aliasing that",
"// argument allows shorter alias for other arguments.",
"return",
"-",
"1",
";",
"}",
"// Replace the highest index if we see an access that has a higher index",
"// than all the one we saw before.",
"int",
"value",
"=",
"(",
"int",
")",
"index",
".",
"getDouble",
"(",
")",
";",
"if",
"(",
"value",
">",
"highestIndex",
")",
"{",
"highestIndex",
"=",
"value",
";",
"}",
"}",
"return",
"highestIndex",
";",
"}"
] | Iterate through all the references to arguments array in the
function to determine the real highestIndex. Returns -1 when we should not
be replacing any arguments for this scope - we should exit tryReplaceArguments
@param highestIndex highest index that has been accessed from the arguments array | [
"Iterate",
"through",
"all",
"the",
"references",
"to",
"arguments",
"array",
"in",
"the",
"function",
"to",
"determine",
"the",
"real",
"highestIndex",
".",
"Returns",
"-",
"1",
"when",
"we",
"should",
"not",
"be",
"replacing",
"any",
"arguments",
"for",
"this",
"scope",
"-",
"we",
"should",
"exit",
"tryReplaceArguments"
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/OptimizeArgumentsArray.java#L177-L223 |
24,010 | google/closure-compiler | src/com/google/javascript/jscomp/OptimizeArgumentsArray.java | OptimizeArgumentsArray.changeMethodSignature | private void changeMethodSignature(ImmutableSortedMap<Integer, String> argNames, Node paramList) {
ImmutableSortedMap<Integer, String> newParams = argNames.tailMap(paramList.getChildCount());
for (String name : newParams.values()) {
paramList.addChildToBack(IR.name(name).useSourceInfoIfMissingFrom(paramList));
}
if (!newParams.isEmpty()) {
compiler.reportChangeToEnclosingScope(paramList);
}
} | java | private void changeMethodSignature(ImmutableSortedMap<Integer, String> argNames, Node paramList) {
ImmutableSortedMap<Integer, String> newParams = argNames.tailMap(paramList.getChildCount());
for (String name : newParams.values()) {
paramList.addChildToBack(IR.name(name).useSourceInfoIfMissingFrom(paramList));
}
if (!newParams.isEmpty()) {
compiler.reportChangeToEnclosingScope(paramList);
}
} | [
"private",
"void",
"changeMethodSignature",
"(",
"ImmutableSortedMap",
"<",
"Integer",
",",
"String",
">",
"argNames",
",",
"Node",
"paramList",
")",
"{",
"ImmutableSortedMap",
"<",
"Integer",
",",
"String",
">",
"newParams",
"=",
"argNames",
".",
"tailMap",
"(",
"paramList",
".",
"getChildCount",
"(",
")",
")",
";",
"for",
"(",
"String",
"name",
":",
"newParams",
".",
"values",
"(",
")",
")",
"{",
"paramList",
".",
"addChildToBack",
"(",
"IR",
".",
"name",
"(",
"name",
")",
".",
"useSourceInfoIfMissingFrom",
"(",
"paramList",
")",
")",
";",
"}",
"if",
"(",
"!",
"newParams",
".",
"isEmpty",
"(",
")",
")",
"{",
"compiler",
".",
"reportChangeToEnclosingScope",
"(",
"paramList",
")",
";",
"}",
"}"
] | Inserts new formal parameters into the method's signature based on the given set of names.
<p>Example: function() --> function(r0, r1, r2)
@param argNames maps param index to param name, if the param with that index has a name.
@param paramList node representing the function signature | [
"Inserts",
"new",
"formal",
"parameters",
"into",
"the",
"method",
"s",
"signature",
"based",
"on",
"the",
"given",
"set",
"of",
"names",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/OptimizeArgumentsArray.java#L233-L241 |
24,011 | google/closure-compiler | src/com/google/javascript/jscomp/parsing/parser/Scanner.java | Scanner.skipWhitespace | private boolean skipWhitespace() {
boolean foundLineTerminator = false;
while (!isAtEnd() && peekWhitespace()) {
if (isLineTerminator(nextChar())) {
foundLineTerminator = true;
}
}
return foundLineTerminator;
} | java | private boolean skipWhitespace() {
boolean foundLineTerminator = false;
while (!isAtEnd() && peekWhitespace()) {
if (isLineTerminator(nextChar())) {
foundLineTerminator = true;
}
}
return foundLineTerminator;
} | [
"private",
"boolean",
"skipWhitespace",
"(",
")",
"{",
"boolean",
"foundLineTerminator",
"=",
"false",
";",
"while",
"(",
"!",
"isAtEnd",
"(",
")",
"&&",
"peekWhitespace",
"(",
")",
")",
"{",
"if",
"(",
"isLineTerminator",
"(",
"nextChar",
"(",
")",
")",
")",
"{",
"foundLineTerminator",
"=",
"true",
";",
"}",
"}",
"return",
"foundLineTerminator",
";",
"}"
] | Returns true if the whitespace that was skipped included any
line terminators. | [
"Returns",
"true",
"if",
"the",
"whitespace",
"that",
"was",
"skipped",
"included",
"any",
"line",
"terminators",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/parsing/parser/Scanner.java#L270-L278 |
24,012 | google/closure-compiler | src/com/google/javascript/jscomp/parsing/parser/Scanner.java | Scanner.processUnicodeEscapes | private static String processUnicodeEscapes(String value) {
while (value.contains("\\")) {
int escapeStart = value.indexOf('\\');
try {
if (value.charAt(escapeStart + 1) != 'u') {
return null;
}
String hexDigits;
int escapeEnd;
if (value.charAt(escapeStart + 2) != '{') {
// Simple escape with exactly four hex digits: \\uXXXX
escapeEnd = escapeStart + 6;
hexDigits = value.substring(escapeStart + 2, escapeEnd);
} else {
// Escape with braces can have any number of hex digits: \\u{XXXXXXX}
escapeEnd = escapeStart + 3;
while (Character.digit(value.charAt(escapeEnd), 0x10) >= 0) {
escapeEnd++;
}
if (value.charAt(escapeEnd) != '}') {
return null;
}
hexDigits = value.substring(escapeStart + 3, escapeEnd);
escapeEnd++;
}
// TODO(mattloring): Allow code points greater than the size of a char
char ch = (char) Integer.parseInt(hexDigits, 0x10);
if (!isIdentifierPart(ch)) {
return null;
}
value = value.substring(0, escapeStart) + ch + value.substring(escapeEnd);
} catch (NumberFormatException | StringIndexOutOfBoundsException e) {
return null;
}
}
return value;
} | java | private static String processUnicodeEscapes(String value) {
while (value.contains("\\")) {
int escapeStart = value.indexOf('\\');
try {
if (value.charAt(escapeStart + 1) != 'u') {
return null;
}
String hexDigits;
int escapeEnd;
if (value.charAt(escapeStart + 2) != '{') {
// Simple escape with exactly four hex digits: \\uXXXX
escapeEnd = escapeStart + 6;
hexDigits = value.substring(escapeStart + 2, escapeEnd);
} else {
// Escape with braces can have any number of hex digits: \\u{XXXXXXX}
escapeEnd = escapeStart + 3;
while (Character.digit(value.charAt(escapeEnd), 0x10) >= 0) {
escapeEnd++;
}
if (value.charAt(escapeEnd) != '}') {
return null;
}
hexDigits = value.substring(escapeStart + 3, escapeEnd);
escapeEnd++;
}
// TODO(mattloring): Allow code points greater than the size of a char
char ch = (char) Integer.parseInt(hexDigits, 0x10);
if (!isIdentifierPart(ch)) {
return null;
}
value = value.substring(0, escapeStart) + ch + value.substring(escapeEnd);
} catch (NumberFormatException | StringIndexOutOfBoundsException e) {
return null;
}
}
return value;
} | [
"private",
"static",
"String",
"processUnicodeEscapes",
"(",
"String",
"value",
")",
"{",
"while",
"(",
"value",
".",
"contains",
"(",
"\"\\\\\"",
")",
")",
"{",
"int",
"escapeStart",
"=",
"value",
".",
"indexOf",
"(",
"'",
"'",
")",
";",
"try",
"{",
"if",
"(",
"value",
".",
"charAt",
"(",
"escapeStart",
"+",
"1",
")",
"!=",
"'",
"'",
")",
"{",
"return",
"null",
";",
"}",
"String",
"hexDigits",
";",
"int",
"escapeEnd",
";",
"if",
"(",
"value",
".",
"charAt",
"(",
"escapeStart",
"+",
"2",
")",
"!=",
"'",
"'",
")",
"{",
"// Simple escape with exactly four hex digits: \\\\uXXXX",
"escapeEnd",
"=",
"escapeStart",
"+",
"6",
";",
"hexDigits",
"=",
"value",
".",
"substring",
"(",
"escapeStart",
"+",
"2",
",",
"escapeEnd",
")",
";",
"}",
"else",
"{",
"// Escape with braces can have any number of hex digits: \\\\u{XXXXXXX}",
"escapeEnd",
"=",
"escapeStart",
"+",
"3",
";",
"while",
"(",
"Character",
".",
"digit",
"(",
"value",
".",
"charAt",
"(",
"escapeEnd",
")",
",",
"0x10",
")",
">=",
"0",
")",
"{",
"escapeEnd",
"++",
";",
"}",
"if",
"(",
"value",
".",
"charAt",
"(",
"escapeEnd",
")",
"!=",
"'",
"'",
")",
"{",
"return",
"null",
";",
"}",
"hexDigits",
"=",
"value",
".",
"substring",
"(",
"escapeStart",
"+",
"3",
",",
"escapeEnd",
")",
";",
"escapeEnd",
"++",
";",
"}",
"// TODO(mattloring): Allow code points greater than the size of a char",
"char",
"ch",
"=",
"(",
"char",
")",
"Integer",
".",
"parseInt",
"(",
"hexDigits",
",",
"0x10",
")",
";",
"if",
"(",
"!",
"isIdentifierPart",
"(",
"ch",
")",
")",
"{",
"return",
"null",
";",
"}",
"value",
"=",
"value",
".",
"substring",
"(",
"0",
",",
"escapeStart",
")",
"+",
"ch",
"+",
"value",
".",
"substring",
"(",
"escapeEnd",
")",
";",
"}",
"catch",
"(",
"NumberFormatException",
"|",
"StringIndexOutOfBoundsException",
"e",
")",
"{",
"return",
"null",
";",
"}",
"}",
"return",
"value",
";",
"}"
] | Converts unicode escapes in the given string to the equivalent unicode character. If there are
no escapes, returns the input unchanged. If there is an invalid escape sequence, returns null. | [
"Converts",
"unicode",
"escapes",
"in",
"the",
"given",
"string",
"to",
"the",
"equivalent",
"unicode",
"character",
".",
"If",
"there",
"are",
"no",
"escapes",
"returns",
"the",
"input",
"unchanged",
".",
"If",
"there",
"is",
"an",
"invalid",
"escape",
"sequence",
"returns",
"null",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/parsing/parser/Scanner.java#L767-L804 |
24,013 | google/closure-compiler | src/com/google/javascript/jscomp/regex/CaseCanonicalize.java | CaseCanonicalize.caseCanonicalize | public static String caseCanonicalize(String s) {
for (int i = 0, n = s.length(); i < n; ++i) {
char ch = s.charAt(i);
char cu = caseCanonicalize(ch);
if (cu != ch) {
StringBuilder sb = new StringBuilder(s);
sb.setCharAt(i, cu);
while (++i < n) {
sb.setCharAt(i, caseCanonicalize(s.charAt(i)));
}
return sb.toString();
}
}
return s;
} | java | public static String caseCanonicalize(String s) {
for (int i = 0, n = s.length(); i < n; ++i) {
char ch = s.charAt(i);
char cu = caseCanonicalize(ch);
if (cu != ch) {
StringBuilder sb = new StringBuilder(s);
sb.setCharAt(i, cu);
while (++i < n) {
sb.setCharAt(i, caseCanonicalize(s.charAt(i)));
}
return sb.toString();
}
}
return s;
} | [
"public",
"static",
"String",
"caseCanonicalize",
"(",
"String",
"s",
")",
"{",
"for",
"(",
"int",
"i",
"=",
"0",
",",
"n",
"=",
"s",
".",
"length",
"(",
")",
";",
"i",
"<",
"n",
";",
"++",
"i",
")",
"{",
"char",
"ch",
"=",
"s",
".",
"charAt",
"(",
"i",
")",
";",
"char",
"cu",
"=",
"caseCanonicalize",
"(",
"ch",
")",
";",
"if",
"(",
"cu",
"!=",
"ch",
")",
"{",
"StringBuilder",
"sb",
"=",
"new",
"StringBuilder",
"(",
"s",
")",
";",
"sb",
".",
"setCharAt",
"(",
"i",
",",
"cu",
")",
";",
"while",
"(",
"++",
"i",
"<",
"n",
")",
"{",
"sb",
".",
"setCharAt",
"(",
"i",
",",
"caseCanonicalize",
"(",
"s",
".",
"charAt",
"(",
"i",
")",
")",
")",
";",
"}",
"return",
"sb",
".",
"toString",
"(",
")",
";",
"}",
"}",
"return",
"s",
";",
"}"
] | Returns the case canonical version of the given string. | [
"Returns",
"the",
"case",
"canonical",
"version",
"of",
"the",
"given",
"string",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/regex/CaseCanonicalize.java#L191-L205 |
24,014 | google/closure-compiler | src/com/google/javascript/jscomp/regex/CaseCanonicalize.java | CaseCanonicalize.caseCanonicalize | public static char caseCanonicalize(char ch) {
if (ch < 0x80) { // Normal case.
return ('A' <= ch && ch <= 'Z') ? (char) (ch | 32) : ch;
}
// Non-ASCII case.
if (CASE_SENSITIVE.contains(ch)) {
for (DeltaSet ds : CANON_DELTA_SETS) {
if (ds.codeUnits.contains(ch)) {
return (char) (ch - ds.delta);
}
}
}
return ch;
} | java | public static char caseCanonicalize(char ch) {
if (ch < 0x80) { // Normal case.
return ('A' <= ch && ch <= 'Z') ? (char) (ch | 32) : ch;
}
// Non-ASCII case.
if (CASE_SENSITIVE.contains(ch)) {
for (DeltaSet ds : CANON_DELTA_SETS) {
if (ds.codeUnits.contains(ch)) {
return (char) (ch - ds.delta);
}
}
}
return ch;
} | [
"public",
"static",
"char",
"caseCanonicalize",
"(",
"char",
"ch",
")",
"{",
"if",
"(",
"ch",
"<",
"0x80",
")",
"{",
"// Normal case.",
"return",
"(",
"'",
"'",
"<=",
"ch",
"&&",
"ch",
"<=",
"'",
"'",
")",
"?",
"(",
"char",
")",
"(",
"ch",
"|",
"32",
")",
":",
"ch",
";",
"}",
"// Non-ASCII case.",
"if",
"(",
"CASE_SENSITIVE",
".",
"contains",
"(",
"ch",
")",
")",
"{",
"for",
"(",
"DeltaSet",
"ds",
":",
"CANON_DELTA_SETS",
")",
"{",
"if",
"(",
"ds",
".",
"codeUnits",
".",
"contains",
"(",
"ch",
")",
")",
"{",
"return",
"(",
"char",
")",
"(",
"ch",
"-",
"ds",
".",
"delta",
")",
";",
"}",
"}",
"}",
"return",
"ch",
";",
"}"
] | Returns the case canonical version of the given code-unit. ECMAScript 5
explicitly says that code-units are to be treated as their code-point
equivalent, even surrogates. | [
"Returns",
"the",
"case",
"canonical",
"version",
"of",
"the",
"given",
"code",
"-",
"unit",
".",
"ECMAScript",
"5",
"explicitly",
"says",
"that",
"code",
"-",
"units",
"are",
"to",
"be",
"treated",
"as",
"their",
"code",
"-",
"point",
"equivalent",
"even",
"surrogates",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/regex/CaseCanonicalize.java#L212-L225 |
24,015 | google/closure-compiler | src/com/google/javascript/jscomp/TypeCheck.java | TypeCheck.process | @Override
public void process(Node externsRoot, Node jsRoot) {
checkNotNull(scopeCreator);
checkNotNull(topScope);
Node externsAndJs = jsRoot.getParent();
checkState(externsAndJs != null);
checkState(externsRoot == null || externsAndJs.hasChild(externsRoot));
if (externsRoot != null) {
check(externsRoot, true);
}
check(jsRoot, false);
} | java | @Override
public void process(Node externsRoot, Node jsRoot) {
checkNotNull(scopeCreator);
checkNotNull(topScope);
Node externsAndJs = jsRoot.getParent();
checkState(externsAndJs != null);
checkState(externsRoot == null || externsAndJs.hasChild(externsRoot));
if (externsRoot != null) {
check(externsRoot, true);
}
check(jsRoot, false);
} | [
"@",
"Override",
"public",
"void",
"process",
"(",
"Node",
"externsRoot",
",",
"Node",
"jsRoot",
")",
"{",
"checkNotNull",
"(",
"scopeCreator",
")",
";",
"checkNotNull",
"(",
"topScope",
")",
";",
"Node",
"externsAndJs",
"=",
"jsRoot",
".",
"getParent",
"(",
")",
";",
"checkState",
"(",
"externsAndJs",
"!=",
"null",
")",
";",
"checkState",
"(",
"externsRoot",
"==",
"null",
"||",
"externsAndJs",
".",
"hasChild",
"(",
"externsRoot",
")",
")",
";",
"if",
"(",
"externsRoot",
"!=",
"null",
")",
"{",
"check",
"(",
"externsRoot",
",",
"true",
")",
";",
"}",
"check",
"(",
"jsRoot",
",",
"false",
")",
";",
"}"
] | Main entry point for this phase of processing. This follows the pattern for
JSCompiler phases.
@param externsRoot The root of the externs parse tree.
@param jsRoot The root of the input parse tree to be checked. | [
"Main",
"entry",
"point",
"for",
"this",
"phase",
"of",
"processing",
".",
"This",
"follows",
"the",
"pattern",
"for",
"JSCompiler",
"phases",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/TypeCheck.java#L437-L450 |
24,016 | google/closure-compiler | src/com/google/javascript/jscomp/TypeCheck.java | TypeCheck.doPercentTypedAccounting | private void doPercentTypedAccounting(Node n) {
JSType type = n.getJSType();
if (type == null) {
nullCount++;
} else if (type.isUnknownType()) {
if (reportUnknownTypes) {
compiler.report(JSError.make(n, UNKNOWN_EXPR_TYPE));
}
unknownCount++;
} else {
typedCount++;
}
} | java | private void doPercentTypedAccounting(Node n) {
JSType type = n.getJSType();
if (type == null) {
nullCount++;
} else if (type.isUnknownType()) {
if (reportUnknownTypes) {
compiler.report(JSError.make(n, UNKNOWN_EXPR_TYPE));
}
unknownCount++;
} else {
typedCount++;
}
} | [
"private",
"void",
"doPercentTypedAccounting",
"(",
"Node",
"n",
")",
"{",
"JSType",
"type",
"=",
"n",
".",
"getJSType",
"(",
")",
";",
"if",
"(",
"type",
"==",
"null",
")",
"{",
"nullCount",
"++",
";",
"}",
"else",
"if",
"(",
"type",
".",
"isUnknownType",
"(",
")",
")",
"{",
"if",
"(",
"reportUnknownTypes",
")",
"{",
"compiler",
".",
"report",
"(",
"JSError",
".",
"make",
"(",
"n",
",",
"UNKNOWN_EXPR_TYPE",
")",
")",
";",
"}",
"unknownCount",
"++",
";",
"}",
"else",
"{",
"typedCount",
"++",
";",
"}",
"}"
] | Counts the given node in the typed statistics.
@param n a node that should be typed | [
"Counts",
"the",
"given",
"node",
"in",
"the",
"typed",
"statistics",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/TypeCheck.java#L1073-L1085 |
24,017 | google/closure-compiler | src/com/google/javascript/jscomp/TypeCheck.java | TypeCheck.checkCanAssignToWithScope | private void checkCanAssignToWithScope(
NodeTraversal t, Node nodeToWarn, Node lvalue, JSType rightType, JSDocInfo info, String msg) {
if (lvalue.isDestructuringPattern()) {
checkDestructuringAssignment(t, nodeToWarn, lvalue, rightType, msg);
} else {
checkCanAssignToNameGetpropOrGetelem(t, nodeToWarn, lvalue, rightType, info, msg);
}
} | java | private void checkCanAssignToWithScope(
NodeTraversal t, Node nodeToWarn, Node lvalue, JSType rightType, JSDocInfo info, String msg) {
if (lvalue.isDestructuringPattern()) {
checkDestructuringAssignment(t, nodeToWarn, lvalue, rightType, msg);
} else {
checkCanAssignToNameGetpropOrGetelem(t, nodeToWarn, lvalue, rightType, info, msg);
}
} | [
"private",
"void",
"checkCanAssignToWithScope",
"(",
"NodeTraversal",
"t",
",",
"Node",
"nodeToWarn",
",",
"Node",
"lvalue",
",",
"JSType",
"rightType",
",",
"JSDocInfo",
"info",
",",
"String",
"msg",
")",
"{",
"if",
"(",
"lvalue",
".",
"isDestructuringPattern",
"(",
")",
")",
"{",
"checkDestructuringAssignment",
"(",
"t",
",",
"nodeToWarn",
",",
"lvalue",
",",
"rightType",
",",
"msg",
")",
";",
"}",
"else",
"{",
"checkCanAssignToNameGetpropOrGetelem",
"(",
"t",
",",
"nodeToWarn",
",",
"lvalue",
",",
"rightType",
",",
"info",
",",
"msg",
")",
";",
"}",
"}"
] | Checks that we can assign the given right type to the given lvalue or destructuring pattern.
<p>See {@link #checkCanAssignToNameGetpropOrGetelem(NodeTraversal, Node, Node, JSType,
JSDocInfo, String)} for more details
@param nodeToWarn A node to report type mismatch warnings on
@param lvalue The lvalue to which we're assigning or a destructuring pattern
@param rightType The type we're assigning to the lvalue
@param msg A message to report along with any type mismatch warnings | [
"Checks",
"that",
"we",
"can",
"assign",
"the",
"given",
"right",
"type",
"to",
"the",
"given",
"lvalue",
"or",
"destructuring",
"pattern",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/TypeCheck.java#L1116-L1123 |
24,018 | google/closure-compiler | src/com/google/javascript/jscomp/TypeCheck.java | TypeCheck.checkCanAssignToNameGetpropOrGetelem | private void checkCanAssignToNameGetpropOrGetelem(
NodeTraversal t, Node nodeToWarn, Node lvalue, JSType rightType, JSDocInfo info, String msg) {
checkArgument(
lvalue.isName() || lvalue.isGetProp() || lvalue.isGetElem() || lvalue.isCast(), lvalue);
if (lvalue.isGetProp()) {
Node object = lvalue.getFirstChild();
JSType objectJsType = getJSType(object);
Node property = lvalue.getLastChild();
String pname = property.getString();
// the first name in this getprop refers to an interface
// we perform checks in addition to the ones below
if (object.isGetProp()) {
JSType jsType = getJSType(object.getFirstChild());
if (jsType.isInterface() && object.getLastChild().getString().equals("prototype")) {
visitInterfacePropertyAssignment(object, lvalue);
}
}
checkEnumAlias(t, info, rightType, nodeToWarn);
checkPropCreation(lvalue);
// Prototype assignments are special, because they actually affect
// the definition of a class. These are mostly validated
// during TypedScopeCreator, and we only look for the "dumb" cases here.
// object.prototype = ...;
if (pname.equals("prototype")) {
validator.expectCanAssignToPrototype(objectJsType, nodeToWarn, rightType);
return;
}
// The generic checks for 'object.property' when 'object' is known,
// and 'property' is declared on it.
// object.property = ...;
ObjectType objectCastType = ObjectType.cast(objectJsType.restrictByNotNullOrUndefined());
JSType expectedPropertyType = getPropertyTypeIfDeclared(objectCastType, pname);
checkPropertyInheritanceOnGetpropAssign(
nodeToWarn, object, pname, info, expectedPropertyType);
// If we successfully found a non-unknown declared type, validate the assignment and don't do
// any further checks.
if (!expectedPropertyType.isUnknownType()) {
// Note: if the property has @implicitCast at its declaration, we don't check any
// assignments to it.
if (!propertyIsImplicitCast(objectCastType, pname)) {
validator.expectCanAssignToPropertyOf(
nodeToWarn, rightType, expectedPropertyType, object, pname);
}
return;
}
}
// Check qualified name sets to 'object' and 'object.property'.
// This can sometimes handle cases when the type of 'object' is not known.
// e.g.,
// var obj = createUnknownType();
// /** @type {number} */ obj.foo = true;
JSType leftType = getJSType(lvalue);
if (lvalue.isQualifiedName()) {
// variable with inferred type case
TypedVar var = t.getTypedScope().getVar(lvalue.getQualifiedName());
if (var != null) {
if (var.isTypeInferred()) {
return;
}
if (NodeUtil.getRootOfQualifiedName(lvalue).isThis()
&& t.getTypedScope() != var.getScope()) {
// Don't look at "this.foo" variables from other scopes.
return;
}
if (var.getType() != null) {
leftType = var.getType();
}
}
} // Fall through case for arbitrary LHS and arbitrary RHS.
validator.expectCanAssignTo(nodeToWarn, rightType, leftType, msg);
} | java | private void checkCanAssignToNameGetpropOrGetelem(
NodeTraversal t, Node nodeToWarn, Node lvalue, JSType rightType, JSDocInfo info, String msg) {
checkArgument(
lvalue.isName() || lvalue.isGetProp() || lvalue.isGetElem() || lvalue.isCast(), lvalue);
if (lvalue.isGetProp()) {
Node object = lvalue.getFirstChild();
JSType objectJsType = getJSType(object);
Node property = lvalue.getLastChild();
String pname = property.getString();
// the first name in this getprop refers to an interface
// we perform checks in addition to the ones below
if (object.isGetProp()) {
JSType jsType = getJSType(object.getFirstChild());
if (jsType.isInterface() && object.getLastChild().getString().equals("prototype")) {
visitInterfacePropertyAssignment(object, lvalue);
}
}
checkEnumAlias(t, info, rightType, nodeToWarn);
checkPropCreation(lvalue);
// Prototype assignments are special, because they actually affect
// the definition of a class. These are mostly validated
// during TypedScopeCreator, and we only look for the "dumb" cases here.
// object.prototype = ...;
if (pname.equals("prototype")) {
validator.expectCanAssignToPrototype(objectJsType, nodeToWarn, rightType);
return;
}
// The generic checks for 'object.property' when 'object' is known,
// and 'property' is declared on it.
// object.property = ...;
ObjectType objectCastType = ObjectType.cast(objectJsType.restrictByNotNullOrUndefined());
JSType expectedPropertyType = getPropertyTypeIfDeclared(objectCastType, pname);
checkPropertyInheritanceOnGetpropAssign(
nodeToWarn, object, pname, info, expectedPropertyType);
// If we successfully found a non-unknown declared type, validate the assignment and don't do
// any further checks.
if (!expectedPropertyType.isUnknownType()) {
// Note: if the property has @implicitCast at its declaration, we don't check any
// assignments to it.
if (!propertyIsImplicitCast(objectCastType, pname)) {
validator.expectCanAssignToPropertyOf(
nodeToWarn, rightType, expectedPropertyType, object, pname);
}
return;
}
}
// Check qualified name sets to 'object' and 'object.property'.
// This can sometimes handle cases when the type of 'object' is not known.
// e.g.,
// var obj = createUnknownType();
// /** @type {number} */ obj.foo = true;
JSType leftType = getJSType(lvalue);
if (lvalue.isQualifiedName()) {
// variable with inferred type case
TypedVar var = t.getTypedScope().getVar(lvalue.getQualifiedName());
if (var != null) {
if (var.isTypeInferred()) {
return;
}
if (NodeUtil.getRootOfQualifiedName(lvalue).isThis()
&& t.getTypedScope() != var.getScope()) {
// Don't look at "this.foo" variables from other scopes.
return;
}
if (var.getType() != null) {
leftType = var.getType();
}
}
} // Fall through case for arbitrary LHS and arbitrary RHS.
validator.expectCanAssignTo(nodeToWarn, rightType, leftType, msg);
} | [
"private",
"void",
"checkCanAssignToNameGetpropOrGetelem",
"(",
"NodeTraversal",
"t",
",",
"Node",
"nodeToWarn",
",",
"Node",
"lvalue",
",",
"JSType",
"rightType",
",",
"JSDocInfo",
"info",
",",
"String",
"msg",
")",
"{",
"checkArgument",
"(",
"lvalue",
".",
"isName",
"(",
")",
"||",
"lvalue",
".",
"isGetProp",
"(",
")",
"||",
"lvalue",
".",
"isGetElem",
"(",
")",
"||",
"lvalue",
".",
"isCast",
"(",
")",
",",
"lvalue",
")",
";",
"if",
"(",
"lvalue",
".",
"isGetProp",
"(",
")",
")",
"{",
"Node",
"object",
"=",
"lvalue",
".",
"getFirstChild",
"(",
")",
";",
"JSType",
"objectJsType",
"=",
"getJSType",
"(",
"object",
")",
";",
"Node",
"property",
"=",
"lvalue",
".",
"getLastChild",
"(",
")",
";",
"String",
"pname",
"=",
"property",
".",
"getString",
"(",
")",
";",
"// the first name in this getprop refers to an interface",
"// we perform checks in addition to the ones below",
"if",
"(",
"object",
".",
"isGetProp",
"(",
")",
")",
"{",
"JSType",
"jsType",
"=",
"getJSType",
"(",
"object",
".",
"getFirstChild",
"(",
")",
")",
";",
"if",
"(",
"jsType",
".",
"isInterface",
"(",
")",
"&&",
"object",
".",
"getLastChild",
"(",
")",
".",
"getString",
"(",
")",
".",
"equals",
"(",
"\"prototype\"",
")",
")",
"{",
"visitInterfacePropertyAssignment",
"(",
"object",
",",
"lvalue",
")",
";",
"}",
"}",
"checkEnumAlias",
"(",
"t",
",",
"info",
",",
"rightType",
",",
"nodeToWarn",
")",
";",
"checkPropCreation",
"(",
"lvalue",
")",
";",
"// Prototype assignments are special, because they actually affect",
"// the definition of a class. These are mostly validated",
"// during TypedScopeCreator, and we only look for the \"dumb\" cases here.",
"// object.prototype = ...;",
"if",
"(",
"pname",
".",
"equals",
"(",
"\"prototype\"",
")",
")",
"{",
"validator",
".",
"expectCanAssignToPrototype",
"(",
"objectJsType",
",",
"nodeToWarn",
",",
"rightType",
")",
";",
"return",
";",
"}",
"// The generic checks for 'object.property' when 'object' is known,",
"// and 'property' is declared on it.",
"// object.property = ...;",
"ObjectType",
"objectCastType",
"=",
"ObjectType",
".",
"cast",
"(",
"objectJsType",
".",
"restrictByNotNullOrUndefined",
"(",
")",
")",
";",
"JSType",
"expectedPropertyType",
"=",
"getPropertyTypeIfDeclared",
"(",
"objectCastType",
",",
"pname",
")",
";",
"checkPropertyInheritanceOnGetpropAssign",
"(",
"nodeToWarn",
",",
"object",
",",
"pname",
",",
"info",
",",
"expectedPropertyType",
")",
";",
"// If we successfully found a non-unknown declared type, validate the assignment and don't do",
"// any further checks.",
"if",
"(",
"!",
"expectedPropertyType",
".",
"isUnknownType",
"(",
")",
")",
"{",
"// Note: if the property has @implicitCast at its declaration, we don't check any",
"// assignments to it.",
"if",
"(",
"!",
"propertyIsImplicitCast",
"(",
"objectCastType",
",",
"pname",
")",
")",
"{",
"validator",
".",
"expectCanAssignToPropertyOf",
"(",
"nodeToWarn",
",",
"rightType",
",",
"expectedPropertyType",
",",
"object",
",",
"pname",
")",
";",
"}",
"return",
";",
"}",
"}",
"// Check qualified name sets to 'object' and 'object.property'.",
"// This can sometimes handle cases when the type of 'object' is not known.",
"// e.g.,",
"// var obj = createUnknownType();",
"// /** @type {number} */ obj.foo = true;",
"JSType",
"leftType",
"=",
"getJSType",
"(",
"lvalue",
")",
";",
"if",
"(",
"lvalue",
".",
"isQualifiedName",
"(",
")",
")",
"{",
"// variable with inferred type case",
"TypedVar",
"var",
"=",
"t",
".",
"getTypedScope",
"(",
")",
".",
"getVar",
"(",
"lvalue",
".",
"getQualifiedName",
"(",
")",
")",
";",
"if",
"(",
"var",
"!=",
"null",
")",
"{",
"if",
"(",
"var",
".",
"isTypeInferred",
"(",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"NodeUtil",
".",
"getRootOfQualifiedName",
"(",
"lvalue",
")",
".",
"isThis",
"(",
")",
"&&",
"t",
".",
"getTypedScope",
"(",
")",
"!=",
"var",
".",
"getScope",
"(",
")",
")",
"{",
"// Don't look at \"this.foo\" variables from other scopes.",
"return",
";",
"}",
"if",
"(",
"var",
".",
"getType",
"(",
")",
"!=",
"null",
")",
"{",
"leftType",
"=",
"var",
".",
"getType",
"(",
")",
";",
"}",
"}",
"}",
"// Fall through case for arbitrary LHS and arbitrary RHS.",
"validator",
".",
"expectCanAssignTo",
"(",
"nodeToWarn",
",",
"rightType",
",",
"leftType",
",",
"msg",
")",
";",
"}"
] | Checks that we can assign the given right type to the given lvalue.
<p>If the lvalue is a qualified name, and has a declared type in the given scope, uses the
declared type of the qualified name instead of the type on the node.
@param nodeToWarn A node to report type mismatch warnings on
@param lvalue The lvalue to which we're assigning - a NAME, GETELEM, or GETPROP
@param rightType The type we're assigning to the lvalue
@param msg A message to report along with any type mismatch warnings | [
"Checks",
"that",
"we",
"can",
"assign",
"the",
"given",
"right",
"type",
"to",
"the",
"given",
"lvalue",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/TypeCheck.java#L1152-L1234 |
24,019 | google/closure-compiler | src/com/google/javascript/jscomp/TypeCheck.java | TypeCheck.visitObjectPattern | private void visitObjectPattern(Node pattern) {
JSType patternType = getJSType(pattern);
validator.expectObject(pattern, patternType, "cannot destructure 'null' or 'undefined'");
for (Node child : pattern.children()) {
DestructuredTarget target = DestructuredTarget.createTarget(typeRegistry, patternType, child);
if (target.hasComputedProperty()) {
Node computedProperty = target.getComputedProperty();
validator.expectIndexMatch(
computedProperty, patternType, getJSType(computedProperty.getFirstChild()));
} else if (target.hasStringKey()) {
Node stringKey = target.getStringKey();
if (!stringKey.isQuotedString()) {
if (patternType.isDict()) {
report(stringKey, TypeValidator.ILLEGAL_PROPERTY_ACCESS, "unquoted", "dict");
}
// check for missing properties given `const {a} = obj;` but not `const {'a': a} = obj;`
checkPropertyAccessForDestructuring(
pattern, patternType, stringKey, getJSType(target.getNode()));
} else if (patternType.isStruct()) {
// check that we are not accessing a struct with a quoted string
report(stringKey, TypeValidator.ILLEGAL_PROPERTY_ACCESS, "quoted", "struct");
}
}
}
ensureTyped(pattern);
} | java | private void visitObjectPattern(Node pattern) {
JSType patternType = getJSType(pattern);
validator.expectObject(pattern, patternType, "cannot destructure 'null' or 'undefined'");
for (Node child : pattern.children()) {
DestructuredTarget target = DestructuredTarget.createTarget(typeRegistry, patternType, child);
if (target.hasComputedProperty()) {
Node computedProperty = target.getComputedProperty();
validator.expectIndexMatch(
computedProperty, patternType, getJSType(computedProperty.getFirstChild()));
} else if (target.hasStringKey()) {
Node stringKey = target.getStringKey();
if (!stringKey.isQuotedString()) {
if (patternType.isDict()) {
report(stringKey, TypeValidator.ILLEGAL_PROPERTY_ACCESS, "unquoted", "dict");
}
// check for missing properties given `const {a} = obj;` but not `const {'a': a} = obj;`
checkPropertyAccessForDestructuring(
pattern, patternType, stringKey, getJSType(target.getNode()));
} else if (patternType.isStruct()) {
// check that we are not accessing a struct with a quoted string
report(stringKey, TypeValidator.ILLEGAL_PROPERTY_ACCESS, "quoted", "struct");
}
}
}
ensureTyped(pattern);
} | [
"private",
"void",
"visitObjectPattern",
"(",
"Node",
"pattern",
")",
"{",
"JSType",
"patternType",
"=",
"getJSType",
"(",
"pattern",
")",
";",
"validator",
".",
"expectObject",
"(",
"pattern",
",",
"patternType",
",",
"\"cannot destructure 'null' or 'undefined'\"",
")",
";",
"for",
"(",
"Node",
"child",
":",
"pattern",
".",
"children",
"(",
")",
")",
"{",
"DestructuredTarget",
"target",
"=",
"DestructuredTarget",
".",
"createTarget",
"(",
"typeRegistry",
",",
"patternType",
",",
"child",
")",
";",
"if",
"(",
"target",
".",
"hasComputedProperty",
"(",
")",
")",
"{",
"Node",
"computedProperty",
"=",
"target",
".",
"getComputedProperty",
"(",
")",
";",
"validator",
".",
"expectIndexMatch",
"(",
"computedProperty",
",",
"patternType",
",",
"getJSType",
"(",
"computedProperty",
".",
"getFirstChild",
"(",
")",
")",
")",
";",
"}",
"else",
"if",
"(",
"target",
".",
"hasStringKey",
"(",
")",
")",
"{",
"Node",
"stringKey",
"=",
"target",
".",
"getStringKey",
"(",
")",
";",
"if",
"(",
"!",
"stringKey",
".",
"isQuotedString",
"(",
")",
")",
"{",
"if",
"(",
"patternType",
".",
"isDict",
"(",
")",
")",
"{",
"report",
"(",
"stringKey",
",",
"TypeValidator",
".",
"ILLEGAL_PROPERTY_ACCESS",
",",
"\"unquoted\"",
",",
"\"dict\"",
")",
";",
"}",
"// check for missing properties given `const {a} = obj;` but not `const {'a': a} = obj;`",
"checkPropertyAccessForDestructuring",
"(",
"pattern",
",",
"patternType",
",",
"stringKey",
",",
"getJSType",
"(",
"target",
".",
"getNode",
"(",
")",
")",
")",
";",
"}",
"else",
"if",
"(",
"patternType",
".",
"isStruct",
"(",
")",
")",
"{",
"// check that we are not accessing a struct with a quoted string",
"report",
"(",
"stringKey",
",",
"TypeValidator",
".",
"ILLEGAL_PROPERTY_ACCESS",
",",
"\"quoted\"",
",",
"\"struct\"",
")",
";",
"}",
"}",
"}",
"ensureTyped",
"(",
"pattern",
")",
";",
"}"
] | Validates all keys in an object pattern
<p>Validating the types assigned to any lhs nodes in the pattern is done at the ASSIGN/VAR/
PARAM_LIST/etc. node | [
"Validates",
"all",
"keys",
"in",
"an",
"object",
"pattern"
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/TypeCheck.java#L1352-L1378 |
24,020 | google/closure-compiler | src/com/google/javascript/jscomp/TypeCheck.java | TypeCheck.propertyIsImplicitCast | private static boolean propertyIsImplicitCast(ObjectType type, String prop) {
for (; type != null; type = type.getImplicitPrototype()) {
JSDocInfo docInfo = type.getOwnPropertyJSDocInfo(prop);
if (docInfo != null && docInfo.isImplicitCast()) {
return true;
}
}
return false;
} | java | private static boolean propertyIsImplicitCast(ObjectType type, String prop) {
for (; type != null; type = type.getImplicitPrototype()) {
JSDocInfo docInfo = type.getOwnPropertyJSDocInfo(prop);
if (docInfo != null && docInfo.isImplicitCast()) {
return true;
}
}
return false;
} | [
"private",
"static",
"boolean",
"propertyIsImplicitCast",
"(",
"ObjectType",
"type",
",",
"String",
"prop",
")",
"{",
"for",
"(",
";",
"type",
"!=",
"null",
";",
"type",
"=",
"type",
".",
"getImplicitPrototype",
"(",
")",
")",
"{",
"JSDocInfo",
"docInfo",
"=",
"type",
".",
"getOwnPropertyJSDocInfo",
"(",
"prop",
")",
";",
"if",
"(",
"docInfo",
"!=",
"null",
"&&",
"docInfo",
".",
"isImplicitCast",
"(",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Returns true if any type in the chain has an implicitCast annotation for
the given property. | [
"Returns",
"true",
"if",
"any",
"type",
"in",
"the",
"chain",
"has",
"an",
"implicitCast",
"annotation",
"for",
"the",
"given",
"property",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/TypeCheck.java#L1493-L1501 |
24,021 | google/closure-compiler | src/com/google/javascript/jscomp/TypeCheck.java | TypeCheck.hasUnknownOrEmptySupertype | private static boolean hasUnknownOrEmptySupertype(FunctionType ctor) {
checkArgument(ctor.isConstructor() || ctor.isInterface());
checkArgument(!ctor.isUnknownType());
// The type system should notice inheritance cycles on its own
// and break the cycle.
while (true) {
ObjectType maybeSuperInstanceType =
ctor.getPrototype().getImplicitPrototype();
if (maybeSuperInstanceType == null) {
return false;
}
if (maybeSuperInstanceType.isUnknownType()
|| maybeSuperInstanceType.isEmptyType()) {
return true;
}
ctor = maybeSuperInstanceType.getConstructor();
if (ctor == null) {
return false;
}
checkState(ctor.isConstructor() || ctor.isInterface());
}
} | java | private static boolean hasUnknownOrEmptySupertype(FunctionType ctor) {
checkArgument(ctor.isConstructor() || ctor.isInterface());
checkArgument(!ctor.isUnknownType());
// The type system should notice inheritance cycles on its own
// and break the cycle.
while (true) {
ObjectType maybeSuperInstanceType =
ctor.getPrototype().getImplicitPrototype();
if (maybeSuperInstanceType == null) {
return false;
}
if (maybeSuperInstanceType.isUnknownType()
|| maybeSuperInstanceType.isEmptyType()) {
return true;
}
ctor = maybeSuperInstanceType.getConstructor();
if (ctor == null) {
return false;
}
checkState(ctor.isConstructor() || ctor.isInterface());
}
} | [
"private",
"static",
"boolean",
"hasUnknownOrEmptySupertype",
"(",
"FunctionType",
"ctor",
")",
"{",
"checkArgument",
"(",
"ctor",
".",
"isConstructor",
"(",
")",
"||",
"ctor",
".",
"isInterface",
"(",
")",
")",
";",
"checkArgument",
"(",
"!",
"ctor",
".",
"isUnknownType",
"(",
")",
")",
";",
"// The type system should notice inheritance cycles on its own",
"// and break the cycle.",
"while",
"(",
"true",
")",
"{",
"ObjectType",
"maybeSuperInstanceType",
"=",
"ctor",
".",
"getPrototype",
"(",
")",
".",
"getImplicitPrototype",
"(",
")",
";",
"if",
"(",
"maybeSuperInstanceType",
"==",
"null",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"maybeSuperInstanceType",
".",
"isUnknownType",
"(",
")",
"||",
"maybeSuperInstanceType",
".",
"isEmptyType",
"(",
")",
")",
"{",
"return",
"true",
";",
"}",
"ctor",
"=",
"maybeSuperInstanceType",
".",
"getConstructor",
"(",
")",
";",
"if",
"(",
"ctor",
"==",
"null",
")",
"{",
"return",
"false",
";",
"}",
"checkState",
"(",
"ctor",
".",
"isConstructor",
"(",
")",
"||",
"ctor",
".",
"isInterface",
"(",
")",
")",
";",
"}",
"}"
] | Given a constructor or an interface type, find out whether the unknown
type is a supertype of the current type. | [
"Given",
"a",
"constructor",
"or",
"an",
"interface",
"type",
"find",
"out",
"whether",
"the",
"unknown",
"type",
"is",
"a",
"supertype",
"of",
"the",
"current",
"type",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/TypeCheck.java#L1736-L1758 |
24,022 | google/closure-compiler | src/com/google/javascript/jscomp/TypeCheck.java | TypeCheck.visitInterfacePropertyAssignment | private void visitInterfacePropertyAssignment(Node object, Node lvalue) {
if (!lvalue.getParent().isAssign()) {
// assignments to interface properties cannot be in destructuring patterns or for-of loops
reportInvalidInterfaceMemberDeclaration(object);
return;
}
Node assign = lvalue.getParent();
Node rvalue = assign.getSecondChild();
JSType rvalueType = getJSType(rvalue);
// Only 2 values are allowed for interface methods:
// goog.abstractMethod
// function () {};
// Other (non-method) interface properties must be stub declarations without assignments, e.g.
// someinterface.prototype.nonMethodProperty;
// which is why we enforce that `rvalueType.isFunctionType()`.
if (!rvalueType.isFunctionType()) {
reportInvalidInterfaceMemberDeclaration(object);
}
if (rvalue.isFunction() && !NodeUtil.isEmptyBlock(NodeUtil.getFunctionBody(rvalue))) {
String abstractMethodName = compiler.getCodingConvention().getAbstractMethodName();
compiler.report(JSError.make(object, INTERFACE_METHOD_NOT_EMPTY, abstractMethodName));
}
} | java | private void visitInterfacePropertyAssignment(Node object, Node lvalue) {
if (!lvalue.getParent().isAssign()) {
// assignments to interface properties cannot be in destructuring patterns or for-of loops
reportInvalidInterfaceMemberDeclaration(object);
return;
}
Node assign = lvalue.getParent();
Node rvalue = assign.getSecondChild();
JSType rvalueType = getJSType(rvalue);
// Only 2 values are allowed for interface methods:
// goog.abstractMethod
// function () {};
// Other (non-method) interface properties must be stub declarations without assignments, e.g.
// someinterface.prototype.nonMethodProperty;
// which is why we enforce that `rvalueType.isFunctionType()`.
if (!rvalueType.isFunctionType()) {
reportInvalidInterfaceMemberDeclaration(object);
}
if (rvalue.isFunction() && !NodeUtil.isEmptyBlock(NodeUtil.getFunctionBody(rvalue))) {
String abstractMethodName = compiler.getCodingConvention().getAbstractMethodName();
compiler.report(JSError.make(object, INTERFACE_METHOD_NOT_EMPTY, abstractMethodName));
}
} | [
"private",
"void",
"visitInterfacePropertyAssignment",
"(",
"Node",
"object",
",",
"Node",
"lvalue",
")",
"{",
"if",
"(",
"!",
"lvalue",
".",
"getParent",
"(",
")",
".",
"isAssign",
"(",
")",
")",
"{",
"// assignments to interface properties cannot be in destructuring patterns or for-of loops",
"reportInvalidInterfaceMemberDeclaration",
"(",
"object",
")",
";",
"return",
";",
"}",
"Node",
"assign",
"=",
"lvalue",
".",
"getParent",
"(",
")",
";",
"Node",
"rvalue",
"=",
"assign",
".",
"getSecondChild",
"(",
")",
";",
"JSType",
"rvalueType",
"=",
"getJSType",
"(",
"rvalue",
")",
";",
"// Only 2 values are allowed for interface methods:",
"// goog.abstractMethod",
"// function () {};",
"// Other (non-method) interface properties must be stub declarations without assignments, e.g.",
"// someinterface.prototype.nonMethodProperty;",
"// which is why we enforce that `rvalueType.isFunctionType()`.",
"if",
"(",
"!",
"rvalueType",
".",
"isFunctionType",
"(",
")",
")",
"{",
"reportInvalidInterfaceMemberDeclaration",
"(",
"object",
")",
";",
"}",
"if",
"(",
"rvalue",
".",
"isFunction",
"(",
")",
"&&",
"!",
"NodeUtil",
".",
"isEmptyBlock",
"(",
"NodeUtil",
".",
"getFunctionBody",
"(",
"rvalue",
")",
")",
")",
"{",
"String",
"abstractMethodName",
"=",
"compiler",
".",
"getCodingConvention",
"(",
")",
".",
"getAbstractMethodName",
"(",
")",
";",
"compiler",
".",
"report",
"(",
"JSError",
".",
"make",
"(",
"object",
",",
"INTERFACE_METHOD_NOT_EMPTY",
",",
"abstractMethodName",
")",
")",
";",
"}",
"}"
] | Visits an lvalue node for cases such as
<pre>
interface.prototype.property = ...;
</pre> | [
"Visits",
"an",
"lvalue",
"node",
"for",
"cases",
"such",
"as"
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/TypeCheck.java#L1801-L1825 |
24,023 | google/closure-compiler | src/com/google/javascript/jscomp/TypeCheck.java | TypeCheck.visitName | boolean visitName(NodeTraversal t, Node n, Node parent) {
// At this stage, we need to determine whether this is a leaf
// node in an expression (which therefore needs to have a type
// assigned for it) versus some other decorative node that we
// can safely ignore. Function names, arguments (children of PARAM_LIST nodes) and
// variable declarations are ignored.
// TODO(user): remove this short-circuiting in favor of a
// pre order traversal of the FUNCTION, CATCH, PARAM_LIST and VAR nodes.
Token parentNodeType = parent.getToken();
if (parentNodeType == Token.FUNCTION
|| parentNodeType == Token.CATCH
|| parentNodeType == Token.PARAM_LIST
|| NodeUtil.isNameDeclaration(parent)
) {
return false;
}
// Not need to type first key in for-in or for-of.
if (NodeUtil.isEnhancedFor(parent) && parent.getFirstChild() == n) {
return false;
}
JSType type = n.getJSType();
if (type == null) {
type = getNativeType(UNKNOWN_TYPE);
TypedVar var = t.getTypedScope().getVar(n.getString());
if (var != null) {
JSType varType = var.getType();
if (varType != null) {
type = varType;
}
}
}
ensureTyped(n, type);
return true;
} | java | boolean visitName(NodeTraversal t, Node n, Node parent) {
// At this stage, we need to determine whether this is a leaf
// node in an expression (which therefore needs to have a type
// assigned for it) versus some other decorative node that we
// can safely ignore. Function names, arguments (children of PARAM_LIST nodes) and
// variable declarations are ignored.
// TODO(user): remove this short-circuiting in favor of a
// pre order traversal of the FUNCTION, CATCH, PARAM_LIST and VAR nodes.
Token parentNodeType = parent.getToken();
if (parentNodeType == Token.FUNCTION
|| parentNodeType == Token.CATCH
|| parentNodeType == Token.PARAM_LIST
|| NodeUtil.isNameDeclaration(parent)
) {
return false;
}
// Not need to type first key in for-in or for-of.
if (NodeUtil.isEnhancedFor(parent) && parent.getFirstChild() == n) {
return false;
}
JSType type = n.getJSType();
if (type == null) {
type = getNativeType(UNKNOWN_TYPE);
TypedVar var = t.getTypedScope().getVar(n.getString());
if (var != null) {
JSType varType = var.getType();
if (varType != null) {
type = varType;
}
}
}
ensureTyped(n, type);
return true;
} | [
"boolean",
"visitName",
"(",
"NodeTraversal",
"t",
",",
"Node",
"n",
",",
"Node",
"parent",
")",
"{",
"// At this stage, we need to determine whether this is a leaf",
"// node in an expression (which therefore needs to have a type",
"// assigned for it) versus some other decorative node that we",
"// can safely ignore. Function names, arguments (children of PARAM_LIST nodes) and",
"// variable declarations are ignored.",
"// TODO(user): remove this short-circuiting in favor of a",
"// pre order traversal of the FUNCTION, CATCH, PARAM_LIST and VAR nodes.",
"Token",
"parentNodeType",
"=",
"parent",
".",
"getToken",
"(",
")",
";",
"if",
"(",
"parentNodeType",
"==",
"Token",
".",
"FUNCTION",
"||",
"parentNodeType",
"==",
"Token",
".",
"CATCH",
"||",
"parentNodeType",
"==",
"Token",
".",
"PARAM_LIST",
"||",
"NodeUtil",
".",
"isNameDeclaration",
"(",
"parent",
")",
")",
"{",
"return",
"false",
";",
"}",
"// Not need to type first key in for-in or for-of.",
"if",
"(",
"NodeUtil",
".",
"isEnhancedFor",
"(",
"parent",
")",
"&&",
"parent",
".",
"getFirstChild",
"(",
")",
"==",
"n",
")",
"{",
"return",
"false",
";",
"}",
"JSType",
"type",
"=",
"n",
".",
"getJSType",
"(",
")",
";",
"if",
"(",
"type",
"==",
"null",
")",
"{",
"type",
"=",
"getNativeType",
"(",
"UNKNOWN_TYPE",
")",
";",
"TypedVar",
"var",
"=",
"t",
".",
"getTypedScope",
"(",
")",
".",
"getVar",
"(",
"n",
".",
"getString",
"(",
")",
")",
";",
"if",
"(",
"var",
"!=",
"null",
")",
"{",
"JSType",
"varType",
"=",
"var",
".",
"getType",
"(",
")",
";",
"if",
"(",
"varType",
"!=",
"null",
")",
"{",
"type",
"=",
"varType",
";",
"}",
"}",
"}",
"ensureTyped",
"(",
"n",
",",
"type",
")",
";",
"return",
"true",
";",
"}"
] | Visits a NAME node.
@param t The node traversal object that supplies context, such as the
scope chain to use in name lookups as well as error reporting.
@param n The node being visited.
@param parent The parent of the node n.
@return whether the node is typeable or not | [
"Visits",
"a",
"NAME",
"node",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/TypeCheck.java#L1844-L1879 |
24,024 | google/closure-compiler | src/com/google/javascript/jscomp/TypeCheck.java | TypeCheck.checkForOfTypes | private void checkForOfTypes(NodeTraversal t, Node forOf) {
Node lhs = forOf.getFirstChild();
Node iterable = forOf.getSecondChild();
JSType iterableType = getJSType(iterable);
JSType actualType;
if (forOf.isForAwaitOf()) {
Optional<JSType> maybeType =
validator.expectAutoboxesToIterableOrAsyncIterable(
iterable,
iterableType,
"Can only async iterate over a (non-null) Iterable or AsyncIterable type");
if (!maybeType.isPresent()) {
// Not iterable or async iterable, error reported by
// expectAutoboxesToIterableOrAsyncIterable.
return;
}
actualType = maybeType.get();
} else {
validator.expectAutoboxesToIterable(
iterable, iterableType, "Can only iterate over a (non-null) Iterable type");
actualType =
// Convert primitives to their wrapper type and remove null/undefined
// If iterable is a union type, autoboxes each member of the union.
iterableType
.autobox()
.getTemplateTypeMap()
.getResolvedTemplateType(typeRegistry.getIterableTemplate());
}
if (NodeUtil.isNameDeclaration(lhs)) {
// e.g. get "x" given the VAR in "for (var x of arr) {"
lhs = lhs.getFirstChild();
}
if (lhs.isDestructuringLhs()) {
// e.g. get `[x, y]` given the VAR in `for (var [x, y] of arr) {`
lhs = lhs.getFirstChild();
}
checkCanAssignToWithScope(
t,
forOf,
lhs,
actualType,
lhs.getJSDocInfo(),
"declared type of for-of loop variable does not match inferred type");
} | java | private void checkForOfTypes(NodeTraversal t, Node forOf) {
Node lhs = forOf.getFirstChild();
Node iterable = forOf.getSecondChild();
JSType iterableType = getJSType(iterable);
JSType actualType;
if (forOf.isForAwaitOf()) {
Optional<JSType> maybeType =
validator.expectAutoboxesToIterableOrAsyncIterable(
iterable,
iterableType,
"Can only async iterate over a (non-null) Iterable or AsyncIterable type");
if (!maybeType.isPresent()) {
// Not iterable or async iterable, error reported by
// expectAutoboxesToIterableOrAsyncIterable.
return;
}
actualType = maybeType.get();
} else {
validator.expectAutoboxesToIterable(
iterable, iterableType, "Can only iterate over a (non-null) Iterable type");
actualType =
// Convert primitives to their wrapper type and remove null/undefined
// If iterable is a union type, autoboxes each member of the union.
iterableType
.autobox()
.getTemplateTypeMap()
.getResolvedTemplateType(typeRegistry.getIterableTemplate());
}
if (NodeUtil.isNameDeclaration(lhs)) {
// e.g. get "x" given the VAR in "for (var x of arr) {"
lhs = lhs.getFirstChild();
}
if (lhs.isDestructuringLhs()) {
// e.g. get `[x, y]` given the VAR in `for (var [x, y] of arr) {`
lhs = lhs.getFirstChild();
}
checkCanAssignToWithScope(
t,
forOf,
lhs,
actualType,
lhs.getJSDocInfo(),
"declared type of for-of loop variable does not match inferred type");
} | [
"private",
"void",
"checkForOfTypes",
"(",
"NodeTraversal",
"t",
",",
"Node",
"forOf",
")",
"{",
"Node",
"lhs",
"=",
"forOf",
".",
"getFirstChild",
"(",
")",
";",
"Node",
"iterable",
"=",
"forOf",
".",
"getSecondChild",
"(",
")",
";",
"JSType",
"iterableType",
"=",
"getJSType",
"(",
"iterable",
")",
";",
"JSType",
"actualType",
";",
"if",
"(",
"forOf",
".",
"isForAwaitOf",
"(",
")",
")",
"{",
"Optional",
"<",
"JSType",
">",
"maybeType",
"=",
"validator",
".",
"expectAutoboxesToIterableOrAsyncIterable",
"(",
"iterable",
",",
"iterableType",
",",
"\"Can only async iterate over a (non-null) Iterable or AsyncIterable type\"",
")",
";",
"if",
"(",
"!",
"maybeType",
".",
"isPresent",
"(",
")",
")",
"{",
"// Not iterable or async iterable, error reported by",
"// expectAutoboxesToIterableOrAsyncIterable.",
"return",
";",
"}",
"actualType",
"=",
"maybeType",
".",
"get",
"(",
")",
";",
"}",
"else",
"{",
"validator",
".",
"expectAutoboxesToIterable",
"(",
"iterable",
",",
"iterableType",
",",
"\"Can only iterate over a (non-null) Iterable type\"",
")",
";",
"actualType",
"=",
"// Convert primitives to their wrapper type and remove null/undefined",
"// If iterable is a union type, autoboxes each member of the union.",
"iterableType",
".",
"autobox",
"(",
")",
".",
"getTemplateTypeMap",
"(",
")",
".",
"getResolvedTemplateType",
"(",
"typeRegistry",
".",
"getIterableTemplate",
"(",
")",
")",
";",
"}",
"if",
"(",
"NodeUtil",
".",
"isNameDeclaration",
"(",
"lhs",
")",
")",
"{",
"// e.g. get \"x\" given the VAR in \"for (var x of arr) {\"",
"lhs",
"=",
"lhs",
".",
"getFirstChild",
"(",
")",
";",
"}",
"if",
"(",
"lhs",
".",
"isDestructuringLhs",
"(",
")",
")",
"{",
"// e.g. get `[x, y]` given the VAR in `for (var [x, y] of arr) {`",
"lhs",
"=",
"lhs",
".",
"getFirstChild",
"(",
")",
";",
"}",
"checkCanAssignToWithScope",
"(",
"t",
",",
"forOf",
",",
"lhs",
",",
"actualType",
",",
"lhs",
".",
"getJSDocInfo",
"(",
")",
",",
"\"declared type of for-of loop variable does not match inferred type\"",
")",
";",
"}"
] | Visits the loop variable of a FOR_OF and FOR_AWAIT_OF and verifies the type being assigned to
it. | [
"Visits",
"the",
"loop",
"variable",
"of",
"a",
"FOR_OF",
"and",
"FOR_AWAIT_OF",
"and",
"verifies",
"the",
"type",
"being",
"assigned",
"to",
"it",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/TypeCheck.java#L1885-L1934 |
24,025 | google/closure-compiler | src/com/google/javascript/jscomp/TypeCheck.java | TypeCheck.visitGetProp | private void visitGetProp(NodeTraversal t, Node n) {
// obj.prop or obj.method()
// Lots of types can appear on the left, a call to a void function can
// never be on the left. getPropertyType will decide what is acceptable
// and what isn't.
Node property = n.getLastChild();
Node objNode = n.getFirstChild();
JSType childType = getJSType(objNode);
if (childType.isDict()) {
report(property, TypeValidator.ILLEGAL_PROPERTY_ACCESS, "'.'", "dict");
} else if (validator.expectNotNullOrUndefined(t, n, childType,
"No properties on this expression", getNativeType(OBJECT_TYPE))) {
checkPropertyAccessForGetProp(n);
}
ensureTyped(n);
} | java | private void visitGetProp(NodeTraversal t, Node n) {
// obj.prop or obj.method()
// Lots of types can appear on the left, a call to a void function can
// never be on the left. getPropertyType will decide what is acceptable
// and what isn't.
Node property = n.getLastChild();
Node objNode = n.getFirstChild();
JSType childType = getJSType(objNode);
if (childType.isDict()) {
report(property, TypeValidator.ILLEGAL_PROPERTY_ACCESS, "'.'", "dict");
} else if (validator.expectNotNullOrUndefined(t, n, childType,
"No properties on this expression", getNativeType(OBJECT_TYPE))) {
checkPropertyAccessForGetProp(n);
}
ensureTyped(n);
} | [
"private",
"void",
"visitGetProp",
"(",
"NodeTraversal",
"t",
",",
"Node",
"n",
")",
"{",
"// obj.prop or obj.method()",
"// Lots of types can appear on the left, a call to a void function can",
"// never be on the left. getPropertyType will decide what is acceptable",
"// and what isn't.",
"Node",
"property",
"=",
"n",
".",
"getLastChild",
"(",
")",
";",
"Node",
"objNode",
"=",
"n",
".",
"getFirstChild",
"(",
")",
";",
"JSType",
"childType",
"=",
"getJSType",
"(",
"objNode",
")",
";",
"if",
"(",
"childType",
".",
"isDict",
"(",
")",
")",
"{",
"report",
"(",
"property",
",",
"TypeValidator",
".",
"ILLEGAL_PROPERTY_ACCESS",
",",
"\"'.'\"",
",",
"\"dict\"",
")",
";",
"}",
"else",
"if",
"(",
"validator",
".",
"expectNotNullOrUndefined",
"(",
"t",
",",
"n",
",",
"childType",
",",
"\"No properties on this expression\"",
",",
"getNativeType",
"(",
"OBJECT_TYPE",
")",
")",
")",
"{",
"checkPropertyAccessForGetProp",
"(",
"n",
")",
";",
"}",
"ensureTyped",
"(",
"n",
")",
";",
"}"
] | Visits a GETPROP node.
@param t The node traversal object that supplies context, such as the scope chain to use in
name lookups as well as error reporting.
@param n The node being visited. | [
"Visits",
"a",
"GETPROP",
"node",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/TypeCheck.java#L1943-L1959 |
24,026 | google/closure-compiler | src/com/google/javascript/jscomp/TypeCheck.java | TypeCheck.visitGetElem | private void visitGetElem(Node n) {
validator.expectIndexMatch(n, getJSType(n.getFirstChild()), getJSType(n.getLastChild()));
ensureTyped(n);
} | java | private void visitGetElem(Node n) {
validator.expectIndexMatch(n, getJSType(n.getFirstChild()), getJSType(n.getLastChild()));
ensureTyped(n);
} | [
"private",
"void",
"visitGetElem",
"(",
"Node",
"n",
")",
"{",
"validator",
".",
"expectIndexMatch",
"(",
"n",
",",
"getJSType",
"(",
"n",
".",
"getFirstChild",
"(",
")",
")",
",",
"getJSType",
"(",
"n",
".",
"getLastChild",
"(",
")",
")",
")",
";",
"ensureTyped",
"(",
"n",
")",
";",
"}"
] | Visits a GETELEM node.
@param n The node being visited. | [
"Visits",
"a",
"GETELEM",
"node",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/TypeCheck.java#L2217-L2220 |
24,027 | google/closure-compiler | src/com/google/javascript/jscomp/TypeCheck.java | TypeCheck.visitVar | private void visitVar(NodeTraversal t, Node n) {
// Handle var declarations in for-of loops separately from regular var declarations.
if (n.getParent().isForOf() || n.getParent().isForIn()) {
return;
}
// TODO(nicksantos): Fix this so that the doc info always shows up
// on the NAME node. We probably want to wait for the parser
// merge to fix this.
JSDocInfo varInfo = n.hasOneChild() ? n.getJSDocInfo() : null;
for (Node child : n.children()) {
if (child.isName()) {
Node value = child.getFirstChild();
if (value != null) {
JSType valueType = getJSType(value);
JSDocInfo info = child.getJSDocInfo();
if (info == null) {
info = varInfo;
}
checkEnumAlias(t, info, valueType, value);
checkCanAssignToWithScope(t, value, child, valueType, info, "initializing variable");
}
} else {
checkState(child.isDestructuringLhs(), child);
Node name = child.getFirstChild();
Node value = child.getSecondChild();
JSType valueType = getJSType(value);
checkCanAssignToWithScope(
t, child, name, valueType, /* info= */ null, "initializing variable");
}
}
} | java | private void visitVar(NodeTraversal t, Node n) {
// Handle var declarations in for-of loops separately from regular var declarations.
if (n.getParent().isForOf() || n.getParent().isForIn()) {
return;
}
// TODO(nicksantos): Fix this so that the doc info always shows up
// on the NAME node. We probably want to wait for the parser
// merge to fix this.
JSDocInfo varInfo = n.hasOneChild() ? n.getJSDocInfo() : null;
for (Node child : n.children()) {
if (child.isName()) {
Node value = child.getFirstChild();
if (value != null) {
JSType valueType = getJSType(value);
JSDocInfo info = child.getJSDocInfo();
if (info == null) {
info = varInfo;
}
checkEnumAlias(t, info, valueType, value);
checkCanAssignToWithScope(t, value, child, valueType, info, "initializing variable");
}
} else {
checkState(child.isDestructuringLhs(), child);
Node name = child.getFirstChild();
Node value = child.getSecondChild();
JSType valueType = getJSType(value);
checkCanAssignToWithScope(
t, child, name, valueType, /* info= */ null, "initializing variable");
}
}
} | [
"private",
"void",
"visitVar",
"(",
"NodeTraversal",
"t",
",",
"Node",
"n",
")",
"{",
"// Handle var declarations in for-of loops separately from regular var declarations.",
"if",
"(",
"n",
".",
"getParent",
"(",
")",
".",
"isForOf",
"(",
")",
"||",
"n",
".",
"getParent",
"(",
")",
".",
"isForIn",
"(",
")",
")",
"{",
"return",
";",
"}",
"// TODO(nicksantos): Fix this so that the doc info always shows up",
"// on the NAME node. We probably want to wait for the parser",
"// merge to fix this.",
"JSDocInfo",
"varInfo",
"=",
"n",
".",
"hasOneChild",
"(",
")",
"?",
"n",
".",
"getJSDocInfo",
"(",
")",
":",
"null",
";",
"for",
"(",
"Node",
"child",
":",
"n",
".",
"children",
"(",
")",
")",
"{",
"if",
"(",
"child",
".",
"isName",
"(",
")",
")",
"{",
"Node",
"value",
"=",
"child",
".",
"getFirstChild",
"(",
")",
";",
"if",
"(",
"value",
"!=",
"null",
")",
"{",
"JSType",
"valueType",
"=",
"getJSType",
"(",
"value",
")",
";",
"JSDocInfo",
"info",
"=",
"child",
".",
"getJSDocInfo",
"(",
")",
";",
"if",
"(",
"info",
"==",
"null",
")",
"{",
"info",
"=",
"varInfo",
";",
"}",
"checkEnumAlias",
"(",
"t",
",",
"info",
",",
"valueType",
",",
"value",
")",
";",
"checkCanAssignToWithScope",
"(",
"t",
",",
"value",
",",
"child",
",",
"valueType",
",",
"info",
",",
"\"initializing variable\"",
")",
";",
"}",
"}",
"else",
"{",
"checkState",
"(",
"child",
".",
"isDestructuringLhs",
"(",
")",
",",
"child",
")",
";",
"Node",
"name",
"=",
"child",
".",
"getFirstChild",
"(",
")",
";",
"Node",
"value",
"=",
"child",
".",
"getSecondChild",
"(",
")",
";",
"JSType",
"valueType",
"=",
"getJSType",
"(",
"value",
")",
";",
"checkCanAssignToWithScope",
"(",
"t",
",",
"child",
",",
"name",
",",
"valueType",
",",
"/* info= */",
"null",
",",
"\"initializing variable\"",
")",
";",
"}",
"}",
"}"
] | Visits a VAR node.
@param t The node traversal object that supplies context, such as the
scope chain to use in name lookups as well as error reporting.
@param n The node being visited. | [
"Visits",
"a",
"VAR",
"node",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/TypeCheck.java#L2229-L2262 |
24,028 | google/closure-compiler | src/com/google/javascript/jscomp/TypeCheck.java | TypeCheck.visitNew | private void visitNew(Node n) {
Node constructor = n.getFirstChild();
JSType type = getJSType(constructor).restrictByNotNullOrUndefined();
if (!couldBeAConstructor(type)
|| type.isEquivalentTo(typeRegistry.getNativeType(SYMBOL_OBJECT_FUNCTION_TYPE))) {
report(n, NOT_A_CONSTRUCTOR);
ensureTyped(n);
return;
}
FunctionType fnType = type.toMaybeFunctionType();
if (fnType != null && fnType.hasInstanceType()) {
FunctionType ctorType = fnType.getInstanceType().getConstructor();
if (ctorType != null && ctorType.isAbstract()) {
report(n, INSTANTIATE_ABSTRACT_CLASS);
}
visitArgumentList(n, fnType);
ensureTyped(n, fnType.getInstanceType());
} else {
ensureTyped(n);
}
} | java | private void visitNew(Node n) {
Node constructor = n.getFirstChild();
JSType type = getJSType(constructor).restrictByNotNullOrUndefined();
if (!couldBeAConstructor(type)
|| type.isEquivalentTo(typeRegistry.getNativeType(SYMBOL_OBJECT_FUNCTION_TYPE))) {
report(n, NOT_A_CONSTRUCTOR);
ensureTyped(n);
return;
}
FunctionType fnType = type.toMaybeFunctionType();
if (fnType != null && fnType.hasInstanceType()) {
FunctionType ctorType = fnType.getInstanceType().getConstructor();
if (ctorType != null && ctorType.isAbstract()) {
report(n, INSTANTIATE_ABSTRACT_CLASS);
}
visitArgumentList(n, fnType);
ensureTyped(n, fnType.getInstanceType());
} else {
ensureTyped(n);
}
} | [
"private",
"void",
"visitNew",
"(",
"Node",
"n",
")",
"{",
"Node",
"constructor",
"=",
"n",
".",
"getFirstChild",
"(",
")",
";",
"JSType",
"type",
"=",
"getJSType",
"(",
"constructor",
")",
".",
"restrictByNotNullOrUndefined",
"(",
")",
";",
"if",
"(",
"!",
"couldBeAConstructor",
"(",
"type",
")",
"||",
"type",
".",
"isEquivalentTo",
"(",
"typeRegistry",
".",
"getNativeType",
"(",
"SYMBOL_OBJECT_FUNCTION_TYPE",
")",
")",
")",
"{",
"report",
"(",
"n",
",",
"NOT_A_CONSTRUCTOR",
")",
";",
"ensureTyped",
"(",
"n",
")",
";",
"return",
";",
"}",
"FunctionType",
"fnType",
"=",
"type",
".",
"toMaybeFunctionType",
"(",
")",
";",
"if",
"(",
"fnType",
"!=",
"null",
"&&",
"fnType",
".",
"hasInstanceType",
"(",
")",
")",
"{",
"FunctionType",
"ctorType",
"=",
"fnType",
".",
"getInstanceType",
"(",
")",
".",
"getConstructor",
"(",
")",
";",
"if",
"(",
"ctorType",
"!=",
"null",
"&&",
"ctorType",
".",
"isAbstract",
"(",
")",
")",
"{",
"report",
"(",
"n",
",",
"INSTANTIATE_ABSTRACT_CLASS",
")",
";",
"}",
"visitArgumentList",
"(",
"n",
",",
"fnType",
")",
";",
"ensureTyped",
"(",
"n",
",",
"fnType",
".",
"getInstanceType",
"(",
")",
")",
";",
"}",
"else",
"{",
"ensureTyped",
"(",
"n",
")",
";",
"}",
"}"
] | Visits a NEW node. | [
"Visits",
"a",
"NEW",
"node",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/TypeCheck.java#L2265-L2286 |
24,029 | google/closure-compiler | src/com/google/javascript/jscomp/TypeCheck.java | TypeCheck.checkInterfaceConflictProperties | private void checkInterfaceConflictProperties(
Node n,
String functionName,
Map<String, ObjectType> properties,
Map<String, ObjectType> currentProperties,
ObjectType interfaceType) {
ObjectType implicitProto = interfaceType.getImplicitPrototype();
Set<String> currentPropertyNames;
if (implicitProto == null) {
// This can be the case if interfaceType is proxy to a non-existent
// object (which is a bad type annotation, but shouldn't crash).
currentPropertyNames = ImmutableSet.of();
} else {
currentPropertyNames = implicitProto.getOwnPropertyNames();
}
for (String name : currentPropertyNames) {
ObjectType oType = properties.get(name);
currentProperties.put(name, interfaceType);
if (oType != null) {
JSType thisPropType = interfaceType.getPropertyType(name);
JSType oPropType = oType.getPropertyType(name);
if (thisPropType.isSubtype(oPropType, this.subtypingMode)
|| oPropType.isSubtype(thisPropType, this.subtypingMode)
|| (thisPropType.isFunctionType()
&& oPropType.isFunctionType()
&& thisPropType
.toMaybeFunctionType()
.hasEqualCallType(oPropType.toMaybeFunctionType()))) {
continue;
}
compiler.report(
JSError.make(
n,
INCOMPATIBLE_EXTENDED_PROPERTY_TYPE,
functionName,
name,
oType.toString(),
interfaceType.toString()));
}
}
for (ObjectType iType : interfaceType.getCtorExtendedInterfaces()) {
checkInterfaceConflictProperties(n, functionName, properties, currentProperties, iType);
}
} | java | private void checkInterfaceConflictProperties(
Node n,
String functionName,
Map<String, ObjectType> properties,
Map<String, ObjectType> currentProperties,
ObjectType interfaceType) {
ObjectType implicitProto = interfaceType.getImplicitPrototype();
Set<String> currentPropertyNames;
if (implicitProto == null) {
// This can be the case if interfaceType is proxy to a non-existent
// object (which is a bad type annotation, but shouldn't crash).
currentPropertyNames = ImmutableSet.of();
} else {
currentPropertyNames = implicitProto.getOwnPropertyNames();
}
for (String name : currentPropertyNames) {
ObjectType oType = properties.get(name);
currentProperties.put(name, interfaceType);
if (oType != null) {
JSType thisPropType = interfaceType.getPropertyType(name);
JSType oPropType = oType.getPropertyType(name);
if (thisPropType.isSubtype(oPropType, this.subtypingMode)
|| oPropType.isSubtype(thisPropType, this.subtypingMode)
|| (thisPropType.isFunctionType()
&& oPropType.isFunctionType()
&& thisPropType
.toMaybeFunctionType()
.hasEqualCallType(oPropType.toMaybeFunctionType()))) {
continue;
}
compiler.report(
JSError.make(
n,
INCOMPATIBLE_EXTENDED_PROPERTY_TYPE,
functionName,
name,
oType.toString(),
interfaceType.toString()));
}
}
for (ObjectType iType : interfaceType.getCtorExtendedInterfaces()) {
checkInterfaceConflictProperties(n, functionName, properties, currentProperties, iType);
}
} | [
"private",
"void",
"checkInterfaceConflictProperties",
"(",
"Node",
"n",
",",
"String",
"functionName",
",",
"Map",
"<",
"String",
",",
"ObjectType",
">",
"properties",
",",
"Map",
"<",
"String",
",",
"ObjectType",
">",
"currentProperties",
",",
"ObjectType",
"interfaceType",
")",
"{",
"ObjectType",
"implicitProto",
"=",
"interfaceType",
".",
"getImplicitPrototype",
"(",
")",
";",
"Set",
"<",
"String",
">",
"currentPropertyNames",
";",
"if",
"(",
"implicitProto",
"==",
"null",
")",
"{",
"// This can be the case if interfaceType is proxy to a non-existent",
"// object (which is a bad type annotation, but shouldn't crash).",
"currentPropertyNames",
"=",
"ImmutableSet",
".",
"of",
"(",
")",
";",
"}",
"else",
"{",
"currentPropertyNames",
"=",
"implicitProto",
".",
"getOwnPropertyNames",
"(",
")",
";",
"}",
"for",
"(",
"String",
"name",
":",
"currentPropertyNames",
")",
"{",
"ObjectType",
"oType",
"=",
"properties",
".",
"get",
"(",
"name",
")",
";",
"currentProperties",
".",
"put",
"(",
"name",
",",
"interfaceType",
")",
";",
"if",
"(",
"oType",
"!=",
"null",
")",
"{",
"JSType",
"thisPropType",
"=",
"interfaceType",
".",
"getPropertyType",
"(",
"name",
")",
";",
"JSType",
"oPropType",
"=",
"oType",
".",
"getPropertyType",
"(",
"name",
")",
";",
"if",
"(",
"thisPropType",
".",
"isSubtype",
"(",
"oPropType",
",",
"this",
".",
"subtypingMode",
")",
"||",
"oPropType",
".",
"isSubtype",
"(",
"thisPropType",
",",
"this",
".",
"subtypingMode",
")",
"||",
"(",
"thisPropType",
".",
"isFunctionType",
"(",
")",
"&&",
"oPropType",
".",
"isFunctionType",
"(",
")",
"&&",
"thisPropType",
".",
"toMaybeFunctionType",
"(",
")",
".",
"hasEqualCallType",
"(",
"oPropType",
".",
"toMaybeFunctionType",
"(",
")",
")",
")",
")",
"{",
"continue",
";",
"}",
"compiler",
".",
"report",
"(",
"JSError",
".",
"make",
"(",
"n",
",",
"INCOMPATIBLE_EXTENDED_PROPERTY_TYPE",
",",
"functionName",
",",
"name",
",",
"oType",
".",
"toString",
"(",
")",
",",
"interfaceType",
".",
"toString",
"(",
")",
")",
")",
";",
"}",
"}",
"for",
"(",
"ObjectType",
"iType",
":",
"interfaceType",
".",
"getCtorExtendedInterfaces",
"(",
")",
")",
"{",
"checkInterfaceConflictProperties",
"(",
"n",
",",
"functionName",
",",
"properties",
",",
"currentProperties",
",",
"iType",
")",
";",
"}",
"}"
] | Check whether there's any property conflict for for a particular super interface
@param n The node being visited
@param functionName The function name being checked
@param properties The property names in the super interfaces that have been visited
@param currentProperties The property names in the super interface that have been visited
@param interfaceType The super interface that is being visited | [
"Check",
"whether",
"there",
"s",
"any",
"property",
"conflict",
"for",
"for",
"a",
"particular",
"super",
"interface"
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/TypeCheck.java#L2301-L2344 |
24,030 | google/closure-compiler | src/com/google/javascript/jscomp/TypeCheck.java | TypeCheck.visitClass | private void visitClass(Node n) {
FunctionType functionType = JSType.toMaybeFunctionType(n.getJSType());
Node extendsClause = n.getSecondChild();
if (!extendsClause.isEmpty()) {
// Ensure that the `extends` clause is actually a constructor or interface. If it is, but
// it's the wrong one then checkConstructor or checkInterface will warn.
JSType superType = extendsClause.getJSType();
if (superType.isConstructor() || superType.isInterface()) {
validator.expectExtends(n, functionType, superType.toMaybeFunctionType());
} else if (!superType.isUnknownType()) {
// Only give this error for supertypes *known* to be wrong - unresolved types are OK here.
compiler.report(
JSError.make(
n,
CONFLICTING_EXTENDED_TYPE,
functionType.isConstructor() ? "constructor" : "interface",
getBestFunctionName(n)));
}
}
if (functionType.isConstructor()) {
checkConstructor(n, functionType);
} else if (functionType.isInterface()) {
checkInterface(n, functionType);
} else {
throw new IllegalStateException(
"CLASS node's type must be either constructor or interface: " + functionType);
}
} | java | private void visitClass(Node n) {
FunctionType functionType = JSType.toMaybeFunctionType(n.getJSType());
Node extendsClause = n.getSecondChild();
if (!extendsClause.isEmpty()) {
// Ensure that the `extends` clause is actually a constructor or interface. If it is, but
// it's the wrong one then checkConstructor or checkInterface will warn.
JSType superType = extendsClause.getJSType();
if (superType.isConstructor() || superType.isInterface()) {
validator.expectExtends(n, functionType, superType.toMaybeFunctionType());
} else if (!superType.isUnknownType()) {
// Only give this error for supertypes *known* to be wrong - unresolved types are OK here.
compiler.report(
JSError.make(
n,
CONFLICTING_EXTENDED_TYPE,
functionType.isConstructor() ? "constructor" : "interface",
getBestFunctionName(n)));
}
}
if (functionType.isConstructor()) {
checkConstructor(n, functionType);
} else if (functionType.isInterface()) {
checkInterface(n, functionType);
} else {
throw new IllegalStateException(
"CLASS node's type must be either constructor or interface: " + functionType);
}
} | [
"private",
"void",
"visitClass",
"(",
"Node",
"n",
")",
"{",
"FunctionType",
"functionType",
"=",
"JSType",
".",
"toMaybeFunctionType",
"(",
"n",
".",
"getJSType",
"(",
")",
")",
";",
"Node",
"extendsClause",
"=",
"n",
".",
"getSecondChild",
"(",
")",
";",
"if",
"(",
"!",
"extendsClause",
".",
"isEmpty",
"(",
")",
")",
"{",
"// Ensure that the `extends` clause is actually a constructor or interface. If it is, but",
"// it's the wrong one then checkConstructor or checkInterface will warn.",
"JSType",
"superType",
"=",
"extendsClause",
".",
"getJSType",
"(",
")",
";",
"if",
"(",
"superType",
".",
"isConstructor",
"(",
")",
"||",
"superType",
".",
"isInterface",
"(",
")",
")",
"{",
"validator",
".",
"expectExtends",
"(",
"n",
",",
"functionType",
",",
"superType",
".",
"toMaybeFunctionType",
"(",
")",
")",
";",
"}",
"else",
"if",
"(",
"!",
"superType",
".",
"isUnknownType",
"(",
")",
")",
"{",
"// Only give this error for supertypes *known* to be wrong - unresolved types are OK here.",
"compiler",
".",
"report",
"(",
"JSError",
".",
"make",
"(",
"n",
",",
"CONFLICTING_EXTENDED_TYPE",
",",
"functionType",
".",
"isConstructor",
"(",
")",
"?",
"\"constructor\"",
":",
"\"interface\"",
",",
"getBestFunctionName",
"(",
"n",
")",
")",
")",
";",
"}",
"}",
"if",
"(",
"functionType",
".",
"isConstructor",
"(",
")",
")",
"{",
"checkConstructor",
"(",
"n",
",",
"functionType",
")",
";",
"}",
"else",
"if",
"(",
"functionType",
".",
"isInterface",
"(",
")",
")",
"{",
"checkInterface",
"(",
"n",
",",
"functionType",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"IllegalStateException",
"(",
"\"CLASS node's type must be either constructor or interface: \"",
"+",
"functionType",
")",
";",
"}",
"}"
] | Visits a CLASS node. | [
"Visits",
"a",
"CLASS",
"node",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/TypeCheck.java#L2382-L2409 |
24,031 | google/closure-compiler | src/com/google/javascript/jscomp/TypeCheck.java | TypeCheck.checkConstructor | private void checkConstructor(Node n, FunctionType functionType) {
FunctionType baseConstructor = functionType.getSuperClassConstructor();
if (!Objects.equals(baseConstructor, getNativeType(OBJECT_FUNCTION_TYPE))
&& baseConstructor != null
&& baseConstructor.isInterface()) {
// Warn if a class extends an interface.
compiler.report(
JSError.make(n, CONFLICTING_EXTENDED_TYPE, "constructor", getBestFunctionName(n)));
} else {
if (n.isFunction()
&& baseConstructor != null
&& baseConstructor.getSource() != null
&& baseConstructor.getSource().isEs6Class()
&& !functionType.getSource().isEs6Class()) {
// Warn if an ES5 class extends an ES6 class.
compiler.report(
JSError.make(
n,
ES5_CLASS_EXTENDING_ES6_CLASS,
functionType.getDisplayName(),
baseConstructor.getDisplayName()));
}
// Warn if any interface property is missing or incorrect
for (JSType baseInterface : functionType.getImplementedInterfaces()) {
boolean badImplementedType = false;
ObjectType baseInterfaceObj = ObjectType.cast(baseInterface);
if (baseInterfaceObj != null) {
FunctionType interfaceConstructor =
baseInterfaceObj.getConstructor();
if (interfaceConstructor != null && !interfaceConstructor.isInterface()) {
badImplementedType = true;
}
} else {
badImplementedType = true;
}
if (badImplementedType) {
report(n, BAD_IMPLEMENTED_TYPE, getBestFunctionName(n));
}
}
// check properties
validator.expectAllInterfaceProperties(n, functionType);
if (!functionType.isAbstract()) {
validator.expectAbstractMethodsImplemented(n, functionType);
}
}
} | java | private void checkConstructor(Node n, FunctionType functionType) {
FunctionType baseConstructor = functionType.getSuperClassConstructor();
if (!Objects.equals(baseConstructor, getNativeType(OBJECT_FUNCTION_TYPE))
&& baseConstructor != null
&& baseConstructor.isInterface()) {
// Warn if a class extends an interface.
compiler.report(
JSError.make(n, CONFLICTING_EXTENDED_TYPE, "constructor", getBestFunctionName(n)));
} else {
if (n.isFunction()
&& baseConstructor != null
&& baseConstructor.getSource() != null
&& baseConstructor.getSource().isEs6Class()
&& !functionType.getSource().isEs6Class()) {
// Warn if an ES5 class extends an ES6 class.
compiler.report(
JSError.make(
n,
ES5_CLASS_EXTENDING_ES6_CLASS,
functionType.getDisplayName(),
baseConstructor.getDisplayName()));
}
// Warn if any interface property is missing or incorrect
for (JSType baseInterface : functionType.getImplementedInterfaces()) {
boolean badImplementedType = false;
ObjectType baseInterfaceObj = ObjectType.cast(baseInterface);
if (baseInterfaceObj != null) {
FunctionType interfaceConstructor =
baseInterfaceObj.getConstructor();
if (interfaceConstructor != null && !interfaceConstructor.isInterface()) {
badImplementedType = true;
}
} else {
badImplementedType = true;
}
if (badImplementedType) {
report(n, BAD_IMPLEMENTED_TYPE, getBestFunctionName(n));
}
}
// check properties
validator.expectAllInterfaceProperties(n, functionType);
if (!functionType.isAbstract()) {
validator.expectAbstractMethodsImplemented(n, functionType);
}
}
} | [
"private",
"void",
"checkConstructor",
"(",
"Node",
"n",
",",
"FunctionType",
"functionType",
")",
"{",
"FunctionType",
"baseConstructor",
"=",
"functionType",
".",
"getSuperClassConstructor",
"(",
")",
";",
"if",
"(",
"!",
"Objects",
".",
"equals",
"(",
"baseConstructor",
",",
"getNativeType",
"(",
"OBJECT_FUNCTION_TYPE",
")",
")",
"&&",
"baseConstructor",
"!=",
"null",
"&&",
"baseConstructor",
".",
"isInterface",
"(",
")",
")",
"{",
"// Warn if a class extends an interface.",
"compiler",
".",
"report",
"(",
"JSError",
".",
"make",
"(",
"n",
",",
"CONFLICTING_EXTENDED_TYPE",
",",
"\"constructor\"",
",",
"getBestFunctionName",
"(",
"n",
")",
")",
")",
";",
"}",
"else",
"{",
"if",
"(",
"n",
".",
"isFunction",
"(",
")",
"&&",
"baseConstructor",
"!=",
"null",
"&&",
"baseConstructor",
".",
"getSource",
"(",
")",
"!=",
"null",
"&&",
"baseConstructor",
".",
"getSource",
"(",
")",
".",
"isEs6Class",
"(",
")",
"&&",
"!",
"functionType",
".",
"getSource",
"(",
")",
".",
"isEs6Class",
"(",
")",
")",
"{",
"// Warn if an ES5 class extends an ES6 class.",
"compiler",
".",
"report",
"(",
"JSError",
".",
"make",
"(",
"n",
",",
"ES5_CLASS_EXTENDING_ES6_CLASS",
",",
"functionType",
".",
"getDisplayName",
"(",
")",
",",
"baseConstructor",
".",
"getDisplayName",
"(",
")",
")",
")",
";",
"}",
"// Warn if any interface property is missing or incorrect",
"for",
"(",
"JSType",
"baseInterface",
":",
"functionType",
".",
"getImplementedInterfaces",
"(",
")",
")",
"{",
"boolean",
"badImplementedType",
"=",
"false",
";",
"ObjectType",
"baseInterfaceObj",
"=",
"ObjectType",
".",
"cast",
"(",
"baseInterface",
")",
";",
"if",
"(",
"baseInterfaceObj",
"!=",
"null",
")",
"{",
"FunctionType",
"interfaceConstructor",
"=",
"baseInterfaceObj",
".",
"getConstructor",
"(",
")",
";",
"if",
"(",
"interfaceConstructor",
"!=",
"null",
"&&",
"!",
"interfaceConstructor",
".",
"isInterface",
"(",
")",
")",
"{",
"badImplementedType",
"=",
"true",
";",
"}",
"}",
"else",
"{",
"badImplementedType",
"=",
"true",
";",
"}",
"if",
"(",
"badImplementedType",
")",
"{",
"report",
"(",
"n",
",",
"BAD_IMPLEMENTED_TYPE",
",",
"getBestFunctionName",
"(",
"n",
")",
")",
";",
"}",
"}",
"// check properties",
"validator",
".",
"expectAllInterfaceProperties",
"(",
"n",
",",
"functionType",
")",
";",
"if",
"(",
"!",
"functionType",
".",
"isAbstract",
"(",
")",
")",
"{",
"validator",
".",
"expectAbstractMethodsImplemented",
"(",
"n",
",",
"functionType",
")",
";",
"}",
"}",
"}"
] | Checks a constructor, which may be either an ES5-style FUNCTION node, or a CLASS node. | [
"Checks",
"a",
"constructor",
"which",
"may",
"be",
"either",
"an",
"ES5",
"-",
"style",
"FUNCTION",
"node",
"or",
"a",
"CLASS",
"node",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/TypeCheck.java#L2412-L2458 |
24,032 | google/closure-compiler | src/com/google/javascript/jscomp/TypeCheck.java | TypeCheck.checkInterface | private void checkInterface(Node n, FunctionType functionType) {
// Interface must extend only interfaces
for (ObjectType extInterface : functionType.getExtendedInterfaces()) {
if (extInterface.getConstructor() != null && !extInterface.getConstructor().isInterface()) {
compiler.report(
JSError.make(n, CONFLICTING_EXTENDED_TYPE, "interface", getBestFunctionName(n)));
}
}
// Check whether the extended interfaces have any conflicts
if (functionType.getExtendedInterfacesCount() > 1) {
// Only check when extending more than one interfaces
HashMap<String, ObjectType> properties = new HashMap<>();
LinkedHashMap<String, ObjectType> currentProperties = new LinkedHashMap<>();
for (ObjectType interfaceType : functionType.getExtendedInterfaces()) {
currentProperties.clear();
checkInterfaceConflictProperties(
n, getBestFunctionName(n), properties, currentProperties, interfaceType);
properties.putAll(currentProperties);
}
}
List<FunctionType> loopPath = functionType.checkExtendsLoop();
if (loopPath != null) {
String strPath = "";
for (int i = 0; i < loopPath.size() - 1; i++) {
strPath += loopPath.get(i).getDisplayName() + " -> ";
}
strPath += Iterables.getLast(loopPath).getDisplayName();
compiler.report(
JSError.make(n, INTERFACE_EXTENDS_LOOP, loopPath.get(0).getDisplayName(), strPath));
}
} | java | private void checkInterface(Node n, FunctionType functionType) {
// Interface must extend only interfaces
for (ObjectType extInterface : functionType.getExtendedInterfaces()) {
if (extInterface.getConstructor() != null && !extInterface.getConstructor().isInterface()) {
compiler.report(
JSError.make(n, CONFLICTING_EXTENDED_TYPE, "interface", getBestFunctionName(n)));
}
}
// Check whether the extended interfaces have any conflicts
if (functionType.getExtendedInterfacesCount() > 1) {
// Only check when extending more than one interfaces
HashMap<String, ObjectType> properties = new HashMap<>();
LinkedHashMap<String, ObjectType> currentProperties = new LinkedHashMap<>();
for (ObjectType interfaceType : functionType.getExtendedInterfaces()) {
currentProperties.clear();
checkInterfaceConflictProperties(
n, getBestFunctionName(n), properties, currentProperties, interfaceType);
properties.putAll(currentProperties);
}
}
List<FunctionType> loopPath = functionType.checkExtendsLoop();
if (loopPath != null) {
String strPath = "";
for (int i = 0; i < loopPath.size() - 1; i++) {
strPath += loopPath.get(i).getDisplayName() + " -> ";
}
strPath += Iterables.getLast(loopPath).getDisplayName();
compiler.report(
JSError.make(n, INTERFACE_EXTENDS_LOOP, loopPath.get(0).getDisplayName(), strPath));
}
} | [
"private",
"void",
"checkInterface",
"(",
"Node",
"n",
",",
"FunctionType",
"functionType",
")",
"{",
"// Interface must extend only interfaces",
"for",
"(",
"ObjectType",
"extInterface",
":",
"functionType",
".",
"getExtendedInterfaces",
"(",
")",
")",
"{",
"if",
"(",
"extInterface",
".",
"getConstructor",
"(",
")",
"!=",
"null",
"&&",
"!",
"extInterface",
".",
"getConstructor",
"(",
")",
".",
"isInterface",
"(",
")",
")",
"{",
"compiler",
".",
"report",
"(",
"JSError",
".",
"make",
"(",
"n",
",",
"CONFLICTING_EXTENDED_TYPE",
",",
"\"interface\"",
",",
"getBestFunctionName",
"(",
"n",
")",
")",
")",
";",
"}",
"}",
"// Check whether the extended interfaces have any conflicts",
"if",
"(",
"functionType",
".",
"getExtendedInterfacesCount",
"(",
")",
">",
"1",
")",
"{",
"// Only check when extending more than one interfaces",
"HashMap",
"<",
"String",
",",
"ObjectType",
">",
"properties",
"=",
"new",
"HashMap",
"<>",
"(",
")",
";",
"LinkedHashMap",
"<",
"String",
",",
"ObjectType",
">",
"currentProperties",
"=",
"new",
"LinkedHashMap",
"<>",
"(",
")",
";",
"for",
"(",
"ObjectType",
"interfaceType",
":",
"functionType",
".",
"getExtendedInterfaces",
"(",
")",
")",
"{",
"currentProperties",
".",
"clear",
"(",
")",
";",
"checkInterfaceConflictProperties",
"(",
"n",
",",
"getBestFunctionName",
"(",
"n",
")",
",",
"properties",
",",
"currentProperties",
",",
"interfaceType",
")",
";",
"properties",
".",
"putAll",
"(",
"currentProperties",
")",
";",
"}",
"}",
"List",
"<",
"FunctionType",
">",
"loopPath",
"=",
"functionType",
".",
"checkExtendsLoop",
"(",
")",
";",
"if",
"(",
"loopPath",
"!=",
"null",
")",
"{",
"String",
"strPath",
"=",
"\"\"",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"loopPath",
".",
"size",
"(",
")",
"-",
"1",
";",
"i",
"++",
")",
"{",
"strPath",
"+=",
"loopPath",
".",
"get",
"(",
"i",
")",
".",
"getDisplayName",
"(",
")",
"+",
"\" -> \"",
";",
"}",
"strPath",
"+=",
"Iterables",
".",
"getLast",
"(",
"loopPath",
")",
".",
"getDisplayName",
"(",
")",
";",
"compiler",
".",
"report",
"(",
"JSError",
".",
"make",
"(",
"n",
",",
"INTERFACE_EXTENDS_LOOP",
",",
"loopPath",
".",
"get",
"(",
"0",
")",
".",
"getDisplayName",
"(",
")",
",",
"strPath",
")",
")",
";",
"}",
"}"
] | Checks an interface, which may be either an ES5-style FUNCTION node, or a CLASS node. | [
"Checks",
"an",
"interface",
"which",
"may",
"be",
"either",
"an",
"ES5",
"-",
"style",
"FUNCTION",
"node",
"or",
"a",
"CLASS",
"node",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/TypeCheck.java#L2461-L2493 |
24,033 | google/closure-compiler | src/com/google/javascript/jscomp/TypeCheck.java | TypeCheck.checkCallConventions | private void checkCallConventions(NodeTraversal t, Node n) {
SubclassRelationship relationship =
compiler.getCodingConvention().getClassesDefinedByCall(n);
TypedScope scope = t.getTypedScope();
if (relationship != null) {
ObjectType superClass =
TypeValidator.getInstanceOfCtor(
scope.lookupQualifiedName(QualifiedName.of(relationship.superclassName)));
ObjectType subClass =
TypeValidator.getInstanceOfCtor(
scope.lookupQualifiedName(QualifiedName.of(relationship.subclassName)));
if (relationship.type == SubclassType.INHERITS
&& superClass != null
&& !superClass.isEmptyType()
&& subClass != null
&& !subClass.isEmptyType()) {
validator.expectSuperType(n, superClass, subClass);
}
}
} | java | private void checkCallConventions(NodeTraversal t, Node n) {
SubclassRelationship relationship =
compiler.getCodingConvention().getClassesDefinedByCall(n);
TypedScope scope = t.getTypedScope();
if (relationship != null) {
ObjectType superClass =
TypeValidator.getInstanceOfCtor(
scope.lookupQualifiedName(QualifiedName.of(relationship.superclassName)));
ObjectType subClass =
TypeValidator.getInstanceOfCtor(
scope.lookupQualifiedName(QualifiedName.of(relationship.subclassName)));
if (relationship.type == SubclassType.INHERITS
&& superClass != null
&& !superClass.isEmptyType()
&& subClass != null
&& !subClass.isEmptyType()) {
validator.expectSuperType(n, superClass, subClass);
}
}
} | [
"private",
"void",
"checkCallConventions",
"(",
"NodeTraversal",
"t",
",",
"Node",
"n",
")",
"{",
"SubclassRelationship",
"relationship",
"=",
"compiler",
".",
"getCodingConvention",
"(",
")",
".",
"getClassesDefinedByCall",
"(",
"n",
")",
";",
"TypedScope",
"scope",
"=",
"t",
".",
"getTypedScope",
"(",
")",
";",
"if",
"(",
"relationship",
"!=",
"null",
")",
"{",
"ObjectType",
"superClass",
"=",
"TypeValidator",
".",
"getInstanceOfCtor",
"(",
"scope",
".",
"lookupQualifiedName",
"(",
"QualifiedName",
".",
"of",
"(",
"relationship",
".",
"superclassName",
")",
")",
")",
";",
"ObjectType",
"subClass",
"=",
"TypeValidator",
".",
"getInstanceOfCtor",
"(",
"scope",
".",
"lookupQualifiedName",
"(",
"QualifiedName",
".",
"of",
"(",
"relationship",
".",
"subclassName",
")",
")",
")",
";",
"if",
"(",
"relationship",
".",
"type",
"==",
"SubclassType",
".",
"INHERITS",
"&&",
"superClass",
"!=",
"null",
"&&",
"!",
"superClass",
".",
"isEmptyType",
"(",
")",
"&&",
"subClass",
"!=",
"null",
"&&",
"!",
"subClass",
".",
"isEmptyType",
"(",
")",
")",
"{",
"validator",
".",
"expectSuperType",
"(",
"n",
",",
"superClass",
",",
"subClass",
")",
";",
"}",
"}",
"}"
] | Validate class-defining calls.
Because JS has no 'native' syntax for defining classes, we need
to do this manually. | [
"Validate",
"class",
"-",
"defining",
"calls",
".",
"Because",
"JS",
"has",
"no",
"native",
"syntax",
"for",
"defining",
"classes",
"we",
"need",
"to",
"do",
"this",
"manually",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/TypeCheck.java#L2506-L2525 |
24,034 | google/closure-compiler | src/com/google/javascript/jscomp/TypeCheck.java | TypeCheck.visitCall | private void visitCall(NodeTraversal t, Node n) {
checkCallConventions(t, n);
Node child = n.getFirstChild();
JSType childType = getJSType(child).restrictByNotNullOrUndefined();
if (!childType.canBeCalled()) {
report(n, NOT_CALLABLE, childType.toString());
ensureTyped(n);
return;
}
// A couple of types can be called as if they were functions.
// If it is a function type, then validate parameters.
if (childType.isFunctionType()) {
FunctionType functionType = childType.toMaybeFunctionType();
// Non-native constructors should not be called directly
// unless they specify a return type
if (functionType.isConstructor()
&& !functionType.isNativeObjectType()
&& (functionType.getReturnType().isUnknownType()
|| functionType.getReturnType().isVoidType())
&& !n.getFirstChild().isSuper()) {
report(n, CONSTRUCTOR_NOT_CALLABLE, childType.toString());
}
// Functions with explicit 'this' types must be called in a GETPROP or GETELEM.
if (functionType.isOrdinaryFunction() && !NodeUtil.isGet(child)) {
JSType receiverType = functionType.getTypeOfThis();
if (receiverType.isUnknownType()
|| receiverType.isAllType()
|| receiverType.isVoidType()
|| (receiverType.isObjectType() && receiverType.toObjectType().isNativeObjectType())) {
// Allow these special cases.
} else {
report(n, EXPECTED_THIS_TYPE, functionType.toString());
}
}
visitArgumentList(n, functionType);
ensureTyped(n, functionType.getReturnType());
} else {
ensureTyped(n);
}
// TODO(nicksantos): Add something to check for calls of RegExp objects,
// which is not supported by IE. Either say something about the return type
// or warn about the non-portability of the call or both.
} | java | private void visitCall(NodeTraversal t, Node n) {
checkCallConventions(t, n);
Node child = n.getFirstChild();
JSType childType = getJSType(child).restrictByNotNullOrUndefined();
if (!childType.canBeCalled()) {
report(n, NOT_CALLABLE, childType.toString());
ensureTyped(n);
return;
}
// A couple of types can be called as if they were functions.
// If it is a function type, then validate parameters.
if (childType.isFunctionType()) {
FunctionType functionType = childType.toMaybeFunctionType();
// Non-native constructors should not be called directly
// unless they specify a return type
if (functionType.isConstructor()
&& !functionType.isNativeObjectType()
&& (functionType.getReturnType().isUnknownType()
|| functionType.getReturnType().isVoidType())
&& !n.getFirstChild().isSuper()) {
report(n, CONSTRUCTOR_NOT_CALLABLE, childType.toString());
}
// Functions with explicit 'this' types must be called in a GETPROP or GETELEM.
if (functionType.isOrdinaryFunction() && !NodeUtil.isGet(child)) {
JSType receiverType = functionType.getTypeOfThis();
if (receiverType.isUnknownType()
|| receiverType.isAllType()
|| receiverType.isVoidType()
|| (receiverType.isObjectType() && receiverType.toObjectType().isNativeObjectType())) {
// Allow these special cases.
} else {
report(n, EXPECTED_THIS_TYPE, functionType.toString());
}
}
visitArgumentList(n, functionType);
ensureTyped(n, functionType.getReturnType());
} else {
ensureTyped(n);
}
// TODO(nicksantos): Add something to check for calls of RegExp objects,
// which is not supported by IE. Either say something about the return type
// or warn about the non-portability of the call or both.
} | [
"private",
"void",
"visitCall",
"(",
"NodeTraversal",
"t",
",",
"Node",
"n",
")",
"{",
"checkCallConventions",
"(",
"t",
",",
"n",
")",
";",
"Node",
"child",
"=",
"n",
".",
"getFirstChild",
"(",
")",
";",
"JSType",
"childType",
"=",
"getJSType",
"(",
"child",
")",
".",
"restrictByNotNullOrUndefined",
"(",
")",
";",
"if",
"(",
"!",
"childType",
".",
"canBeCalled",
"(",
")",
")",
"{",
"report",
"(",
"n",
",",
"NOT_CALLABLE",
",",
"childType",
".",
"toString",
"(",
")",
")",
";",
"ensureTyped",
"(",
"n",
")",
";",
"return",
";",
"}",
"// A couple of types can be called as if they were functions.",
"// If it is a function type, then validate parameters.",
"if",
"(",
"childType",
".",
"isFunctionType",
"(",
")",
")",
"{",
"FunctionType",
"functionType",
"=",
"childType",
".",
"toMaybeFunctionType",
"(",
")",
";",
"// Non-native constructors should not be called directly",
"// unless they specify a return type",
"if",
"(",
"functionType",
".",
"isConstructor",
"(",
")",
"&&",
"!",
"functionType",
".",
"isNativeObjectType",
"(",
")",
"&&",
"(",
"functionType",
".",
"getReturnType",
"(",
")",
".",
"isUnknownType",
"(",
")",
"||",
"functionType",
".",
"getReturnType",
"(",
")",
".",
"isVoidType",
"(",
")",
")",
"&&",
"!",
"n",
".",
"getFirstChild",
"(",
")",
".",
"isSuper",
"(",
")",
")",
"{",
"report",
"(",
"n",
",",
"CONSTRUCTOR_NOT_CALLABLE",
",",
"childType",
".",
"toString",
"(",
")",
")",
";",
"}",
"// Functions with explicit 'this' types must be called in a GETPROP or GETELEM.",
"if",
"(",
"functionType",
".",
"isOrdinaryFunction",
"(",
")",
"&&",
"!",
"NodeUtil",
".",
"isGet",
"(",
"child",
")",
")",
"{",
"JSType",
"receiverType",
"=",
"functionType",
".",
"getTypeOfThis",
"(",
")",
";",
"if",
"(",
"receiverType",
".",
"isUnknownType",
"(",
")",
"||",
"receiverType",
".",
"isAllType",
"(",
")",
"||",
"receiverType",
".",
"isVoidType",
"(",
")",
"||",
"(",
"receiverType",
".",
"isObjectType",
"(",
")",
"&&",
"receiverType",
".",
"toObjectType",
"(",
")",
".",
"isNativeObjectType",
"(",
")",
")",
")",
"{",
"// Allow these special cases.",
"}",
"else",
"{",
"report",
"(",
"n",
",",
"EXPECTED_THIS_TYPE",
",",
"functionType",
".",
"toString",
"(",
")",
")",
";",
"}",
"}",
"visitArgumentList",
"(",
"n",
",",
"functionType",
")",
";",
"ensureTyped",
"(",
"n",
",",
"functionType",
".",
"getReturnType",
"(",
")",
")",
";",
"}",
"else",
"{",
"ensureTyped",
"(",
"n",
")",
";",
"}",
"// TODO(nicksantos): Add something to check for calls of RegExp objects,",
"// which is not supported by IE. Either say something about the return type",
"// or warn about the non-portability of the call or both.",
"}"
] | Visits a CALL node.
@param t The node traversal object that supplies context, such as the
scope chain to use in name lookups as well as error reporting.
@param n The node being visited. | [
"Visits",
"a",
"CALL",
"node",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/TypeCheck.java#L2534-L2583 |
24,035 | google/closure-compiler | src/com/google/javascript/jscomp/TypeCheck.java | TypeCheck.visitArgumentList | private void visitArgumentList(Node call, FunctionType functionType) {
Iterator<Node> parameters = functionType.getParameters().iterator();
Iterator<Node> arguments = NodeUtil.getInvocationArgsAsIterable(call).iterator();
checkArgumentsMatchParameters(call, functionType, arguments, parameters, 0);
} | java | private void visitArgumentList(Node call, FunctionType functionType) {
Iterator<Node> parameters = functionType.getParameters().iterator();
Iterator<Node> arguments = NodeUtil.getInvocationArgsAsIterable(call).iterator();
checkArgumentsMatchParameters(call, functionType, arguments, parameters, 0);
} | [
"private",
"void",
"visitArgumentList",
"(",
"Node",
"call",
",",
"FunctionType",
"functionType",
")",
"{",
"Iterator",
"<",
"Node",
">",
"parameters",
"=",
"functionType",
".",
"getParameters",
"(",
")",
".",
"iterator",
"(",
")",
";",
"Iterator",
"<",
"Node",
">",
"arguments",
"=",
"NodeUtil",
".",
"getInvocationArgsAsIterable",
"(",
"call",
")",
".",
"iterator",
"(",
")",
";",
"checkArgumentsMatchParameters",
"(",
"call",
",",
"functionType",
",",
"arguments",
",",
"parameters",
",",
"0",
")",
";",
"}"
] | Visits the parameters of a CALL or a NEW node. | [
"Visits",
"the",
"parameters",
"of",
"a",
"CALL",
"or",
"a",
"NEW",
"node",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/TypeCheck.java#L2586-L2590 |
24,036 | google/closure-compiler | src/com/google/javascript/jscomp/TypeCheck.java | TypeCheck.checkArgumentsMatchParameters | private void checkArgumentsMatchParameters(
Node call,
FunctionType functionType,
Iterator<Node> arguments,
Iterator<Node> parameters,
int firstParameterIndex) {
int spreadArgumentCount = 0;
int normalArgumentCount = firstParameterIndex;
boolean checkArgumentTypeAgainstParameter = true;
Node parameter = null;
Node argument = null;
while (arguments.hasNext()) {
// get the next argument
argument = arguments.next();
// Count normal & spread arguments.
if (argument.isSpread()) {
// we have some form of this case
// someCall(arg1, arg2, ...firstSpreadExpression, argN, ...secondSpreadExpression)
spreadArgumentCount++;
// Once we see a spread parameter, we can no longer match up arguments with parameters.
checkArgumentTypeAgainstParameter = false;
} else {
normalArgumentCount++;
}
// Get the next parameter, if we're still matching parameters and arguments.
if (checkArgumentTypeAgainstParameter) {
if (parameters.hasNext()) {
parameter = parameters.next();
} else if (parameter != null && parameter.isVarArgs()) {
// use varargs for all remaining parameters
} else {
// else we ran out of parameters and will report that after this loop
parameter = null;
checkArgumentTypeAgainstParameter = false;
}
}
if (checkArgumentTypeAgainstParameter) {
validator.expectArgumentMatchesParameter(
argument, getJSType(argument), getJSType(parameter), call, normalArgumentCount);
}
}
int minArity = functionType.getMinArity();
int maxArity = functionType.getMaxArity();
if (spreadArgumentCount > 0) {
if (normalArgumentCount > maxArity) {
// We cannot reliably check whether the total argument count is wrong, but we can at
// least tell if there are more arguments than the function can handle even ignoring the
// spreads.
report(
call,
WRONG_ARGUMENT_COUNT,
typeRegistry.getReadableTypeNameNoDeref(call.getFirstChild()),
"at least " + String.valueOf(normalArgumentCount),
String.valueOf(minArity),
maxArity == Integer.MAX_VALUE ? "" : " and no more than " + maxArity + " argument(s)");
}
} else {
if (minArity > normalArgumentCount || maxArity < normalArgumentCount) {
report(
call,
WRONG_ARGUMENT_COUNT,
typeRegistry.getReadableTypeNameNoDeref(call.getFirstChild()),
String.valueOf(normalArgumentCount),
String.valueOf(minArity),
maxArity == Integer.MAX_VALUE ? "" : " and no more than " + maxArity + " argument(s)");
}
}
} | java | private void checkArgumentsMatchParameters(
Node call,
FunctionType functionType,
Iterator<Node> arguments,
Iterator<Node> parameters,
int firstParameterIndex) {
int spreadArgumentCount = 0;
int normalArgumentCount = firstParameterIndex;
boolean checkArgumentTypeAgainstParameter = true;
Node parameter = null;
Node argument = null;
while (arguments.hasNext()) {
// get the next argument
argument = arguments.next();
// Count normal & spread arguments.
if (argument.isSpread()) {
// we have some form of this case
// someCall(arg1, arg2, ...firstSpreadExpression, argN, ...secondSpreadExpression)
spreadArgumentCount++;
// Once we see a spread parameter, we can no longer match up arguments with parameters.
checkArgumentTypeAgainstParameter = false;
} else {
normalArgumentCount++;
}
// Get the next parameter, if we're still matching parameters and arguments.
if (checkArgumentTypeAgainstParameter) {
if (parameters.hasNext()) {
parameter = parameters.next();
} else if (parameter != null && parameter.isVarArgs()) {
// use varargs for all remaining parameters
} else {
// else we ran out of parameters and will report that after this loop
parameter = null;
checkArgumentTypeAgainstParameter = false;
}
}
if (checkArgumentTypeAgainstParameter) {
validator.expectArgumentMatchesParameter(
argument, getJSType(argument), getJSType(parameter), call, normalArgumentCount);
}
}
int minArity = functionType.getMinArity();
int maxArity = functionType.getMaxArity();
if (spreadArgumentCount > 0) {
if (normalArgumentCount > maxArity) {
// We cannot reliably check whether the total argument count is wrong, but we can at
// least tell if there are more arguments than the function can handle even ignoring the
// spreads.
report(
call,
WRONG_ARGUMENT_COUNT,
typeRegistry.getReadableTypeNameNoDeref(call.getFirstChild()),
"at least " + String.valueOf(normalArgumentCount),
String.valueOf(minArity),
maxArity == Integer.MAX_VALUE ? "" : " and no more than " + maxArity + " argument(s)");
}
} else {
if (minArity > normalArgumentCount || maxArity < normalArgumentCount) {
report(
call,
WRONG_ARGUMENT_COUNT,
typeRegistry.getReadableTypeNameNoDeref(call.getFirstChild()),
String.valueOf(normalArgumentCount),
String.valueOf(minArity),
maxArity == Integer.MAX_VALUE ? "" : " and no more than " + maxArity + " argument(s)");
}
}
} | [
"private",
"void",
"checkArgumentsMatchParameters",
"(",
"Node",
"call",
",",
"FunctionType",
"functionType",
",",
"Iterator",
"<",
"Node",
">",
"arguments",
",",
"Iterator",
"<",
"Node",
">",
"parameters",
",",
"int",
"firstParameterIndex",
")",
"{",
"int",
"spreadArgumentCount",
"=",
"0",
";",
"int",
"normalArgumentCount",
"=",
"firstParameterIndex",
";",
"boolean",
"checkArgumentTypeAgainstParameter",
"=",
"true",
";",
"Node",
"parameter",
"=",
"null",
";",
"Node",
"argument",
"=",
"null",
";",
"while",
"(",
"arguments",
".",
"hasNext",
"(",
")",
")",
"{",
"// get the next argument",
"argument",
"=",
"arguments",
".",
"next",
"(",
")",
";",
"// Count normal & spread arguments.",
"if",
"(",
"argument",
".",
"isSpread",
"(",
")",
")",
"{",
"// we have some form of this case",
"// someCall(arg1, arg2, ...firstSpreadExpression, argN, ...secondSpreadExpression)",
"spreadArgumentCount",
"++",
";",
"// Once we see a spread parameter, we can no longer match up arguments with parameters.",
"checkArgumentTypeAgainstParameter",
"=",
"false",
";",
"}",
"else",
"{",
"normalArgumentCount",
"++",
";",
"}",
"// Get the next parameter, if we're still matching parameters and arguments.",
"if",
"(",
"checkArgumentTypeAgainstParameter",
")",
"{",
"if",
"(",
"parameters",
".",
"hasNext",
"(",
")",
")",
"{",
"parameter",
"=",
"parameters",
".",
"next",
"(",
")",
";",
"}",
"else",
"if",
"(",
"parameter",
"!=",
"null",
"&&",
"parameter",
".",
"isVarArgs",
"(",
")",
")",
"{",
"// use varargs for all remaining parameters",
"}",
"else",
"{",
"// else we ran out of parameters and will report that after this loop",
"parameter",
"=",
"null",
";",
"checkArgumentTypeAgainstParameter",
"=",
"false",
";",
"}",
"}",
"if",
"(",
"checkArgumentTypeAgainstParameter",
")",
"{",
"validator",
".",
"expectArgumentMatchesParameter",
"(",
"argument",
",",
"getJSType",
"(",
"argument",
")",
",",
"getJSType",
"(",
"parameter",
")",
",",
"call",
",",
"normalArgumentCount",
")",
";",
"}",
"}",
"int",
"minArity",
"=",
"functionType",
".",
"getMinArity",
"(",
")",
";",
"int",
"maxArity",
"=",
"functionType",
".",
"getMaxArity",
"(",
")",
";",
"if",
"(",
"spreadArgumentCount",
">",
"0",
")",
"{",
"if",
"(",
"normalArgumentCount",
">",
"maxArity",
")",
"{",
"// We cannot reliably check whether the total argument count is wrong, but we can at",
"// least tell if there are more arguments than the function can handle even ignoring the",
"// spreads.",
"report",
"(",
"call",
",",
"WRONG_ARGUMENT_COUNT",
",",
"typeRegistry",
".",
"getReadableTypeNameNoDeref",
"(",
"call",
".",
"getFirstChild",
"(",
")",
")",
",",
"\"at least \"",
"+",
"String",
".",
"valueOf",
"(",
"normalArgumentCount",
")",
",",
"String",
".",
"valueOf",
"(",
"minArity",
")",
",",
"maxArity",
"==",
"Integer",
".",
"MAX_VALUE",
"?",
"\"\"",
":",
"\" and no more than \"",
"+",
"maxArity",
"+",
"\" argument(s)\"",
")",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"minArity",
">",
"normalArgumentCount",
"||",
"maxArity",
"<",
"normalArgumentCount",
")",
"{",
"report",
"(",
"call",
",",
"WRONG_ARGUMENT_COUNT",
",",
"typeRegistry",
".",
"getReadableTypeNameNoDeref",
"(",
"call",
".",
"getFirstChild",
"(",
")",
")",
",",
"String",
".",
"valueOf",
"(",
"normalArgumentCount",
")",
",",
"String",
".",
"valueOf",
"(",
"minArity",
")",
",",
"maxArity",
"==",
"Integer",
".",
"MAX_VALUE",
"?",
"\"\"",
":",
"\" and no more than \"",
"+",
"maxArity",
"+",
"\" argument(s)\"",
")",
";",
"}",
"}",
"}"
] | Checks that a list of arguments match a list of formal parameters
<p>If given a TAGGED_TEMPLATE_LIT, the given Iterator should only contain the parameters
corresponding to the actual template lit sub arguments, skipping over the first parameter.
@param firstParameterIndex The index of the first parameter in the given Iterator in the
function type's parameter list. | [
"Checks",
"that",
"a",
"list",
"of",
"arguments",
"match",
"a",
"list",
"of",
"formal",
"parameters"
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/TypeCheck.java#L2601-L2674 |
24,037 | google/closure-compiler | src/com/google/javascript/jscomp/TypeCheck.java | TypeCheck.visitImplicitReturnExpression | private void visitImplicitReturnExpression(NodeTraversal t, Node exprNode) {
Node enclosingFunction = t.getEnclosingFunction();
JSType jsType = getJSType(enclosingFunction);
if (jsType.isFunctionType()) {
FunctionType functionType = jsType.toMaybeFunctionType();
JSType expectedReturnType = functionType.getReturnType();
// if no return type is specified, undefined must be returned
// (it's a void function)
if (expectedReturnType == null) {
expectedReturnType = getNativeType(VOID_TYPE);
} else if (enclosingFunction.isAsyncFunction()) {
// Unwrap the async function's declared return type.
expectedReturnType = Promises.createAsyncReturnableType(typeRegistry, expectedReturnType);
}
// Fetch the returned value's type
JSType actualReturnType = getJSType(exprNode);
validator.expectCanAssignTo(
exprNode, actualReturnType, expectedReturnType, "inconsistent return type");
}
} | java | private void visitImplicitReturnExpression(NodeTraversal t, Node exprNode) {
Node enclosingFunction = t.getEnclosingFunction();
JSType jsType = getJSType(enclosingFunction);
if (jsType.isFunctionType()) {
FunctionType functionType = jsType.toMaybeFunctionType();
JSType expectedReturnType = functionType.getReturnType();
// if no return type is specified, undefined must be returned
// (it's a void function)
if (expectedReturnType == null) {
expectedReturnType = getNativeType(VOID_TYPE);
} else if (enclosingFunction.isAsyncFunction()) {
// Unwrap the async function's declared return type.
expectedReturnType = Promises.createAsyncReturnableType(typeRegistry, expectedReturnType);
}
// Fetch the returned value's type
JSType actualReturnType = getJSType(exprNode);
validator.expectCanAssignTo(
exprNode, actualReturnType, expectedReturnType, "inconsistent return type");
}
} | [
"private",
"void",
"visitImplicitReturnExpression",
"(",
"NodeTraversal",
"t",
",",
"Node",
"exprNode",
")",
"{",
"Node",
"enclosingFunction",
"=",
"t",
".",
"getEnclosingFunction",
"(",
")",
";",
"JSType",
"jsType",
"=",
"getJSType",
"(",
"enclosingFunction",
")",
";",
"if",
"(",
"jsType",
".",
"isFunctionType",
"(",
")",
")",
"{",
"FunctionType",
"functionType",
"=",
"jsType",
".",
"toMaybeFunctionType",
"(",
")",
";",
"JSType",
"expectedReturnType",
"=",
"functionType",
".",
"getReturnType",
"(",
")",
";",
"// if no return type is specified, undefined must be returned",
"// (it's a void function)",
"if",
"(",
"expectedReturnType",
"==",
"null",
")",
"{",
"expectedReturnType",
"=",
"getNativeType",
"(",
"VOID_TYPE",
")",
";",
"}",
"else",
"if",
"(",
"enclosingFunction",
".",
"isAsyncFunction",
"(",
")",
")",
"{",
"// Unwrap the async function's declared return type.",
"expectedReturnType",
"=",
"Promises",
".",
"createAsyncReturnableType",
"(",
"typeRegistry",
",",
"expectedReturnType",
")",
";",
"}",
"// Fetch the returned value's type",
"JSType",
"actualReturnType",
"=",
"getJSType",
"(",
"exprNode",
")",
";",
"validator",
".",
"expectCanAssignTo",
"(",
"exprNode",
",",
"actualReturnType",
",",
"expectedReturnType",
",",
"\"inconsistent return type\"",
")",
";",
"}",
"}"
] | Visits an arrow function expression body. | [
"Visits",
"an",
"arrow",
"function",
"expression",
"body",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/TypeCheck.java#L2677-L2699 |
24,038 | google/closure-compiler | src/com/google/javascript/jscomp/TypeCheck.java | TypeCheck.visitReturn | private void visitReturn(NodeTraversal t, Node n) {
Node enclosingFunction = t.getEnclosingFunction();
if (enclosingFunction.isGeneratorFunction() && !n.hasChildren()) {
// Allow "return;" in a generator function, even if it's not the declared return type.
// e.g. Don't warn for a generator function with JSDoc "@return {!Generator<number>}" and
// a "return;" in the fn body, even though "undefined" does not match "number".
return;
}
JSType jsType = getJSType(enclosingFunction);
if (jsType.isFunctionType()) {
FunctionType functionType = jsType.toMaybeFunctionType();
JSType returnType = functionType.getReturnType();
// if no return type is specified, undefined must be returned
// (it's a void function)
if (returnType == null) {
returnType = getNativeType(VOID_TYPE);
} else if (enclosingFunction.isGeneratorFunction()) {
// Unwrap the template variable from a generator function's declared return type.
// e.g. if returnType is "Generator<string>", make it just "string".
returnType = JsIterables.getElementType(returnType, typeRegistry);
if (enclosingFunction.isAsyncGeneratorFunction()) {
// Can return x|IThenable<x> in an AsyncGenerator<x>, no await needed. Note that we must
// first wrap the type in IThenable as createAsyncReturnableType will map a non-IThenable
// to `?`.
returnType =
Promises.createAsyncReturnableType(
typeRegistry, Promises.wrapInIThenable(typeRegistry, returnType));
}
} else if (enclosingFunction.isAsyncFunction()) {
// e.g. `!Promise<string>` => `string|!IThenable<string>`
// We transform the expected return type rather than the actual return type so that the
// extual return type is always reported to the user. This was felt to be clearer.
returnType = Promises.createAsyncReturnableType(typeRegistry, returnType);
} else if (returnType.isVoidType() && functionType.isConstructor()) {
// Allow constructors to use empty returns for flow control.
if (!n.hasChildren()) {
return;
}
// Allow constructors to return its own instance type
returnType = functionType.getInstanceType();
}
// fetching the returned value's type
Node valueNode = n.getFirstChild();
JSType actualReturnType;
if (valueNode == null) {
actualReturnType = getNativeType(VOID_TYPE);
valueNode = n;
} else {
actualReturnType = getJSType(valueNode);
}
// verifying
validator.expectCanAssignTo(
valueNode, actualReturnType, returnType, "inconsistent return type");
}
} | java | private void visitReturn(NodeTraversal t, Node n) {
Node enclosingFunction = t.getEnclosingFunction();
if (enclosingFunction.isGeneratorFunction() && !n.hasChildren()) {
// Allow "return;" in a generator function, even if it's not the declared return type.
// e.g. Don't warn for a generator function with JSDoc "@return {!Generator<number>}" and
// a "return;" in the fn body, even though "undefined" does not match "number".
return;
}
JSType jsType = getJSType(enclosingFunction);
if (jsType.isFunctionType()) {
FunctionType functionType = jsType.toMaybeFunctionType();
JSType returnType = functionType.getReturnType();
// if no return type is specified, undefined must be returned
// (it's a void function)
if (returnType == null) {
returnType = getNativeType(VOID_TYPE);
} else if (enclosingFunction.isGeneratorFunction()) {
// Unwrap the template variable from a generator function's declared return type.
// e.g. if returnType is "Generator<string>", make it just "string".
returnType = JsIterables.getElementType(returnType, typeRegistry);
if (enclosingFunction.isAsyncGeneratorFunction()) {
// Can return x|IThenable<x> in an AsyncGenerator<x>, no await needed. Note that we must
// first wrap the type in IThenable as createAsyncReturnableType will map a non-IThenable
// to `?`.
returnType =
Promises.createAsyncReturnableType(
typeRegistry, Promises.wrapInIThenable(typeRegistry, returnType));
}
} else if (enclosingFunction.isAsyncFunction()) {
// e.g. `!Promise<string>` => `string|!IThenable<string>`
// We transform the expected return type rather than the actual return type so that the
// extual return type is always reported to the user. This was felt to be clearer.
returnType = Promises.createAsyncReturnableType(typeRegistry, returnType);
} else if (returnType.isVoidType() && functionType.isConstructor()) {
// Allow constructors to use empty returns for flow control.
if (!n.hasChildren()) {
return;
}
// Allow constructors to return its own instance type
returnType = functionType.getInstanceType();
}
// fetching the returned value's type
Node valueNode = n.getFirstChild();
JSType actualReturnType;
if (valueNode == null) {
actualReturnType = getNativeType(VOID_TYPE);
valueNode = n;
} else {
actualReturnType = getJSType(valueNode);
}
// verifying
validator.expectCanAssignTo(
valueNode, actualReturnType, returnType, "inconsistent return type");
}
} | [
"private",
"void",
"visitReturn",
"(",
"NodeTraversal",
"t",
",",
"Node",
"n",
")",
"{",
"Node",
"enclosingFunction",
"=",
"t",
".",
"getEnclosingFunction",
"(",
")",
";",
"if",
"(",
"enclosingFunction",
".",
"isGeneratorFunction",
"(",
")",
"&&",
"!",
"n",
".",
"hasChildren",
"(",
")",
")",
"{",
"// Allow \"return;\" in a generator function, even if it's not the declared return type.",
"// e.g. Don't warn for a generator function with JSDoc \"@return {!Generator<number>}\" and",
"// a \"return;\" in the fn body, even though \"undefined\" does not match \"number\".",
"return",
";",
"}",
"JSType",
"jsType",
"=",
"getJSType",
"(",
"enclosingFunction",
")",
";",
"if",
"(",
"jsType",
".",
"isFunctionType",
"(",
")",
")",
"{",
"FunctionType",
"functionType",
"=",
"jsType",
".",
"toMaybeFunctionType",
"(",
")",
";",
"JSType",
"returnType",
"=",
"functionType",
".",
"getReturnType",
"(",
")",
";",
"// if no return type is specified, undefined must be returned",
"// (it's a void function)",
"if",
"(",
"returnType",
"==",
"null",
")",
"{",
"returnType",
"=",
"getNativeType",
"(",
"VOID_TYPE",
")",
";",
"}",
"else",
"if",
"(",
"enclosingFunction",
".",
"isGeneratorFunction",
"(",
")",
")",
"{",
"// Unwrap the template variable from a generator function's declared return type.",
"// e.g. if returnType is \"Generator<string>\", make it just \"string\".",
"returnType",
"=",
"JsIterables",
".",
"getElementType",
"(",
"returnType",
",",
"typeRegistry",
")",
";",
"if",
"(",
"enclosingFunction",
".",
"isAsyncGeneratorFunction",
"(",
")",
")",
"{",
"// Can return x|IThenable<x> in an AsyncGenerator<x>, no await needed. Note that we must",
"// first wrap the type in IThenable as createAsyncReturnableType will map a non-IThenable",
"// to `?`.",
"returnType",
"=",
"Promises",
".",
"createAsyncReturnableType",
"(",
"typeRegistry",
",",
"Promises",
".",
"wrapInIThenable",
"(",
"typeRegistry",
",",
"returnType",
")",
")",
";",
"}",
"}",
"else",
"if",
"(",
"enclosingFunction",
".",
"isAsyncFunction",
"(",
")",
")",
"{",
"// e.g. `!Promise<string>` => `string|!IThenable<string>`",
"// We transform the expected return type rather than the actual return type so that the",
"// extual return type is always reported to the user. This was felt to be clearer.",
"returnType",
"=",
"Promises",
".",
"createAsyncReturnableType",
"(",
"typeRegistry",
",",
"returnType",
")",
";",
"}",
"else",
"if",
"(",
"returnType",
".",
"isVoidType",
"(",
")",
"&&",
"functionType",
".",
"isConstructor",
"(",
")",
")",
"{",
"// Allow constructors to use empty returns for flow control.",
"if",
"(",
"!",
"n",
".",
"hasChildren",
"(",
")",
")",
"{",
"return",
";",
"}",
"// Allow constructors to return its own instance type",
"returnType",
"=",
"functionType",
".",
"getInstanceType",
"(",
")",
";",
"}",
"// fetching the returned value's type",
"Node",
"valueNode",
"=",
"n",
".",
"getFirstChild",
"(",
")",
";",
"JSType",
"actualReturnType",
";",
"if",
"(",
"valueNode",
"==",
"null",
")",
"{",
"actualReturnType",
"=",
"getNativeType",
"(",
"VOID_TYPE",
")",
";",
"valueNode",
"=",
"n",
";",
"}",
"else",
"{",
"actualReturnType",
"=",
"getJSType",
"(",
"valueNode",
")",
";",
"}",
"// verifying",
"validator",
".",
"expectCanAssignTo",
"(",
"valueNode",
",",
"actualReturnType",
",",
"returnType",
",",
"\"inconsistent return type\"",
")",
";",
"}",
"}"
] | Visits a RETURN node.
@param t The node traversal object that supplies context, such as the
scope chain to use in name lookups as well as error reporting.
@param n The node being visited. | [
"Visits",
"a",
"RETURN",
"node",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/TypeCheck.java#L2708-L2769 |
24,039 | google/closure-compiler | src/com/google/javascript/jscomp/TypeCheck.java | TypeCheck.visitYield | private void visitYield(NodeTraversal t, Node n) {
JSType jsType = getJSType(t.getEnclosingFunction());
JSType declaredYieldType = getNativeType(UNKNOWN_TYPE);
if (jsType.isFunctionType()) {
FunctionType functionType = jsType.toMaybeFunctionType();
JSType returnType = functionType.getReturnType();
declaredYieldType = JsIterables.getElementType(returnType, typeRegistry);
if (t.getEnclosingFunction().isAsyncGeneratorFunction()) {
// Can yield x|IThenable<x> in an AsyncGenerator<x>, no await needed. Note that we must
// first wrap the type in IThenable as createAsyncReturnableType will map a non-IThenable to
// `?`.
declaredYieldType =
Promises.createAsyncReturnableType(
typeRegistry, Promises.wrapInIThenable(typeRegistry, declaredYieldType));
}
}
// fetching the yielded value's type
Node valueNode = n.getFirstChild();
JSType actualYieldType;
if (valueNode == null) {
actualYieldType = getNativeType(VOID_TYPE);
valueNode = n;
} else {
actualYieldType = getJSType(valueNode);
}
if (n.isYieldAll()) {
if (t.getEnclosingFunction().isAsyncGeneratorFunction()) {
Optional<JSType> maybeActualYieldType =
validator.expectAutoboxesToIterableOrAsyncIterable(
n, actualYieldType, "Expression yield* expects an iterable or async iterable");
if (!maybeActualYieldType.isPresent()) {
// don't do any further typechecking of the yield* type.
return;
}
actualYieldType = maybeActualYieldType.get();
} else {
if (!validator.expectAutoboxesToIterable(
n, actualYieldType, "Expression yield* expects an iterable")) {
// don't do any further typechecking of the yield* type.
return;
}
actualYieldType =
actualYieldType.autobox().getInstantiatedTypeArgument(getNativeType(ITERABLE_TYPE));
}
}
// verifying
validator.expectCanAssignTo(
valueNode,
actualYieldType,
declaredYieldType,
"Yielded type does not match declared return type.");
} | java | private void visitYield(NodeTraversal t, Node n) {
JSType jsType = getJSType(t.getEnclosingFunction());
JSType declaredYieldType = getNativeType(UNKNOWN_TYPE);
if (jsType.isFunctionType()) {
FunctionType functionType = jsType.toMaybeFunctionType();
JSType returnType = functionType.getReturnType();
declaredYieldType = JsIterables.getElementType(returnType, typeRegistry);
if (t.getEnclosingFunction().isAsyncGeneratorFunction()) {
// Can yield x|IThenable<x> in an AsyncGenerator<x>, no await needed. Note that we must
// first wrap the type in IThenable as createAsyncReturnableType will map a non-IThenable to
// `?`.
declaredYieldType =
Promises.createAsyncReturnableType(
typeRegistry, Promises.wrapInIThenable(typeRegistry, declaredYieldType));
}
}
// fetching the yielded value's type
Node valueNode = n.getFirstChild();
JSType actualYieldType;
if (valueNode == null) {
actualYieldType = getNativeType(VOID_TYPE);
valueNode = n;
} else {
actualYieldType = getJSType(valueNode);
}
if (n.isYieldAll()) {
if (t.getEnclosingFunction().isAsyncGeneratorFunction()) {
Optional<JSType> maybeActualYieldType =
validator.expectAutoboxesToIterableOrAsyncIterable(
n, actualYieldType, "Expression yield* expects an iterable or async iterable");
if (!maybeActualYieldType.isPresent()) {
// don't do any further typechecking of the yield* type.
return;
}
actualYieldType = maybeActualYieldType.get();
} else {
if (!validator.expectAutoboxesToIterable(
n, actualYieldType, "Expression yield* expects an iterable")) {
// don't do any further typechecking of the yield* type.
return;
}
actualYieldType =
actualYieldType.autobox().getInstantiatedTypeArgument(getNativeType(ITERABLE_TYPE));
}
}
// verifying
validator.expectCanAssignTo(
valueNode,
actualYieldType,
declaredYieldType,
"Yielded type does not match declared return type.");
} | [
"private",
"void",
"visitYield",
"(",
"NodeTraversal",
"t",
",",
"Node",
"n",
")",
"{",
"JSType",
"jsType",
"=",
"getJSType",
"(",
"t",
".",
"getEnclosingFunction",
"(",
")",
")",
";",
"JSType",
"declaredYieldType",
"=",
"getNativeType",
"(",
"UNKNOWN_TYPE",
")",
";",
"if",
"(",
"jsType",
".",
"isFunctionType",
"(",
")",
")",
"{",
"FunctionType",
"functionType",
"=",
"jsType",
".",
"toMaybeFunctionType",
"(",
")",
";",
"JSType",
"returnType",
"=",
"functionType",
".",
"getReturnType",
"(",
")",
";",
"declaredYieldType",
"=",
"JsIterables",
".",
"getElementType",
"(",
"returnType",
",",
"typeRegistry",
")",
";",
"if",
"(",
"t",
".",
"getEnclosingFunction",
"(",
")",
".",
"isAsyncGeneratorFunction",
"(",
")",
")",
"{",
"// Can yield x|IThenable<x> in an AsyncGenerator<x>, no await needed. Note that we must",
"// first wrap the type in IThenable as createAsyncReturnableType will map a non-IThenable to",
"// `?`.",
"declaredYieldType",
"=",
"Promises",
".",
"createAsyncReturnableType",
"(",
"typeRegistry",
",",
"Promises",
".",
"wrapInIThenable",
"(",
"typeRegistry",
",",
"declaredYieldType",
")",
")",
";",
"}",
"}",
"// fetching the yielded value's type",
"Node",
"valueNode",
"=",
"n",
".",
"getFirstChild",
"(",
")",
";",
"JSType",
"actualYieldType",
";",
"if",
"(",
"valueNode",
"==",
"null",
")",
"{",
"actualYieldType",
"=",
"getNativeType",
"(",
"VOID_TYPE",
")",
";",
"valueNode",
"=",
"n",
";",
"}",
"else",
"{",
"actualYieldType",
"=",
"getJSType",
"(",
"valueNode",
")",
";",
"}",
"if",
"(",
"n",
".",
"isYieldAll",
"(",
")",
")",
"{",
"if",
"(",
"t",
".",
"getEnclosingFunction",
"(",
")",
".",
"isAsyncGeneratorFunction",
"(",
")",
")",
"{",
"Optional",
"<",
"JSType",
">",
"maybeActualYieldType",
"=",
"validator",
".",
"expectAutoboxesToIterableOrAsyncIterable",
"(",
"n",
",",
"actualYieldType",
",",
"\"Expression yield* expects an iterable or async iterable\"",
")",
";",
"if",
"(",
"!",
"maybeActualYieldType",
".",
"isPresent",
"(",
")",
")",
"{",
"// don't do any further typechecking of the yield* type.",
"return",
";",
"}",
"actualYieldType",
"=",
"maybeActualYieldType",
".",
"get",
"(",
")",
";",
"}",
"else",
"{",
"if",
"(",
"!",
"validator",
".",
"expectAutoboxesToIterable",
"(",
"n",
",",
"actualYieldType",
",",
"\"Expression yield* expects an iterable\"",
")",
")",
"{",
"// don't do any further typechecking of the yield* type.",
"return",
";",
"}",
"actualYieldType",
"=",
"actualYieldType",
".",
"autobox",
"(",
")",
".",
"getInstantiatedTypeArgument",
"(",
"getNativeType",
"(",
"ITERABLE_TYPE",
")",
")",
";",
"}",
"}",
"// verifying",
"validator",
".",
"expectCanAssignTo",
"(",
"valueNode",
",",
"actualYieldType",
",",
"declaredYieldType",
",",
"\"Yielded type does not match declared return type.\"",
")",
";",
"}"
] | Visits a YIELD node. | [
"Visits",
"a",
"YIELD",
"node",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/TypeCheck.java#L2772-L2828 |
24,040 | google/closure-compiler | src/com/google/javascript/jscomp/TypeCheck.java | TypeCheck.visitBinaryOperator | private void visitBinaryOperator(Token op, Node n) {
Node left = n.getFirstChild();
JSType leftType = getJSType(left);
Node right = n.getLastChild();
JSType rightType = getJSType(right);
switch (op) {
case ASSIGN_LSH:
case ASSIGN_RSH:
case LSH:
case RSH:
case ASSIGN_URSH:
case URSH:
String opStr = NodeUtil.opToStr(n.getToken());
if (!leftType.matchesNumberContext()) {
report(left, BIT_OPERATION, opStr, leftType.toString());
} else {
this.validator.expectNumberStrict(n, leftType, "operator " + opStr);
}
if (!rightType.matchesNumberContext()) {
report(right, BIT_OPERATION, opStr, rightType.toString());
} else {
this.validator.expectNumberStrict(n, rightType, "operator " + opStr);
}
break;
case ASSIGN_DIV:
case ASSIGN_MOD:
case ASSIGN_MUL:
case ASSIGN_SUB:
case ASSIGN_EXPONENT:
case DIV:
case MOD:
case MUL:
case SUB:
case EXPONENT:
validator.expectNumber(left, leftType, "left operand");
validator.expectNumber(right, rightType, "right operand");
break;
case ASSIGN_BITAND:
case ASSIGN_BITXOR:
case ASSIGN_BITOR:
case BITAND:
case BITXOR:
case BITOR:
validator.expectBitwiseable(left, leftType, "bad left operand to bitwise operator");
validator.expectBitwiseable(right, rightType, "bad right operand to bitwise operator");
break;
case ASSIGN_ADD:
case ADD:
break;
default:
report(n, UNEXPECTED_TOKEN, op.toString());
}
ensureTyped(n);
} | java | private void visitBinaryOperator(Token op, Node n) {
Node left = n.getFirstChild();
JSType leftType = getJSType(left);
Node right = n.getLastChild();
JSType rightType = getJSType(right);
switch (op) {
case ASSIGN_LSH:
case ASSIGN_RSH:
case LSH:
case RSH:
case ASSIGN_URSH:
case URSH:
String opStr = NodeUtil.opToStr(n.getToken());
if (!leftType.matchesNumberContext()) {
report(left, BIT_OPERATION, opStr, leftType.toString());
} else {
this.validator.expectNumberStrict(n, leftType, "operator " + opStr);
}
if (!rightType.matchesNumberContext()) {
report(right, BIT_OPERATION, opStr, rightType.toString());
} else {
this.validator.expectNumberStrict(n, rightType, "operator " + opStr);
}
break;
case ASSIGN_DIV:
case ASSIGN_MOD:
case ASSIGN_MUL:
case ASSIGN_SUB:
case ASSIGN_EXPONENT:
case DIV:
case MOD:
case MUL:
case SUB:
case EXPONENT:
validator.expectNumber(left, leftType, "left operand");
validator.expectNumber(right, rightType, "right operand");
break;
case ASSIGN_BITAND:
case ASSIGN_BITXOR:
case ASSIGN_BITOR:
case BITAND:
case BITXOR:
case BITOR:
validator.expectBitwiseable(left, leftType, "bad left operand to bitwise operator");
validator.expectBitwiseable(right, rightType, "bad right operand to bitwise operator");
break;
case ASSIGN_ADD:
case ADD:
break;
default:
report(n, UNEXPECTED_TOKEN, op.toString());
}
ensureTyped(n);
} | [
"private",
"void",
"visitBinaryOperator",
"(",
"Token",
"op",
",",
"Node",
"n",
")",
"{",
"Node",
"left",
"=",
"n",
".",
"getFirstChild",
"(",
")",
";",
"JSType",
"leftType",
"=",
"getJSType",
"(",
"left",
")",
";",
"Node",
"right",
"=",
"n",
".",
"getLastChild",
"(",
")",
";",
"JSType",
"rightType",
"=",
"getJSType",
"(",
"right",
")",
";",
"switch",
"(",
"op",
")",
"{",
"case",
"ASSIGN_LSH",
":",
"case",
"ASSIGN_RSH",
":",
"case",
"LSH",
":",
"case",
"RSH",
":",
"case",
"ASSIGN_URSH",
":",
"case",
"URSH",
":",
"String",
"opStr",
"=",
"NodeUtil",
".",
"opToStr",
"(",
"n",
".",
"getToken",
"(",
")",
")",
";",
"if",
"(",
"!",
"leftType",
".",
"matchesNumberContext",
"(",
")",
")",
"{",
"report",
"(",
"left",
",",
"BIT_OPERATION",
",",
"opStr",
",",
"leftType",
".",
"toString",
"(",
")",
")",
";",
"}",
"else",
"{",
"this",
".",
"validator",
".",
"expectNumberStrict",
"(",
"n",
",",
"leftType",
",",
"\"operator \"",
"+",
"opStr",
")",
";",
"}",
"if",
"(",
"!",
"rightType",
".",
"matchesNumberContext",
"(",
")",
")",
"{",
"report",
"(",
"right",
",",
"BIT_OPERATION",
",",
"opStr",
",",
"rightType",
".",
"toString",
"(",
")",
")",
";",
"}",
"else",
"{",
"this",
".",
"validator",
".",
"expectNumberStrict",
"(",
"n",
",",
"rightType",
",",
"\"operator \"",
"+",
"opStr",
")",
";",
"}",
"break",
";",
"case",
"ASSIGN_DIV",
":",
"case",
"ASSIGN_MOD",
":",
"case",
"ASSIGN_MUL",
":",
"case",
"ASSIGN_SUB",
":",
"case",
"ASSIGN_EXPONENT",
":",
"case",
"DIV",
":",
"case",
"MOD",
":",
"case",
"MUL",
":",
"case",
"SUB",
":",
"case",
"EXPONENT",
":",
"validator",
".",
"expectNumber",
"(",
"left",
",",
"leftType",
",",
"\"left operand\"",
")",
";",
"validator",
".",
"expectNumber",
"(",
"right",
",",
"rightType",
",",
"\"right operand\"",
")",
";",
"break",
";",
"case",
"ASSIGN_BITAND",
":",
"case",
"ASSIGN_BITXOR",
":",
"case",
"ASSIGN_BITOR",
":",
"case",
"BITAND",
":",
"case",
"BITXOR",
":",
"case",
"BITOR",
":",
"validator",
".",
"expectBitwiseable",
"(",
"left",
",",
"leftType",
",",
"\"bad left operand to bitwise operator\"",
")",
";",
"validator",
".",
"expectBitwiseable",
"(",
"right",
",",
"rightType",
",",
"\"bad right operand to bitwise operator\"",
")",
";",
"break",
";",
"case",
"ASSIGN_ADD",
":",
"case",
"ADD",
":",
"break",
";",
"default",
":",
"report",
"(",
"n",
",",
"UNEXPECTED_TOKEN",
",",
"op",
".",
"toString",
"(",
")",
")",
";",
"}",
"ensureTyped",
"(",
"n",
")",
";",
"}"
] | This function unifies the type checking involved in the core binary operators and the
corresponding assignment operators. The representation used internally is such that common code
can handle both kinds of operators easily.
@param op The operator.
@param t The traversal object, needed to report errors.
@param n The node being checked. | [
"This",
"function",
"unifies",
"the",
"type",
"checking",
"involved",
"in",
"the",
"core",
"binary",
"operators",
"and",
"the",
"corresponding",
"assignment",
"operators",
".",
"The",
"representation",
"used",
"internally",
"is",
"such",
"that",
"common",
"code",
"can",
"handle",
"both",
"kinds",
"of",
"operators",
"easily",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/TypeCheck.java#L2884-L2941 |
24,041 | google/closure-compiler | src/com/google/javascript/jscomp/TypeCheck.java | TypeCheck.checkEnumAlias | private void checkEnumAlias(
NodeTraversal t, JSDocInfo declInfo, JSType valueType, Node nodeToWarn) {
if (declInfo == null || !declInfo.hasEnumParameterType()) {
return;
}
if (!valueType.isEnumType()) {
return;
}
EnumType valueEnumType = valueType.toMaybeEnumType();
JSType valueEnumPrimitiveType =
valueEnumType.getElementsType().getPrimitiveType();
validator.expectCanAssignTo(
nodeToWarn,
valueEnumPrimitiveType,
declInfo.getEnumParameterType().evaluate(t.getTypedScope(), typeRegistry),
"incompatible enum element types");
} | java | private void checkEnumAlias(
NodeTraversal t, JSDocInfo declInfo, JSType valueType, Node nodeToWarn) {
if (declInfo == null || !declInfo.hasEnumParameterType()) {
return;
}
if (!valueType.isEnumType()) {
return;
}
EnumType valueEnumType = valueType.toMaybeEnumType();
JSType valueEnumPrimitiveType =
valueEnumType.getElementsType().getPrimitiveType();
validator.expectCanAssignTo(
nodeToWarn,
valueEnumPrimitiveType,
declInfo.getEnumParameterType().evaluate(t.getTypedScope(), typeRegistry),
"incompatible enum element types");
} | [
"private",
"void",
"checkEnumAlias",
"(",
"NodeTraversal",
"t",
",",
"JSDocInfo",
"declInfo",
",",
"JSType",
"valueType",
",",
"Node",
"nodeToWarn",
")",
"{",
"if",
"(",
"declInfo",
"==",
"null",
"||",
"!",
"declInfo",
".",
"hasEnumParameterType",
"(",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"!",
"valueType",
".",
"isEnumType",
"(",
")",
")",
"{",
"return",
";",
"}",
"EnumType",
"valueEnumType",
"=",
"valueType",
".",
"toMaybeEnumType",
"(",
")",
";",
"JSType",
"valueEnumPrimitiveType",
"=",
"valueEnumType",
".",
"getElementsType",
"(",
")",
".",
"getPrimitiveType",
"(",
")",
";",
"validator",
".",
"expectCanAssignTo",
"(",
"nodeToWarn",
",",
"valueEnumPrimitiveType",
",",
"declInfo",
".",
"getEnumParameterType",
"(",
")",
".",
"evaluate",
"(",
"t",
".",
"getTypedScope",
"(",
")",
",",
"typeRegistry",
")",
",",
"\"incompatible enum element types\"",
")",
";",
"}"
] | Checks enum aliases.
<p>We verify that the enum element type of the enum used for initialization is a subtype of the
enum element type of the enum the value is being copied in.
<p>Example:
<pre>var myEnum = myOtherEnum;</pre>
<p>Enum aliases are irregular, so we need special code for this :(
@param valueType the type of the value used for initialization of the enum
@param nodeToWarn the node on which to issue warnings on | [
"Checks",
"enum",
"aliases",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/TypeCheck.java#L2958-L2976 |
24,042 | google/closure-compiler | src/com/google/javascript/jscomp/TypeCheck.java | TypeCheck.ensureTyped | private void ensureTyped(Node n, JSType type) {
// Make sure FUNCTION nodes always get function type.
checkState(!n.isFunction() || type.isFunctionType() || type.isUnknownType());
if (n.getJSType() == null) {
n.setJSType(type);
}
} | java | private void ensureTyped(Node n, JSType type) {
// Make sure FUNCTION nodes always get function type.
checkState(!n.isFunction() || type.isFunctionType() || type.isUnknownType());
if (n.getJSType() == null) {
n.setJSType(type);
}
} | [
"private",
"void",
"ensureTyped",
"(",
"Node",
"n",
",",
"JSType",
"type",
")",
"{",
"// Make sure FUNCTION nodes always get function type.",
"checkState",
"(",
"!",
"n",
".",
"isFunction",
"(",
")",
"||",
"type",
".",
"isFunctionType",
"(",
")",
"||",
"type",
".",
"isUnknownType",
"(",
")",
")",
";",
"if",
"(",
"n",
".",
"getJSType",
"(",
")",
"==",
"null",
")",
"{",
"n",
".",
"setJSType",
"(",
"type",
")",
";",
"}",
"}"
] | Ensures the node is typed.
@param n The node getting a type assigned to it.
@param type The type to be assigned. | [
"Ensures",
"the",
"node",
"is",
"typed",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/TypeCheck.java#L3028-L3034 |
24,043 | google/closure-compiler | src/com/google/javascript/jscomp/TypeCheck.java | TypeCheck.isObjectTypeWithNonStringifiableKey | private boolean isObjectTypeWithNonStringifiableKey(JSType type) {
if (!type.isTemplatizedType()) {
return false;
}
TemplatizedType templatizedType = type.toMaybeTemplatizedType();
if (templatizedType.getReferencedType().isNativeObjectType()
&& templatizedType.getTemplateTypes().size() > 1) {
return !isReasonableObjectPropertyKey(templatizedType.getTemplateTypes().get(0));
} else {
return false;
}
} | java | private boolean isObjectTypeWithNonStringifiableKey(JSType type) {
if (!type.isTemplatizedType()) {
return false;
}
TemplatizedType templatizedType = type.toMaybeTemplatizedType();
if (templatizedType.getReferencedType().isNativeObjectType()
&& templatizedType.getTemplateTypes().size() > 1) {
return !isReasonableObjectPropertyKey(templatizedType.getTemplateTypes().get(0));
} else {
return false;
}
} | [
"private",
"boolean",
"isObjectTypeWithNonStringifiableKey",
"(",
"JSType",
"type",
")",
"{",
"if",
"(",
"!",
"type",
".",
"isTemplatizedType",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"TemplatizedType",
"templatizedType",
"=",
"type",
".",
"toMaybeTemplatizedType",
"(",
")",
";",
"if",
"(",
"templatizedType",
".",
"getReferencedType",
"(",
")",
".",
"isNativeObjectType",
"(",
")",
"&&",
"templatizedType",
".",
"getTemplateTypes",
"(",
")",
".",
"size",
"(",
")",
">",
"1",
")",
"{",
"return",
"!",
"isReasonableObjectPropertyKey",
"(",
"templatizedType",
".",
"getTemplateTypes",
"(",
")",
".",
"get",
"(",
"0",
")",
")",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}"
] | Checks whether current type is Object type with non-stringifable key. | [
"Checks",
"whether",
"current",
"type",
"is",
"Object",
"type",
"with",
"non",
"-",
"stringifable",
"key",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/TypeCheck.java#L3156-L3167 |
24,044 | google/closure-compiler | src/com/google/javascript/jscomp/graph/Graph.java | Graph.connectIfNotFound | public final void connectIfNotFound(N n1, E edge, N n2) {
if (!isConnected(n1, edge, n2)) {
connect(n1, edge, n2);
}
} | java | public final void connectIfNotFound(N n1, E edge, N n2) {
if (!isConnected(n1, edge, n2)) {
connect(n1, edge, n2);
}
} | [
"public",
"final",
"void",
"connectIfNotFound",
"(",
"N",
"n1",
",",
"E",
"edge",
",",
"N",
"n2",
")",
"{",
"if",
"(",
"!",
"isConnected",
"(",
"n1",
",",
"edge",
",",
"n2",
")",
")",
"{",
"connect",
"(",
"n1",
",",
"edge",
",",
"n2",
")",
";",
"}",
"}"
] | Connects two nodes in the graph with an edge if such edge does not already
exists between the nodes.
@param n1 First node.
@param edge The edge.
@param n2 Second node. | [
"Connects",
"two",
"nodes",
"in",
"the",
"graph",
"with",
"an",
"edge",
"if",
"such",
"edge",
"does",
"not",
"already",
"exists",
"between",
"the",
"nodes",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/graph/Graph.java#L118-L122 |
24,045 | google/closure-compiler | src/com/google/javascript/jscomp/graph/Graph.java | Graph.getNodeOrFail | @SuppressWarnings("unchecked")
<T extends GraphNode<N, E>> T getNodeOrFail(N val) {
T node = (T) getNode(val);
if (node == null) {
throw new IllegalArgumentException(val + " does not exist in graph");
}
return node;
} | java | @SuppressWarnings("unchecked")
<T extends GraphNode<N, E>> T getNodeOrFail(N val) {
T node = (T) getNode(val);
if (node == null) {
throw new IllegalArgumentException(val + " does not exist in graph");
}
return node;
} | [
"@",
"SuppressWarnings",
"(",
"\"unchecked\"",
")",
"<",
"T",
"extends",
"GraphNode",
"<",
"N",
",",
"E",
">",
">",
"T",
"getNodeOrFail",
"(",
"N",
"val",
")",
"{",
"T",
"node",
"=",
"(",
"T",
")",
"getNode",
"(",
"val",
")",
";",
"if",
"(",
"node",
"==",
"null",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"val",
"+",
"\" does not exist in graph\"",
")",
";",
"}",
"return",
"node",
";",
"}"
] | Gets the node of the specified type, or throws an
IllegalArgumentException. | [
"Gets",
"the",
"node",
"of",
"the",
"specified",
"type",
"or",
"throws",
"an",
"IllegalArgumentException",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/graph/Graph.java#L218-L225 |
24,046 | google/closure-compiler | src/com/google/javascript/jscomp/graph/Graph.java | Graph.pushAnnotations | private static void pushAnnotations(
Deque<GraphAnnotationState> stack,
Collection<? extends Annotatable> haveAnnotations) {
stack.push(new GraphAnnotationState(haveAnnotations.size()));
for (Annotatable h : haveAnnotations) {
stack.peek().add(new AnnotationState(h, h.getAnnotation()));
h.setAnnotation(null);
}
} | java | private static void pushAnnotations(
Deque<GraphAnnotationState> stack,
Collection<? extends Annotatable> haveAnnotations) {
stack.push(new GraphAnnotationState(haveAnnotations.size()));
for (Annotatable h : haveAnnotations) {
stack.peek().add(new AnnotationState(h, h.getAnnotation()));
h.setAnnotation(null);
}
} | [
"private",
"static",
"void",
"pushAnnotations",
"(",
"Deque",
"<",
"GraphAnnotationState",
">",
"stack",
",",
"Collection",
"<",
"?",
"extends",
"Annotatable",
">",
"haveAnnotations",
")",
"{",
"stack",
".",
"push",
"(",
"new",
"GraphAnnotationState",
"(",
"haveAnnotations",
".",
"size",
"(",
")",
")",
")",
";",
"for",
"(",
"Annotatable",
"h",
":",
"haveAnnotations",
")",
"{",
"stack",
".",
"peek",
"(",
")",
".",
"add",
"(",
"new",
"AnnotationState",
"(",
"h",
",",
"h",
".",
"getAnnotation",
"(",
")",
")",
")",
";",
"h",
".",
"setAnnotation",
"(",
"null",
")",
";",
"}",
"}"
] | Pushes a new list on stack and stores nodes annotations in the new list.
Clears objects' annotations as well. | [
"Pushes",
"a",
"new",
"list",
"on",
"stack",
"and",
"stores",
"nodes",
"annotations",
"in",
"the",
"new",
"list",
".",
"Clears",
"objects",
"annotations",
"as",
"well",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/graph/Graph.java#L333-L341 |
24,047 | google/closure-compiler | src/com/google/javascript/jscomp/graph/Graph.java | Graph.popAnnotations | private static void popAnnotations(Deque<GraphAnnotationState> stack) {
for (AnnotationState as : stack.pop()) {
as.first.setAnnotation(as.second);
}
} | java | private static void popAnnotations(Deque<GraphAnnotationState> stack) {
for (AnnotationState as : stack.pop()) {
as.first.setAnnotation(as.second);
}
} | [
"private",
"static",
"void",
"popAnnotations",
"(",
"Deque",
"<",
"GraphAnnotationState",
">",
"stack",
")",
"{",
"for",
"(",
"AnnotationState",
"as",
":",
"stack",
".",
"pop",
"(",
")",
")",
"{",
"as",
".",
"first",
".",
"setAnnotation",
"(",
"as",
".",
"second",
")",
";",
"}",
"}"
] | Restores the node annotations on the top of stack and pops stack. | [
"Restores",
"the",
"node",
"annotations",
"on",
"the",
"top",
"of",
"stack",
"and",
"pops",
"stack",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/graph/Graph.java#L346-L350 |
24,048 | google/closure-compiler | src/com/google/javascript/jscomp/PassConfig.java | PassConfig.regenerateGlobalTypedScope | void regenerateGlobalTypedScope(AbstractCompiler compiler, Node root) {
typedScopeCreator = new TypedScopeCreator(compiler);
topScope = typedScopeCreator.createScope(root, null);
} | java | void regenerateGlobalTypedScope(AbstractCompiler compiler, Node root) {
typedScopeCreator = new TypedScopeCreator(compiler);
topScope = typedScopeCreator.createScope(root, null);
} | [
"void",
"regenerateGlobalTypedScope",
"(",
"AbstractCompiler",
"compiler",
",",
"Node",
"root",
")",
"{",
"typedScopeCreator",
"=",
"new",
"TypedScopeCreator",
"(",
"compiler",
")",
";",
"topScope",
"=",
"typedScopeCreator",
".",
"createScope",
"(",
"root",
",",
"null",
")",
";",
"}"
] | Regenerates the top scope from scratch.
@param compiler The compiler for which the global scope is regenerated.
@param root The root of the AST. | [
"Regenerates",
"the",
"top",
"scope",
"from",
"scratch",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/PassConfig.java#L53-L56 |
24,049 | google/closure-compiler | src/com/google/javascript/jscomp/PassConfig.java | PassConfig.patchGlobalTypedScope | void patchGlobalTypedScope(AbstractCompiler compiler, Node scriptRoot) {
checkNotNull(typedScopeCreator);
typedScopeCreator.patchGlobalScope(topScope, scriptRoot);
} | java | void patchGlobalTypedScope(AbstractCompiler compiler, Node scriptRoot) {
checkNotNull(typedScopeCreator);
typedScopeCreator.patchGlobalScope(topScope, scriptRoot);
} | [
"void",
"patchGlobalTypedScope",
"(",
"AbstractCompiler",
"compiler",
",",
"Node",
"scriptRoot",
")",
"{",
"checkNotNull",
"(",
"typedScopeCreator",
")",
";",
"typedScopeCreator",
".",
"patchGlobalScope",
"(",
"topScope",
",",
"scriptRoot",
")",
";",
"}"
] | Regenerates the top scope potentially only for a sub-tree of AST and then
copies information for the old global scope.
@param compiler The compiler for which the global scope is generated.
@param scriptRoot The root of the AST used to generate global scope. | [
"Regenerates",
"the",
"top",
"scope",
"potentially",
"only",
"for",
"a",
"sub",
"-",
"tree",
"of",
"AST",
"and",
"then",
"copies",
"information",
"for",
"the",
"old",
"global",
"scope",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/PassConfig.java#L70-L73 |
24,050 | google/closure-compiler | src/com/google/javascript/jscomp/PassConfig.java | PassConfig.getPassGraph | GraphvizGraph getPassGraph() {
LinkedDirectedGraph<String, String> graph =
LinkedDirectedGraph.createWithoutAnnotations();
Iterable<PassFactory> allPasses =
Iterables.concat(getChecks(), getOptimizations());
String lastPass = null;
String loopStart = null;
for (PassFactory pass : allPasses) {
String passName = pass.getName();
int i = 1;
while (graph.hasNode(passName)) {
passName = pass.getName() + (i++);
}
graph.createNode(passName);
if (loopStart == null && !pass.isOneTimePass()) {
loopStart = passName;
} else if (loopStart != null && pass.isOneTimePass()) {
graph.connect(lastPass, "loop", loopStart);
loopStart = null;
}
if (lastPass != null) {
graph.connect(lastPass, "", passName);
}
lastPass = passName;
}
return graph;
} | java | GraphvizGraph getPassGraph() {
LinkedDirectedGraph<String, String> graph =
LinkedDirectedGraph.createWithoutAnnotations();
Iterable<PassFactory> allPasses =
Iterables.concat(getChecks(), getOptimizations());
String lastPass = null;
String loopStart = null;
for (PassFactory pass : allPasses) {
String passName = pass.getName();
int i = 1;
while (graph.hasNode(passName)) {
passName = pass.getName() + (i++);
}
graph.createNode(passName);
if (loopStart == null && !pass.isOneTimePass()) {
loopStart = passName;
} else if (loopStart != null && pass.isOneTimePass()) {
graph.connect(lastPass, "loop", loopStart);
loopStart = null;
}
if (lastPass != null) {
graph.connect(lastPass, "", passName);
}
lastPass = passName;
}
return graph;
} | [
"GraphvizGraph",
"getPassGraph",
"(",
")",
"{",
"LinkedDirectedGraph",
"<",
"String",
",",
"String",
">",
"graph",
"=",
"LinkedDirectedGraph",
".",
"createWithoutAnnotations",
"(",
")",
";",
"Iterable",
"<",
"PassFactory",
">",
"allPasses",
"=",
"Iterables",
".",
"concat",
"(",
"getChecks",
"(",
")",
",",
"getOptimizations",
"(",
")",
")",
";",
"String",
"lastPass",
"=",
"null",
";",
"String",
"loopStart",
"=",
"null",
";",
"for",
"(",
"PassFactory",
"pass",
":",
"allPasses",
")",
"{",
"String",
"passName",
"=",
"pass",
".",
"getName",
"(",
")",
";",
"int",
"i",
"=",
"1",
";",
"while",
"(",
"graph",
".",
"hasNode",
"(",
"passName",
")",
")",
"{",
"passName",
"=",
"pass",
".",
"getName",
"(",
")",
"+",
"(",
"i",
"++",
")",
";",
"}",
"graph",
".",
"createNode",
"(",
"passName",
")",
";",
"if",
"(",
"loopStart",
"==",
"null",
"&&",
"!",
"pass",
".",
"isOneTimePass",
"(",
")",
")",
"{",
"loopStart",
"=",
"passName",
";",
"}",
"else",
"if",
"(",
"loopStart",
"!=",
"null",
"&&",
"pass",
".",
"isOneTimePass",
"(",
")",
")",
"{",
"graph",
".",
"connect",
"(",
"lastPass",
",",
"\"loop\"",
",",
"loopStart",
")",
";",
"loopStart",
"=",
"null",
";",
"}",
"if",
"(",
"lastPass",
"!=",
"null",
")",
"{",
"graph",
".",
"connect",
"(",
"lastPass",
",",
"\"\"",
",",
"passName",
")",
";",
"}",
"lastPass",
"=",
"passName",
";",
"}",
"return",
"graph",
";",
"}"
] | Gets a graph of the passes run. For debugging. | [
"Gets",
"a",
"graph",
"of",
"the",
"passes",
"run",
".",
"For",
"debugging",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/PassConfig.java#L126-L154 |
24,051 | google/closure-compiler | src/com/google/javascript/jscomp/PassConfig.java | PassConfig.makeTypeInference | final TypeInferencePass makeTypeInference(AbstractCompiler compiler) {
return new TypeInferencePass(
compiler, compiler.getReverseAbstractInterpreter(),
topScope, typedScopeCreator);
} | java | final TypeInferencePass makeTypeInference(AbstractCompiler compiler) {
return new TypeInferencePass(
compiler, compiler.getReverseAbstractInterpreter(),
topScope, typedScopeCreator);
} | [
"final",
"TypeInferencePass",
"makeTypeInference",
"(",
"AbstractCompiler",
"compiler",
")",
"{",
"return",
"new",
"TypeInferencePass",
"(",
"compiler",
",",
"compiler",
".",
"getReverseAbstractInterpreter",
"(",
")",
",",
"topScope",
",",
"typedScopeCreator",
")",
";",
"}"
] | Create a type inference pass. | [
"Create",
"a",
"type",
"inference",
"pass",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/PassConfig.java#L159-L163 |
24,052 | google/closure-compiler | src/com/google/javascript/jscomp/PassConfig.java | PassConfig.makeTypeCheck | final TypeCheck makeTypeCheck(AbstractCompiler compiler) {
return new TypeCheck(
compiler,
compiler.getReverseAbstractInterpreter(),
compiler.getTypeRegistry(),
topScope,
typedScopeCreator)
.reportUnknownTypes(options.enables(DiagnosticGroup.forType(TypeCheck.UNKNOWN_EXPR_TYPE)))
.reportMissingProperties(
!options.disables(DiagnosticGroup.forType(TypeCheck.INEXISTENT_PROPERTY)));
} | java | final TypeCheck makeTypeCheck(AbstractCompiler compiler) {
return new TypeCheck(
compiler,
compiler.getReverseAbstractInterpreter(),
compiler.getTypeRegistry(),
topScope,
typedScopeCreator)
.reportUnknownTypes(options.enables(DiagnosticGroup.forType(TypeCheck.UNKNOWN_EXPR_TYPE)))
.reportMissingProperties(
!options.disables(DiagnosticGroup.forType(TypeCheck.INEXISTENT_PROPERTY)));
} | [
"final",
"TypeCheck",
"makeTypeCheck",
"(",
"AbstractCompiler",
"compiler",
")",
"{",
"return",
"new",
"TypeCheck",
"(",
"compiler",
",",
"compiler",
".",
"getReverseAbstractInterpreter",
"(",
")",
",",
"compiler",
".",
"getTypeRegistry",
"(",
")",
",",
"topScope",
",",
"typedScopeCreator",
")",
".",
"reportUnknownTypes",
"(",
"options",
".",
"enables",
"(",
"DiagnosticGroup",
".",
"forType",
"(",
"TypeCheck",
".",
"UNKNOWN_EXPR_TYPE",
")",
")",
")",
".",
"reportMissingProperties",
"(",
"!",
"options",
".",
"disables",
"(",
"DiagnosticGroup",
".",
"forType",
"(",
"TypeCheck",
".",
"INEXISTENT_PROPERTY",
")",
")",
")",
";",
"}"
] | Create a type-checking pass. | [
"Create",
"a",
"type",
"-",
"checking",
"pass",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/PassConfig.java#L172-L182 |
24,053 | google/closure-compiler | src/com/google/javascript/jscomp/PassConfig.java | PassConfig.addPassFactoryBefore | static final void addPassFactoryBefore(
List<PassFactory> factoryList, PassFactory factory, String passName) {
factoryList.add(
findPassIndexByName(factoryList, passName), factory);
} | java | static final void addPassFactoryBefore(
List<PassFactory> factoryList, PassFactory factory, String passName) {
factoryList.add(
findPassIndexByName(factoryList, passName), factory);
} | [
"static",
"final",
"void",
"addPassFactoryBefore",
"(",
"List",
"<",
"PassFactory",
">",
"factoryList",
",",
"PassFactory",
"factory",
",",
"String",
"passName",
")",
"{",
"factoryList",
".",
"add",
"(",
"findPassIndexByName",
"(",
"factoryList",
",",
"passName",
")",
",",
"factory",
")",
";",
"}"
] | Insert the given pass factory before the factory of the given name. | [
"Insert",
"the",
"given",
"pass",
"factory",
"before",
"the",
"factory",
"of",
"the",
"given",
"name",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/PassConfig.java#L187-L191 |
24,054 | google/closure-compiler | src/com/google/javascript/jscomp/PassConfig.java | PassConfig.replacePassFactory | static final void replacePassFactory(
List<PassFactory> factoryList, PassFactory factory) {
factoryList.set(
findPassIndexByName(factoryList, factory.getName()), factory);
} | java | static final void replacePassFactory(
List<PassFactory> factoryList, PassFactory factory) {
factoryList.set(
findPassIndexByName(factoryList, factory.getName()), factory);
} | [
"static",
"final",
"void",
"replacePassFactory",
"(",
"List",
"<",
"PassFactory",
">",
"factoryList",
",",
"PassFactory",
"factory",
")",
"{",
"factoryList",
".",
"set",
"(",
"findPassIndexByName",
"(",
"factoryList",
",",
"factory",
".",
"getName",
"(",
")",
")",
",",
"factory",
")",
";",
"}"
] | Find a pass factory with the same name as the given one, and replace it. | [
"Find",
"a",
"pass",
"factory",
"with",
"the",
"same",
"name",
"as",
"the",
"given",
"one",
"and",
"replace",
"it",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/PassConfig.java#L196-L200 |
24,055 | google/closure-compiler | src/com/google/javascript/jscomp/PassConfig.java | PassConfig.findPassIndexByName | private static int findPassIndexByName(
List<PassFactory> factoryList, String name) {
for (int i = 0; i < factoryList.size(); i++) {
if (factoryList.get(i).getName().equals(name)) {
return i;
}
}
throw new IllegalArgumentException(
"No factory named '" + name + "' in the factory list");
} | java | private static int findPassIndexByName(
List<PassFactory> factoryList, String name) {
for (int i = 0; i < factoryList.size(); i++) {
if (factoryList.get(i).getName().equals(name)) {
return i;
}
}
throw new IllegalArgumentException(
"No factory named '" + name + "' in the factory list");
} | [
"private",
"static",
"int",
"findPassIndexByName",
"(",
"List",
"<",
"PassFactory",
">",
"factoryList",
",",
"String",
"name",
")",
"{",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"factoryList",
".",
"size",
"(",
")",
";",
"i",
"++",
")",
"{",
"if",
"(",
"factoryList",
".",
"get",
"(",
"i",
")",
".",
"getName",
"(",
")",
".",
"equals",
"(",
"name",
")",
")",
"{",
"return",
"i",
";",
"}",
"}",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"No factory named '\"",
"+",
"name",
"+",
"\"' in the factory list\"",
")",
";",
"}"
] | Throws an exception if no pass with the given name exists. | [
"Throws",
"an",
"exception",
"if",
"no",
"pass",
"with",
"the",
"given",
"name",
"exists",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/PassConfig.java#L205-L215 |
24,056 | google/closure-compiler | src/com/google/javascript/jscomp/PassConfig.java | PassConfig.getBasePassConfig | final PassConfig getBasePassConfig() {
PassConfig current = this;
while (current instanceof PassConfigDelegate) {
current = ((PassConfigDelegate) current).delegate;
}
return current;
} | java | final PassConfig getBasePassConfig() {
PassConfig current = this;
while (current instanceof PassConfigDelegate) {
current = ((PassConfigDelegate) current).delegate;
}
return current;
} | [
"final",
"PassConfig",
"getBasePassConfig",
"(",
")",
"{",
"PassConfig",
"current",
"=",
"this",
";",
"while",
"(",
"current",
"instanceof",
"PassConfigDelegate",
")",
"{",
"current",
"=",
"(",
"(",
"PassConfigDelegate",
")",
"current",
")",
".",
"delegate",
";",
"}",
"return",
"current",
";",
"}"
] | Find the first pass provider that does not have a delegate. | [
"Find",
"the",
"first",
"pass",
"provider",
"that",
"does",
"not",
"have",
"a",
"delegate",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/PassConfig.java#L220-L226 |
24,057 | google/closure-compiler | src/com/google/javascript/rhino/HamtPMap.java | HamtPMap.empty | @SuppressWarnings("unchecked") // Empty immutable collection is safe to cast.
public static <K, V> HamtPMap<K, V> empty() {
return (HamtPMap<K, V>) EMPTY;
} | java | @SuppressWarnings("unchecked") // Empty immutable collection is safe to cast.
public static <K, V> HamtPMap<K, V> empty() {
return (HamtPMap<K, V>) EMPTY;
} | [
"@",
"SuppressWarnings",
"(",
"\"unchecked\"",
")",
"// Empty immutable collection is safe to cast.",
"public",
"static",
"<",
"K",
",",
"V",
">",
"HamtPMap",
"<",
"K",
",",
"V",
">",
"empty",
"(",
")",
"{",
"return",
"(",
"HamtPMap",
"<",
"K",
",",
"V",
">",
")",
"EMPTY",
";",
"}"
] | Returns an empty map. | [
"Returns",
"an",
"empty",
"map",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/rhino/HamtPMap.java#L115-L118 |
24,058 | google/closure-compiler | src/com/google/javascript/rhino/HamtPMap.java | HamtPMap.emptyChildren | @SuppressWarnings("unchecked") // Empty array is safe to cast.
private static <K, V> HamtPMap<K, V>[] emptyChildren() {
return (HamtPMap<K, V>[]) EMPTY_CHILDREN;
} | java | @SuppressWarnings("unchecked") // Empty array is safe to cast.
private static <K, V> HamtPMap<K, V>[] emptyChildren() {
return (HamtPMap<K, V>[]) EMPTY_CHILDREN;
} | [
"@",
"SuppressWarnings",
"(",
"\"unchecked\"",
")",
"// Empty array is safe to cast.",
"private",
"static",
"<",
"K",
",",
"V",
">",
"HamtPMap",
"<",
"K",
",",
"V",
">",
"[",
"]",
"emptyChildren",
"(",
")",
"{",
"return",
"(",
"HamtPMap",
"<",
"K",
",",
"V",
">",
"[",
"]",
")",
"EMPTY_CHILDREN",
";",
"}"
] | Returns an empty array of child maps. | [
"Returns",
"an",
"empty",
"array",
"of",
"child",
"maps",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/rhino/HamtPMap.java#L121-L124 |
24,059 | google/closure-compiler | src/com/google/javascript/rhino/HamtPMap.java | HamtPMap.appendTo | private void appendTo(StringBuilder sb) {
if (sb.length() > 1) {
sb.append(", ");
}
sb.append(key).append(": ").append(value);
for (HamtPMap<K, V> child : children) {
child.appendTo(sb);
}
} | java | private void appendTo(StringBuilder sb) {
if (sb.length() > 1) {
sb.append(", ");
}
sb.append(key).append(": ").append(value);
for (HamtPMap<K, V> child : children) {
child.appendTo(sb);
}
} | [
"private",
"void",
"appendTo",
"(",
"StringBuilder",
"sb",
")",
"{",
"if",
"(",
"sb",
".",
"length",
"(",
")",
">",
"1",
")",
"{",
"sb",
".",
"append",
"(",
"\", \"",
")",
";",
"}",
"sb",
".",
"append",
"(",
"key",
")",
".",
"append",
"(",
"\": \"",
")",
".",
"append",
"(",
"value",
")",
";",
"for",
"(",
"HamtPMap",
"<",
"K",
",",
"V",
">",
"child",
":",
"children",
")",
"{",
"child",
".",
"appendTo",
"(",
"sb",
")",
";",
"}",
"}"
] | Appends this map's contents to a string builder. | [
"Appends",
"this",
"map",
"s",
"contents",
"to",
"a",
"string",
"builder",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/rhino/HamtPMap.java#L136-L144 |
24,060 | google/closure-compiler | src/com/google/javascript/rhino/HamtPMap.java | HamtPMap.get | @Override
public V get(K key) {
return !isEmpty() ? get(key, hash(key)) : null;
} | java | @Override
public V get(K key) {
return !isEmpty() ? get(key, hash(key)) : null;
} | [
"@",
"Override",
"public",
"V",
"get",
"(",
"K",
"key",
")",
"{",
"return",
"!",
"isEmpty",
"(",
")",
"?",
"get",
"(",
"key",
",",
"hash",
"(",
"key",
")",
")",
":",
"null",
";",
"}"
] | Retrieves the value associated with the given key from the map, or returns null if it is not
present. | [
"Retrieves",
"the",
"value",
"associated",
"with",
"the",
"given",
"key",
"from",
"the",
"map",
"or",
"returns",
"null",
"if",
"it",
"is",
"not",
"present",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/rhino/HamtPMap.java#L165-L168 |
24,061 | google/closure-compiler | src/com/google/javascript/rhino/HamtPMap.java | HamtPMap.plus | @Override
public HamtPMap<K, V> plus(K key, V value) {
return !isEmpty()
? plus(key, hash(key), checkNotNull(value))
: new HamtPMap<>(key, hash(key), value, 0, emptyChildren());
} | java | @Override
public HamtPMap<K, V> plus(K key, V value) {
return !isEmpty()
? plus(key, hash(key), checkNotNull(value))
: new HamtPMap<>(key, hash(key), value, 0, emptyChildren());
} | [
"@",
"Override",
"public",
"HamtPMap",
"<",
"K",
",",
"V",
">",
"plus",
"(",
"K",
"key",
",",
"V",
"value",
")",
"{",
"return",
"!",
"isEmpty",
"(",
")",
"?",
"plus",
"(",
"key",
",",
"hash",
"(",
"key",
")",
",",
"checkNotNull",
"(",
"value",
")",
")",
":",
"new",
"HamtPMap",
"<>",
"(",
"key",
",",
"hash",
"(",
"key",
")",
",",
"value",
",",
"0",
",",
"emptyChildren",
"(",
")",
")",
";",
"}"
] | Returns a new map with the given key-value pair added. If the value is already present, then
this same map will be returned. | [
"Returns",
"a",
"new",
"map",
"with",
"the",
"given",
"key",
"-",
"value",
"pair",
"added",
".",
"If",
"the",
"value",
"is",
"already",
"present",
"then",
"this",
"same",
"map",
"will",
"be",
"returned",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/rhino/HamtPMap.java#L184-L189 |
24,062 | google/closure-compiler | src/com/google/javascript/rhino/HamtPMap.java | HamtPMap.minus | @Override
public HamtPMap<K, V> minus(K key) {
return !isEmpty() ? minus(key, hash(key), null) : this;
} | java | @Override
public HamtPMap<K, V> minus(K key) {
return !isEmpty() ? minus(key, hash(key), null) : this;
} | [
"@",
"Override",
"public",
"HamtPMap",
"<",
"K",
",",
"V",
">",
"minus",
"(",
"K",
"key",
")",
"{",
"return",
"!",
"isEmpty",
"(",
")",
"?",
"minus",
"(",
"key",
",",
"hash",
"(",
"key",
")",
",",
"null",
")",
":",
"this",
";",
"}"
] | Returns a new map with the given key removed. If the key was not present in the first place,
then this same map will be returned. | [
"Returns",
"a",
"new",
"map",
"with",
"the",
"given",
"key",
"removed",
".",
"If",
"the",
"key",
"was",
"not",
"present",
"in",
"the",
"first",
"place",
"then",
"this",
"same",
"map",
"will",
"be",
"returned",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/rhino/HamtPMap.java#L237-L240 |
24,063 | google/closure-compiler | src/com/google/javascript/rhino/HamtPMap.java | HamtPMap.equivalent | @Override
public boolean equivalent(PMap<K, V> that, BiPredicate<V, V> equivalence) {
return equivalent(
!this.isEmpty() ? this : null, !that.isEmpty() ? (HamtPMap<K, V>) that : null, equivalence);
} | java | @Override
public boolean equivalent(PMap<K, V> that, BiPredicate<V, V> equivalence) {
return equivalent(
!this.isEmpty() ? this : null, !that.isEmpty() ? (HamtPMap<K, V>) that : null, equivalence);
} | [
"@",
"Override",
"public",
"boolean",
"equivalent",
"(",
"PMap",
"<",
"K",
",",
"V",
">",
"that",
",",
"BiPredicate",
"<",
"V",
",",
"V",
">",
"equivalence",
")",
"{",
"return",
"equivalent",
"(",
"!",
"this",
".",
"isEmpty",
"(",
")",
"?",
"this",
":",
"null",
",",
"!",
"that",
".",
"isEmpty",
"(",
")",
"?",
"(",
"HamtPMap",
"<",
"K",
",",
"V",
">",
")",
"that",
":",
"null",
",",
"equivalence",
")",
";",
"}"
] | Checks equality recursively based on the given equivalence. Short-circuits as soon as a 'false'
result is found. | [
"Checks",
"equality",
"recursively",
"based",
"on",
"the",
"given",
"equivalence",
".",
"Short",
"-",
"circuits",
"as",
"soon",
"as",
"a",
"false",
"result",
"is",
"found",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/rhino/HamtPMap.java#L375-L379 |
24,064 | google/closure-compiler | src/com/google/javascript/rhino/HamtPMap.java | HamtPMap.getChild | private HamtPMap<K, V> getChild(int bit) {
return (mask & bit) != 0 ? children[index(bit)] : null;
} | java | private HamtPMap<K, V> getChild(int bit) {
return (mask & bit) != 0 ? children[index(bit)] : null;
} | [
"private",
"HamtPMap",
"<",
"K",
",",
"V",
">",
"getChild",
"(",
"int",
"bit",
")",
"{",
"return",
"(",
"mask",
"&",
"bit",
")",
"!=",
"0",
"?",
"children",
"[",
"index",
"(",
"bit",
")",
"]",
":",
"null",
";",
"}"
] | Returns the child for the given bit, which must have exactly one bit set. Returns null if there
is no child for that bit. | [
"Returns",
"the",
"child",
"for",
"the",
"given",
"bit",
"which",
"must",
"have",
"exactly",
"one",
"bit",
"set",
".",
"Returns",
"null",
"if",
"there",
"is",
"no",
"child",
"for",
"that",
"bit",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/rhino/HamtPMap.java#L431-L433 |
24,065 | google/closure-compiler | src/com/google/javascript/rhino/HamtPMap.java | HamtPMap.compareUnsigned | private static int compareUnsigned(int left, int right) {
// NOTE: JDK 7 does not have a built-in operation for this, other than casting to longs.
// In JDK 8 it's just Integer.compareUnsigned(left, right). For now we emulate it
// by shifting the sign bit away, with a fallback second compare only if needed.
int diff = (left >>> 2) - (right >>> 2);
return diff != 0 ? diff : (left & 3) - (right & 3);
} | java | private static int compareUnsigned(int left, int right) {
// NOTE: JDK 7 does not have a built-in operation for this, other than casting to longs.
// In JDK 8 it's just Integer.compareUnsigned(left, right). For now we emulate it
// by shifting the sign bit away, with a fallback second compare only if needed.
int diff = (left >>> 2) - (right >>> 2);
return diff != 0 ? diff : (left & 3) - (right & 3);
} | [
"private",
"static",
"int",
"compareUnsigned",
"(",
"int",
"left",
",",
"int",
"right",
")",
"{",
"// NOTE: JDK 7 does not have a built-in operation for this, other than casting to longs.",
"// In JDK 8 it's just Integer.compareUnsigned(left, right). For now we emulate it",
"// by shifting the sign bit away, with a fallback second compare only if needed.",
"int",
"diff",
"=",
"(",
"left",
">>>",
"2",
")",
"-",
"(",
"right",
">>>",
"2",
")",
";",
"return",
"diff",
"!=",
"0",
"?",
"diff",
":",
"(",
"left",
"&",
"3",
")",
"-",
"(",
"right",
"&",
"3",
")",
";",
"}"
] | Compare two unsigned integers. | [
"Compare",
"two",
"unsigned",
"integers",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/rhino/HamtPMap.java#L463-L469 |
24,066 | google/closure-compiler | src/com/google/javascript/rhino/HamtPMap.java | HamtPMap.pivot | @SuppressWarnings("unchecked")
private HamtPMap<K, V> pivot(K key, int hash) {
return pivot(key, hash, null, (V[]) new Object[1]);
} | java | @SuppressWarnings("unchecked")
private HamtPMap<K, V> pivot(K key, int hash) {
return pivot(key, hash, null, (V[]) new Object[1]);
} | [
"@",
"SuppressWarnings",
"(",
"\"unchecked\"",
")",
"private",
"HamtPMap",
"<",
"K",
",",
"V",
">",
"pivot",
"(",
"K",
"key",
",",
"int",
"hash",
")",
"{",
"return",
"pivot",
"(",
"key",
",",
"hash",
",",
"null",
",",
"(",
"V",
"[",
"]",
")",
"new",
"Object",
"[",
"1",
"]",
")",
";",
"}"
] | Returns a new version of this map with the given key at the root, and the root element moved to
some deeper node. If the key is not found, then value will be null. | [
"Returns",
"a",
"new",
"version",
"of",
"this",
"map",
"with",
"the",
"given",
"key",
"at",
"the",
"root",
"and",
"the",
"root",
"element",
"moved",
"to",
"some",
"deeper",
"node",
".",
"If",
"the",
"key",
"is",
"not",
"found",
"then",
"value",
"will",
"be",
"null",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/rhino/HamtPMap.java#L475-L478 |
24,067 | google/closure-compiler | src/com/google/javascript/rhino/HamtPMap.java | HamtPMap.pivot | private HamtPMap<K, V> pivot(K key, int hash, HamtPMap<K, V> parent, V[] result) {
int newMask = mask;
HamtPMap<K, V>[] newChildren = this.children;
if (hash == this.hash && key.equals(this.key)) {
// Found the key: swap out this key/value with the parent and return the result in the holder.
result[0] = this.value;
} else {
// Otherwise, see if the value might be present in a child.
int searchBucket = bucket(hash);
int replacementBucket = bucket(this.hash);
if (searchBucket == replacementBucket) {
int bucketMask = 1 << searchBucket;
if ((mask & bucketMask) != 0) {
// Found a child, call pivot recursively.
int index = index(bucketMask);
HamtPMap<K, V> child = newChildren[index];
HamtPMap<K, V> newChild = child.pivot(key, shift(hash), this, result);
newChildren = replaceChild(newChildren, index, newChild);
}
} else {
int searchMask = 1 << searchBucket;
if ((mask & searchMask) != 0) {
int index = index(searchMask);
HamtPMap<K, V> child = newChildren[index];
HamtPMap<K, V> newChild = child.minus(key, shift(hash), result);
if (!newChild.isEmpty()) {
newChildren = replaceChild(newChildren, index, newChild);
} else {
newChildren = deleteChild(newChildren, index);
newMask &= ~searchMask;
}
}
int replacementMask = 1 << replacementBucket;
int index = Integer.bitCount(newMask & (replacementMask - 1));
if ((mask & replacementMask) != 0) {
HamtPMap<K, V> child = newChildren[index];
HamtPMap<K, V> newChild = child.plus(this.key, shift(this.hash), this.value);
newChildren = replaceChild(newChildren, index, newChild);
} else {
newChildren =
insertChild(
newChildren,
index,
new HamtPMap<>(this.key, shift(this.hash), this.value, 0, emptyChildren()));
newMask |= replacementMask;
}
}
}
return parent != null
? new HamtPMap<>(parent.key, shift(parent.hash), parent.value, newMask, newChildren)
: new HamtPMap<>(key, hash, result[0], newMask, newChildren);
} | java | private HamtPMap<K, V> pivot(K key, int hash, HamtPMap<K, V> parent, V[] result) {
int newMask = mask;
HamtPMap<K, V>[] newChildren = this.children;
if (hash == this.hash && key.equals(this.key)) {
// Found the key: swap out this key/value with the parent and return the result in the holder.
result[0] = this.value;
} else {
// Otherwise, see if the value might be present in a child.
int searchBucket = bucket(hash);
int replacementBucket = bucket(this.hash);
if (searchBucket == replacementBucket) {
int bucketMask = 1 << searchBucket;
if ((mask & bucketMask) != 0) {
// Found a child, call pivot recursively.
int index = index(bucketMask);
HamtPMap<K, V> child = newChildren[index];
HamtPMap<K, V> newChild = child.pivot(key, shift(hash), this, result);
newChildren = replaceChild(newChildren, index, newChild);
}
} else {
int searchMask = 1 << searchBucket;
if ((mask & searchMask) != 0) {
int index = index(searchMask);
HamtPMap<K, V> child = newChildren[index];
HamtPMap<K, V> newChild = child.minus(key, shift(hash), result);
if (!newChild.isEmpty()) {
newChildren = replaceChild(newChildren, index, newChild);
} else {
newChildren = deleteChild(newChildren, index);
newMask &= ~searchMask;
}
}
int replacementMask = 1 << replacementBucket;
int index = Integer.bitCount(newMask & (replacementMask - 1));
if ((mask & replacementMask) != 0) {
HamtPMap<K, V> child = newChildren[index];
HamtPMap<K, V> newChild = child.plus(this.key, shift(this.hash), this.value);
newChildren = replaceChild(newChildren, index, newChild);
} else {
newChildren =
insertChild(
newChildren,
index,
new HamtPMap<>(this.key, shift(this.hash), this.value, 0, emptyChildren()));
newMask |= replacementMask;
}
}
}
return parent != null
? new HamtPMap<>(parent.key, shift(parent.hash), parent.value, newMask, newChildren)
: new HamtPMap<>(key, hash, result[0], newMask, newChildren);
} | [
"private",
"HamtPMap",
"<",
"K",
",",
"V",
">",
"pivot",
"(",
"K",
"key",
",",
"int",
"hash",
",",
"HamtPMap",
"<",
"K",
",",
"V",
">",
"parent",
",",
"V",
"[",
"]",
"result",
")",
"{",
"int",
"newMask",
"=",
"mask",
";",
"HamtPMap",
"<",
"K",
",",
"V",
">",
"[",
"]",
"newChildren",
"=",
"this",
".",
"children",
";",
"if",
"(",
"hash",
"==",
"this",
".",
"hash",
"&&",
"key",
".",
"equals",
"(",
"this",
".",
"key",
")",
")",
"{",
"// Found the key: swap out this key/value with the parent and return the result in the holder.",
"result",
"[",
"0",
"]",
"=",
"this",
".",
"value",
";",
"}",
"else",
"{",
"// Otherwise, see if the value might be present in a child.",
"int",
"searchBucket",
"=",
"bucket",
"(",
"hash",
")",
";",
"int",
"replacementBucket",
"=",
"bucket",
"(",
"this",
".",
"hash",
")",
";",
"if",
"(",
"searchBucket",
"==",
"replacementBucket",
")",
"{",
"int",
"bucketMask",
"=",
"1",
"<<",
"searchBucket",
";",
"if",
"(",
"(",
"mask",
"&",
"bucketMask",
")",
"!=",
"0",
")",
"{",
"// Found a child, call pivot recursively.",
"int",
"index",
"=",
"index",
"(",
"bucketMask",
")",
";",
"HamtPMap",
"<",
"K",
",",
"V",
">",
"child",
"=",
"newChildren",
"[",
"index",
"]",
";",
"HamtPMap",
"<",
"K",
",",
"V",
">",
"newChild",
"=",
"child",
".",
"pivot",
"(",
"key",
",",
"shift",
"(",
"hash",
")",
",",
"this",
",",
"result",
")",
";",
"newChildren",
"=",
"replaceChild",
"(",
"newChildren",
",",
"index",
",",
"newChild",
")",
";",
"}",
"}",
"else",
"{",
"int",
"searchMask",
"=",
"1",
"<<",
"searchBucket",
";",
"if",
"(",
"(",
"mask",
"&",
"searchMask",
")",
"!=",
"0",
")",
"{",
"int",
"index",
"=",
"index",
"(",
"searchMask",
")",
";",
"HamtPMap",
"<",
"K",
",",
"V",
">",
"child",
"=",
"newChildren",
"[",
"index",
"]",
";",
"HamtPMap",
"<",
"K",
",",
"V",
">",
"newChild",
"=",
"child",
".",
"minus",
"(",
"key",
",",
"shift",
"(",
"hash",
")",
",",
"result",
")",
";",
"if",
"(",
"!",
"newChild",
".",
"isEmpty",
"(",
")",
")",
"{",
"newChildren",
"=",
"replaceChild",
"(",
"newChildren",
",",
"index",
",",
"newChild",
")",
";",
"}",
"else",
"{",
"newChildren",
"=",
"deleteChild",
"(",
"newChildren",
",",
"index",
")",
";",
"newMask",
"&=",
"~",
"searchMask",
";",
"}",
"}",
"int",
"replacementMask",
"=",
"1",
"<<",
"replacementBucket",
";",
"int",
"index",
"=",
"Integer",
".",
"bitCount",
"(",
"newMask",
"&",
"(",
"replacementMask",
"-",
"1",
")",
")",
";",
"if",
"(",
"(",
"mask",
"&",
"replacementMask",
")",
"!=",
"0",
")",
"{",
"HamtPMap",
"<",
"K",
",",
"V",
">",
"child",
"=",
"newChildren",
"[",
"index",
"]",
";",
"HamtPMap",
"<",
"K",
",",
"V",
">",
"newChild",
"=",
"child",
".",
"plus",
"(",
"this",
".",
"key",
",",
"shift",
"(",
"this",
".",
"hash",
")",
",",
"this",
".",
"value",
")",
";",
"newChildren",
"=",
"replaceChild",
"(",
"newChildren",
",",
"index",
",",
"newChild",
")",
";",
"}",
"else",
"{",
"newChildren",
"=",
"insertChild",
"(",
"newChildren",
",",
"index",
",",
"new",
"HamtPMap",
"<>",
"(",
"this",
".",
"key",
",",
"shift",
"(",
"this",
".",
"hash",
")",
",",
"this",
".",
"value",
",",
"0",
",",
"emptyChildren",
"(",
")",
")",
")",
";",
"newMask",
"|=",
"replacementMask",
";",
"}",
"}",
"}",
"return",
"parent",
"!=",
"null",
"?",
"new",
"HamtPMap",
"<>",
"(",
"parent",
".",
"key",
",",
"shift",
"(",
"parent",
".",
"hash",
")",
",",
"parent",
".",
"value",
",",
"newMask",
",",
"newChildren",
")",
":",
"new",
"HamtPMap",
"<>",
"(",
"key",
",",
"hash",
",",
"result",
"[",
"0",
"]",
",",
"newMask",
",",
"newChildren",
")",
";",
"}"
] | Internal recursive version of pivot. If parent is null then the result is used for the value in
the returned map. The value, if found, is stored in the 'result' array as a secondary return. | [
"Internal",
"recursive",
"version",
"of",
"pivot",
".",
"If",
"parent",
"is",
"null",
"then",
"the",
"result",
"is",
"used",
"for",
"the",
"value",
"in",
"the",
"returned",
"map",
".",
"The",
"value",
"if",
"found",
"is",
"stored",
"in",
"the",
"result",
"array",
"as",
"a",
"secondary",
"return",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/rhino/HamtPMap.java#L484-L536 |
24,068 | google/closure-compiler | src/com/google/javascript/rhino/HamtPMap.java | HamtPMap.vacateRoot | private HamtPMap<K, V> vacateRoot() {
int bucket = bucket(this.hash);
int bucketMask = 1 << bucket;
int index = index(bucketMask);
if ((mask & bucketMask) != 0) {
HamtPMap<K, V> newChild = children[index].plus(this.key, shift(this.hash), this.value);
return new HamtPMap<>(null, 0, null, mask, replaceChild(children, index, newChild));
}
HamtPMap<K, V> newChild =
new HamtPMap<>(this.key, shift(this.hash), this.value, 0, emptyChildren());
return new HamtPMap<>(null, 0, null, mask | bucketMask, insertChild(children, index, newChild));
} | java | private HamtPMap<K, V> vacateRoot() {
int bucket = bucket(this.hash);
int bucketMask = 1 << bucket;
int index = index(bucketMask);
if ((mask & bucketMask) != 0) {
HamtPMap<K, V> newChild = children[index].plus(this.key, shift(this.hash), this.value);
return new HamtPMap<>(null, 0, null, mask, replaceChild(children, index, newChild));
}
HamtPMap<K, V> newChild =
new HamtPMap<>(this.key, shift(this.hash), this.value, 0, emptyChildren());
return new HamtPMap<>(null, 0, null, mask | bucketMask, insertChild(children, index, newChild));
} | [
"private",
"HamtPMap",
"<",
"K",
",",
"V",
">",
"vacateRoot",
"(",
")",
"{",
"int",
"bucket",
"=",
"bucket",
"(",
"this",
".",
"hash",
")",
";",
"int",
"bucketMask",
"=",
"1",
"<<",
"bucket",
";",
"int",
"index",
"=",
"index",
"(",
"bucketMask",
")",
";",
"if",
"(",
"(",
"mask",
"&",
"bucketMask",
")",
"!=",
"0",
")",
"{",
"HamtPMap",
"<",
"K",
",",
"V",
">",
"newChild",
"=",
"children",
"[",
"index",
"]",
".",
"plus",
"(",
"this",
".",
"key",
",",
"shift",
"(",
"this",
".",
"hash",
")",
",",
"this",
".",
"value",
")",
";",
"return",
"new",
"HamtPMap",
"<>",
"(",
"null",
",",
"0",
",",
"null",
",",
"mask",
",",
"replaceChild",
"(",
"children",
",",
"index",
",",
"newChild",
")",
")",
";",
"}",
"HamtPMap",
"<",
"K",
",",
"V",
">",
"newChild",
"=",
"new",
"HamtPMap",
"<>",
"(",
"this",
".",
"key",
",",
"shift",
"(",
"this",
".",
"hash",
")",
",",
"this",
".",
"value",
",",
"0",
",",
"emptyChildren",
"(",
")",
")",
";",
"return",
"new",
"HamtPMap",
"<>",
"(",
"null",
",",
"0",
",",
"null",
",",
"mask",
"|",
"bucketMask",
",",
"insertChild",
"(",
"children",
",",
"index",
",",
"newChild",
")",
")",
";",
"}"
] | Moves the root into the appropriate child. | [
"Moves",
"the",
"root",
"into",
"the",
"appropriate",
"child",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/rhino/HamtPMap.java#L539-L550 |
24,069 | google/closure-compiler | src/com/google/javascript/rhino/HamtPMap.java | HamtPMap.withChildren | private HamtPMap<K, V> withChildren(int mask, HamtPMap<K, V>[] children) {
return mask == this.mask && children == this.children
? this
: new HamtPMap<>(key, hash, value, mask, children);
} | java | private HamtPMap<K, V> withChildren(int mask, HamtPMap<K, V>[] children) {
return mask == this.mask && children == this.children
? this
: new HamtPMap<>(key, hash, value, mask, children);
} | [
"private",
"HamtPMap",
"<",
"K",
",",
"V",
">",
"withChildren",
"(",
"int",
"mask",
",",
"HamtPMap",
"<",
"K",
",",
"V",
">",
"[",
"]",
"children",
")",
"{",
"return",
"mask",
"==",
"this",
".",
"mask",
"&&",
"children",
"==",
"this",
".",
"children",
"?",
"this",
":",
"new",
"HamtPMap",
"<>",
"(",
"key",
",",
"hash",
",",
"value",
",",
"mask",
",",
"children",
")",
";",
"}"
] | Returns a copy of this node with a different array of children. | [
"Returns",
"a",
"copy",
"of",
"this",
"node",
"with",
"a",
"different",
"array",
"of",
"children",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/rhino/HamtPMap.java#L553-L557 |
24,070 | google/closure-compiler | src/com/google/javascript/rhino/HamtPMap.java | HamtPMap.deleteRoot | private static <K, V> HamtPMap<K, V> deleteRoot(int mask, HamtPMap<K, V>[] children) {
if (mask == 0) {
return null;
}
HamtPMap<K, V> child = children[0];
int hashBits = Integer.numberOfTrailingZeros(mask);
int newHash = unshift(child.hash, hashBits);
HamtPMap<K, V> newChild = deleteRoot(child.mask, child.children);
if (newChild == null) {
int newMask = mask & ~Integer.lowestOneBit(mask);
return new HamtPMap<>(child.key, newHash, child.value, newMask, deleteChild(children, 0));
} else {
return new HamtPMap<>(
child.key, newHash, child.value, mask, replaceChild(children, 0, newChild));
}
} | java | private static <K, V> HamtPMap<K, V> deleteRoot(int mask, HamtPMap<K, V>[] children) {
if (mask == 0) {
return null;
}
HamtPMap<K, V> child = children[0];
int hashBits = Integer.numberOfTrailingZeros(mask);
int newHash = unshift(child.hash, hashBits);
HamtPMap<K, V> newChild = deleteRoot(child.mask, child.children);
if (newChild == null) {
int newMask = mask & ~Integer.lowestOneBit(mask);
return new HamtPMap<>(child.key, newHash, child.value, newMask, deleteChild(children, 0));
} else {
return new HamtPMap<>(
child.key, newHash, child.value, mask, replaceChild(children, 0, newChild));
}
} | [
"private",
"static",
"<",
"K",
",",
"V",
">",
"HamtPMap",
"<",
"K",
",",
"V",
">",
"deleteRoot",
"(",
"int",
"mask",
",",
"HamtPMap",
"<",
"K",
",",
"V",
">",
"[",
"]",
"children",
")",
"{",
"if",
"(",
"mask",
"==",
"0",
")",
"{",
"return",
"null",
";",
"}",
"HamtPMap",
"<",
"K",
",",
"V",
">",
"child",
"=",
"children",
"[",
"0",
"]",
";",
"int",
"hashBits",
"=",
"Integer",
".",
"numberOfTrailingZeros",
"(",
"mask",
")",
";",
"int",
"newHash",
"=",
"unshift",
"(",
"child",
".",
"hash",
",",
"hashBits",
")",
";",
"HamtPMap",
"<",
"K",
",",
"V",
">",
"newChild",
"=",
"deleteRoot",
"(",
"child",
".",
"mask",
",",
"child",
".",
"children",
")",
";",
"if",
"(",
"newChild",
"==",
"null",
")",
"{",
"int",
"newMask",
"=",
"mask",
"&",
"~",
"Integer",
".",
"lowestOneBit",
"(",
"mask",
")",
";",
"return",
"new",
"HamtPMap",
"<>",
"(",
"child",
".",
"key",
",",
"newHash",
",",
"child",
".",
"value",
",",
"newMask",
",",
"deleteChild",
"(",
"children",
",",
"0",
")",
")",
";",
"}",
"else",
"{",
"return",
"new",
"HamtPMap",
"<>",
"(",
"child",
".",
"key",
",",
"newHash",
",",
"child",
".",
"value",
",",
"mask",
",",
"replaceChild",
"(",
"children",
",",
"0",
",",
"newChild",
")",
")",
";",
"}",
"}"
] | Returns a new map with the elements from children. One element is removed from one of the
children and promoted to a root node. If there are no children, returns null. | [
"Returns",
"a",
"new",
"map",
"with",
"the",
"elements",
"from",
"children",
".",
"One",
"element",
"is",
"removed",
"from",
"one",
"of",
"the",
"children",
"and",
"promoted",
"to",
"a",
"root",
"node",
".",
"If",
"there",
"are",
"no",
"children",
"returns",
"null",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/rhino/HamtPMap.java#L563-L578 |
24,071 | google/closure-compiler | src/com/google/javascript/rhino/HamtPMap.java | HamtPMap.insertChild | private static <K, V> HamtPMap<K, V>[] insertChild(
HamtPMap<K, V>[] children, int index, HamtPMap<K, V> child) {
@SuppressWarnings("unchecked") // only used internally.
HamtPMap<K, V>[] newChildren = (HamtPMap<K, V>[]) new HamtPMap<?, ?>[children.length + 1];
newChildren[index] = child;
System.arraycopy(children, 0, newChildren, 0, index);
System.arraycopy(children, index, newChildren, index + 1, children.length - index);
return newChildren;
} | java | private static <K, V> HamtPMap<K, V>[] insertChild(
HamtPMap<K, V>[] children, int index, HamtPMap<K, V> child) {
@SuppressWarnings("unchecked") // only used internally.
HamtPMap<K, V>[] newChildren = (HamtPMap<K, V>[]) new HamtPMap<?, ?>[children.length + 1];
newChildren[index] = child;
System.arraycopy(children, 0, newChildren, 0, index);
System.arraycopy(children, index, newChildren, index + 1, children.length - index);
return newChildren;
} | [
"private",
"static",
"<",
"K",
",",
"V",
">",
"HamtPMap",
"<",
"K",
",",
"V",
">",
"[",
"]",
"insertChild",
"(",
"HamtPMap",
"<",
"K",
",",
"V",
">",
"[",
"]",
"children",
",",
"int",
"index",
",",
"HamtPMap",
"<",
"K",
",",
"V",
">",
"child",
")",
"{",
"@",
"SuppressWarnings",
"(",
"\"unchecked\"",
")",
"// only used internally.",
"HamtPMap",
"<",
"K",
",",
"V",
">",
"[",
"]",
"newChildren",
"=",
"(",
"HamtPMap",
"<",
"K",
",",
"V",
">",
"[",
"]",
")",
"new",
"HamtPMap",
"<",
"?",
",",
"?",
">",
"[",
"children",
".",
"length",
"+",
"1",
"]",
";",
"newChildren",
"[",
"index",
"]",
"=",
"child",
";",
"System",
".",
"arraycopy",
"(",
"children",
",",
"0",
",",
"newChildren",
",",
"0",
",",
"index",
")",
";",
"System",
".",
"arraycopy",
"(",
"children",
",",
"index",
",",
"newChildren",
",",
"index",
"+",
"1",
",",
"children",
".",
"length",
"-",
"index",
")",
";",
"return",
"newChildren",
";",
"}"
] | Returns a new array of children with an additional child inserted at the given index. | [
"Returns",
"a",
"new",
"array",
"of",
"children",
"with",
"an",
"additional",
"child",
"inserted",
"at",
"the",
"given",
"index",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/rhino/HamtPMap.java#L581-L589 |
24,072 | google/closure-compiler | src/com/google/javascript/rhino/HamtPMap.java | HamtPMap.replaceChild | private static <K, V> HamtPMap<K, V>[] replaceChild(
HamtPMap<K, V>[] children, int index, HamtPMap<K, V> child) {
HamtPMap<K, V>[] newChildren = Arrays.copyOf(children, children.length);
newChildren[index] = child;
return newChildren;
} | java | private static <K, V> HamtPMap<K, V>[] replaceChild(
HamtPMap<K, V>[] children, int index, HamtPMap<K, V> child) {
HamtPMap<K, V>[] newChildren = Arrays.copyOf(children, children.length);
newChildren[index] = child;
return newChildren;
} | [
"private",
"static",
"<",
"K",
",",
"V",
">",
"HamtPMap",
"<",
"K",
",",
"V",
">",
"[",
"]",
"replaceChild",
"(",
"HamtPMap",
"<",
"K",
",",
"V",
">",
"[",
"]",
"children",
",",
"int",
"index",
",",
"HamtPMap",
"<",
"K",
",",
"V",
">",
"child",
")",
"{",
"HamtPMap",
"<",
"K",
",",
"V",
">",
"[",
"]",
"newChildren",
"=",
"Arrays",
".",
"copyOf",
"(",
"children",
",",
"children",
".",
"length",
")",
";",
"newChildren",
"[",
"index",
"]",
"=",
"child",
";",
"return",
"newChildren",
";",
"}"
] | Returns a new array of children with the child at the given index replaced. | [
"Returns",
"a",
"new",
"array",
"of",
"children",
"with",
"the",
"child",
"at",
"the",
"given",
"index",
"replaced",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/rhino/HamtPMap.java#L592-L597 |
24,073 | google/closure-compiler | src/com/google/javascript/rhino/HamtPMap.java | HamtPMap.deleteChild | private static <K, V> HamtPMap<K, V>[] deleteChild(
HamtPMap<K, V>[] children, int index) {
if (children.length == 1) {
// Note: index should always be zero.
return emptyChildren();
}
@SuppressWarnings("unchecked") // only used internally.
HamtPMap<K, V>[] newChildren = (HamtPMap<K, V>[]) new HamtPMap<?, ?>[children.length - 1];
System.arraycopy(children, 0, newChildren, 0, index);
System.arraycopy(children, index + 1, newChildren, index, children.length - index - 1);
return newChildren;
} | java | private static <K, V> HamtPMap<K, V>[] deleteChild(
HamtPMap<K, V>[] children, int index) {
if (children.length == 1) {
// Note: index should always be zero.
return emptyChildren();
}
@SuppressWarnings("unchecked") // only used internally.
HamtPMap<K, V>[] newChildren = (HamtPMap<K, V>[]) new HamtPMap<?, ?>[children.length - 1];
System.arraycopy(children, 0, newChildren, 0, index);
System.arraycopy(children, index + 1, newChildren, index, children.length - index - 1);
return newChildren;
} | [
"private",
"static",
"<",
"K",
",",
"V",
">",
"HamtPMap",
"<",
"K",
",",
"V",
">",
"[",
"]",
"deleteChild",
"(",
"HamtPMap",
"<",
"K",
",",
"V",
">",
"[",
"]",
"children",
",",
"int",
"index",
")",
"{",
"if",
"(",
"children",
".",
"length",
"==",
"1",
")",
"{",
"// Note: index should always be zero.",
"return",
"emptyChildren",
"(",
")",
";",
"}",
"@",
"SuppressWarnings",
"(",
"\"unchecked\"",
")",
"// only used internally.",
"HamtPMap",
"<",
"K",
",",
"V",
">",
"[",
"]",
"newChildren",
"=",
"(",
"HamtPMap",
"<",
"K",
",",
"V",
">",
"[",
"]",
")",
"new",
"HamtPMap",
"<",
"?",
",",
"?",
">",
"[",
"children",
".",
"length",
"-",
"1",
"]",
";",
"System",
".",
"arraycopy",
"(",
"children",
",",
"0",
",",
"newChildren",
",",
"0",
",",
"index",
")",
";",
"System",
".",
"arraycopy",
"(",
"children",
",",
"index",
"+",
"1",
",",
"newChildren",
",",
"index",
",",
"children",
".",
"length",
"-",
"index",
"-",
"1",
")",
";",
"return",
"newChildren",
";",
"}"
] | Returns a new array of children with the child at the given index deleted. | [
"Returns",
"a",
"new",
"array",
"of",
"children",
"with",
"the",
"child",
"at",
"the",
"given",
"index",
"deleted",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/rhino/HamtPMap.java#L600-L611 |
24,074 | google/closure-compiler | src/com/google/javascript/jscomp/IncrementalScopeCreator.java | IncrementalScopeCreator.getInstance | public static IncrementalScopeCreator getInstance(AbstractCompiler compiler) {
IncrementalScopeCreator creator = compiler.getScopeCreator();
if (creator == null) {
creator = new IncrementalScopeCreator(compiler);
compiler.putScopeCreator(creator);
}
return creator;
} | java | public static IncrementalScopeCreator getInstance(AbstractCompiler compiler) {
IncrementalScopeCreator creator = compiler.getScopeCreator();
if (creator == null) {
creator = new IncrementalScopeCreator(compiler);
compiler.putScopeCreator(creator);
}
return creator;
} | [
"public",
"static",
"IncrementalScopeCreator",
"getInstance",
"(",
"AbstractCompiler",
"compiler",
")",
"{",
"IncrementalScopeCreator",
"creator",
"=",
"compiler",
".",
"getScopeCreator",
"(",
")",
";",
"if",
"(",
"creator",
"==",
"null",
")",
"{",
"creator",
"=",
"new",
"IncrementalScopeCreator",
"(",
"compiler",
")",
";",
"compiler",
".",
"putScopeCreator",
"(",
"creator",
")",
";",
"}",
"return",
"creator",
";",
"}"
] | Get an instance of the ScopeCreator | [
"Get",
"an",
"instance",
"of",
"the",
"ScopeCreator"
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/IncrementalScopeCreator.java#L65-L72 |
24,075 | google/closure-compiler | src/com/google/javascript/jscomp/bundle/Source.java | Source.builder | public static Builder builder() {
return new AutoValue_Source.Builder()
.setPath(DEV_NULL)
.setCode("")
.setOriginalCodeSupplier(null)
.setSourceMap("")
.setSourceUrl("")
.setSourceMappingUrl("")
.setRuntimes(ImmutableSet.of())
.setLoadFlags(ImmutableMap.of())
.setEstimatedSize(0);
} | java | public static Builder builder() {
return new AutoValue_Source.Builder()
.setPath(DEV_NULL)
.setCode("")
.setOriginalCodeSupplier(null)
.setSourceMap("")
.setSourceUrl("")
.setSourceMappingUrl("")
.setRuntimes(ImmutableSet.of())
.setLoadFlags(ImmutableMap.of())
.setEstimatedSize(0);
} | [
"public",
"static",
"Builder",
"builder",
"(",
")",
"{",
"return",
"new",
"AutoValue_Source",
".",
"Builder",
"(",
")",
".",
"setPath",
"(",
"DEV_NULL",
")",
".",
"setCode",
"(",
"\"\"",
")",
".",
"setOriginalCodeSupplier",
"(",
"null",
")",
".",
"setSourceMap",
"(",
"\"\"",
")",
".",
"setSourceUrl",
"(",
"\"\"",
")",
".",
"setSourceMappingUrl",
"(",
"\"\"",
")",
".",
"setRuntimes",
"(",
"ImmutableSet",
".",
"of",
"(",
")",
")",
".",
"setLoadFlags",
"(",
"ImmutableMap",
".",
"of",
"(",
")",
")",
".",
"setEstimatedSize",
"(",
"0",
")",
";",
"}"
] | Makes a new empty builder. | [
"Makes",
"a",
"new",
"empty",
"builder",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/bundle/Source.java#L75-L86 |
24,076 | google/closure-compiler | src/com/google/javascript/jscomp/ChangeVerifier.java | ChangeVerifier.associateClones | private void associateClones(Node n, Node snapshot) {
// TODO(johnlenz): determine if MODULE_BODY is useful here.
if (n.isRoot() || NodeUtil.isChangeScopeRoot(n)) {
clonesByCurrent.put(n, snapshot);
}
Node child = n.getFirstChild();
Node snapshotChild = snapshot.getFirstChild();
while (child != null) {
associateClones(child, snapshotChild);
child = child.getNext();
snapshotChild = snapshotChild.getNext();
}
} | java | private void associateClones(Node n, Node snapshot) {
// TODO(johnlenz): determine if MODULE_BODY is useful here.
if (n.isRoot() || NodeUtil.isChangeScopeRoot(n)) {
clonesByCurrent.put(n, snapshot);
}
Node child = n.getFirstChild();
Node snapshotChild = snapshot.getFirstChild();
while (child != null) {
associateClones(child, snapshotChild);
child = child.getNext();
snapshotChild = snapshotChild.getNext();
}
} | [
"private",
"void",
"associateClones",
"(",
"Node",
"n",
",",
"Node",
"snapshot",
")",
"{",
"// TODO(johnlenz): determine if MODULE_BODY is useful here.",
"if",
"(",
"n",
".",
"isRoot",
"(",
")",
"||",
"NodeUtil",
".",
"isChangeScopeRoot",
"(",
"n",
")",
")",
"{",
"clonesByCurrent",
".",
"put",
"(",
"n",
",",
"snapshot",
")",
";",
"}",
"Node",
"child",
"=",
"n",
".",
"getFirstChild",
"(",
")",
";",
"Node",
"snapshotChild",
"=",
"snapshot",
".",
"getFirstChild",
"(",
")",
";",
"while",
"(",
"child",
"!=",
"null",
")",
"{",
"associateClones",
"(",
"child",
",",
"snapshotChild",
")",
";",
"child",
"=",
"child",
".",
"getNext",
"(",
")",
";",
"snapshotChild",
"=",
"snapshotChild",
".",
"getNext",
"(",
")",
";",
"}",
"}"
] | Given an AST and its copy, map the root node of each scope of main to the
corresponding root node of clone | [
"Given",
"an",
"AST",
"and",
"its",
"copy",
"map",
"the",
"root",
"node",
"of",
"each",
"scope",
"of",
"main",
"to",
"the",
"corresponding",
"root",
"node",
"of",
"clone"
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/ChangeVerifier.java#L62-L75 |
24,077 | google/closure-compiler | src/com/google/javascript/jscomp/ChangeVerifier.java | ChangeVerifier.verifyScopeChangesHaveBeenRecorded | private void verifyScopeChangesHaveBeenRecorded(String passName, Node root) {
final String passNameMsg = passName.isEmpty() ? "" : passName + ": ";
// Gather all the scope nodes that existed when the snapshot was taken.
final Set<Node> snapshotScopeNodes = new HashSet<>();
NodeUtil.visitPreOrder(
clonesByCurrent.get(root),
new Visitor() {
@Override
public void visit(Node oldNode) {
if (NodeUtil.isChangeScopeRoot(oldNode)) {
snapshotScopeNodes.add(oldNode);
}
}
});
NodeUtil.visitPreOrder(
root,
new Visitor() {
@Override
public void visit(Node n) {
if (n.isRoot()) {
verifyRoot(n);
} else if (NodeUtil.isChangeScopeRoot(n)) {
Node clone = clonesByCurrent.get(n);
// Remove any scope nodes that still exist.
snapshotScopeNodes.remove(clone);
verifyNode(passNameMsg, n);
if (clone == null) {
verifyNewNode(passNameMsg, n);
} else {
verifyNodeChange(passNameMsg, n, clone);
}
}
}
});
// Only actually deleted snapshot scope nodes should remain.
verifyDeletedScopeNodes(passNameMsg, snapshotScopeNodes);
} | java | private void verifyScopeChangesHaveBeenRecorded(String passName, Node root) {
final String passNameMsg = passName.isEmpty() ? "" : passName + ": ";
// Gather all the scope nodes that existed when the snapshot was taken.
final Set<Node> snapshotScopeNodes = new HashSet<>();
NodeUtil.visitPreOrder(
clonesByCurrent.get(root),
new Visitor() {
@Override
public void visit(Node oldNode) {
if (NodeUtil.isChangeScopeRoot(oldNode)) {
snapshotScopeNodes.add(oldNode);
}
}
});
NodeUtil.visitPreOrder(
root,
new Visitor() {
@Override
public void visit(Node n) {
if (n.isRoot()) {
verifyRoot(n);
} else if (NodeUtil.isChangeScopeRoot(n)) {
Node clone = clonesByCurrent.get(n);
// Remove any scope nodes that still exist.
snapshotScopeNodes.remove(clone);
verifyNode(passNameMsg, n);
if (clone == null) {
verifyNewNode(passNameMsg, n);
} else {
verifyNodeChange(passNameMsg, n, clone);
}
}
}
});
// Only actually deleted snapshot scope nodes should remain.
verifyDeletedScopeNodes(passNameMsg, snapshotScopeNodes);
} | [
"private",
"void",
"verifyScopeChangesHaveBeenRecorded",
"(",
"String",
"passName",
",",
"Node",
"root",
")",
"{",
"final",
"String",
"passNameMsg",
"=",
"passName",
".",
"isEmpty",
"(",
")",
"?",
"\"\"",
":",
"passName",
"+",
"\": \"",
";",
"// Gather all the scope nodes that existed when the snapshot was taken.",
"final",
"Set",
"<",
"Node",
">",
"snapshotScopeNodes",
"=",
"new",
"HashSet",
"<>",
"(",
")",
";",
"NodeUtil",
".",
"visitPreOrder",
"(",
"clonesByCurrent",
".",
"get",
"(",
"root",
")",
",",
"new",
"Visitor",
"(",
")",
"{",
"@",
"Override",
"public",
"void",
"visit",
"(",
"Node",
"oldNode",
")",
"{",
"if",
"(",
"NodeUtil",
".",
"isChangeScopeRoot",
"(",
"oldNode",
")",
")",
"{",
"snapshotScopeNodes",
".",
"add",
"(",
"oldNode",
")",
";",
"}",
"}",
"}",
")",
";",
"NodeUtil",
".",
"visitPreOrder",
"(",
"root",
",",
"new",
"Visitor",
"(",
")",
"{",
"@",
"Override",
"public",
"void",
"visit",
"(",
"Node",
"n",
")",
"{",
"if",
"(",
"n",
".",
"isRoot",
"(",
")",
")",
"{",
"verifyRoot",
"(",
"n",
")",
";",
"}",
"else",
"if",
"(",
"NodeUtil",
".",
"isChangeScopeRoot",
"(",
"n",
")",
")",
"{",
"Node",
"clone",
"=",
"clonesByCurrent",
".",
"get",
"(",
"n",
")",
";",
"// Remove any scope nodes that still exist.",
"snapshotScopeNodes",
".",
"remove",
"(",
"clone",
")",
";",
"verifyNode",
"(",
"passNameMsg",
",",
"n",
")",
";",
"if",
"(",
"clone",
"==",
"null",
")",
"{",
"verifyNewNode",
"(",
"passNameMsg",
",",
"n",
")",
";",
"}",
"else",
"{",
"verifyNodeChange",
"(",
"passNameMsg",
",",
"n",
",",
"clone",
")",
";",
"}",
"}",
"}",
"}",
")",
";",
"// Only actually deleted snapshot scope nodes should remain.",
"verifyDeletedScopeNodes",
"(",
"passNameMsg",
",",
"snapshotScopeNodes",
")",
";",
"}"
] | Checks that the scope roots marked as changed have indeed changed | [
"Checks",
"that",
"the",
"scope",
"roots",
"marked",
"as",
"changed",
"have",
"indeed",
"changed"
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/ChangeVerifier.java#L78-L117 |
24,078 | google/closure-compiler | src/com/google/javascript/rhino/jstype/FunctionParamBuilder.java | FunctionParamBuilder.addRequiredParams | public boolean addRequiredParams(JSType ...types) {
if (hasOptionalOrVarArgs()) {
return false;
}
for (JSType type : types) {
newParameter(type);
}
return true;
} | java | public boolean addRequiredParams(JSType ...types) {
if (hasOptionalOrVarArgs()) {
return false;
}
for (JSType type : types) {
newParameter(type);
}
return true;
} | [
"public",
"boolean",
"addRequiredParams",
"(",
"JSType",
"...",
"types",
")",
"{",
"if",
"(",
"hasOptionalOrVarArgs",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"for",
"(",
"JSType",
"type",
":",
"types",
")",
"{",
"newParameter",
"(",
"type",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Add parameters of the given type to the end of the param list.
@return False if this is called after optional params are added. | [
"Add",
"parameters",
"of",
"the",
"given",
"type",
"to",
"the",
"end",
"of",
"the",
"param",
"list",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/rhino/jstype/FunctionParamBuilder.java#L62-L71 |
24,079 | google/closure-compiler | src/com/google/javascript/rhino/jstype/FunctionParamBuilder.java | FunctionParamBuilder.addOptionalParams | public boolean addOptionalParams(JSType ...types) {
if (hasVarArgs()) {
return false;
}
for (JSType type : types) {
newParameter(registry.createOptionalType(type)).setOptionalArg(true);
}
return true;
} | java | public boolean addOptionalParams(JSType ...types) {
if (hasVarArgs()) {
return false;
}
for (JSType type : types) {
newParameter(registry.createOptionalType(type)).setOptionalArg(true);
}
return true;
} | [
"public",
"boolean",
"addOptionalParams",
"(",
"JSType",
"...",
"types",
")",
"{",
"if",
"(",
"hasVarArgs",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"for",
"(",
"JSType",
"type",
":",
"types",
")",
"{",
"newParameter",
"(",
"registry",
".",
"createOptionalType",
"(",
"type",
")",
")",
".",
"setOptionalArg",
"(",
"true",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Add optional parameters of the given type to the end of the param list.
@param types Types for each optional parameter. The builder will make them
undefine-able.
@return False if this is called after var args are added. | [
"Add",
"optional",
"parameters",
"of",
"the",
"given",
"type",
"to",
"the",
"end",
"of",
"the",
"param",
"list",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/rhino/jstype/FunctionParamBuilder.java#L79-L88 |
24,080 | google/closure-compiler | src/com/google/javascript/rhino/jstype/FunctionParamBuilder.java | FunctionParamBuilder.addVarArgs | public boolean addVarArgs(JSType type) {
if (hasVarArgs()) {
return false;
}
newParameter(type).setVarArgs(true);
return true;
} | java | public boolean addVarArgs(JSType type) {
if (hasVarArgs()) {
return false;
}
newParameter(type).setVarArgs(true);
return true;
} | [
"public",
"boolean",
"addVarArgs",
"(",
"JSType",
"type",
")",
"{",
"if",
"(",
"hasVarArgs",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"newParameter",
"(",
"type",
")",
".",
"setVarArgs",
"(",
"true",
")",
";",
"return",
"true",
";",
"}"
] | Add variable arguments to the end of the parameter list.
@return False if this is called after var args are added. | [
"Add",
"variable",
"arguments",
"to",
"the",
"end",
"of",
"the",
"parameter",
"list",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/rhino/jstype/FunctionParamBuilder.java#L94-L101 |
24,081 | google/closure-compiler | src/com/google/javascript/rhino/jstype/FunctionParamBuilder.java | FunctionParamBuilder.newParameterFromNode | public Node newParameterFromNode(Node n) {
Node newParam = newParameter(n.getJSType());
newParam.setVarArgs(n.isVarArgs());
newParam.setOptionalArg(n.isOptionalArg());
return newParam;
} | java | public Node newParameterFromNode(Node n) {
Node newParam = newParameter(n.getJSType());
newParam.setVarArgs(n.isVarArgs());
newParam.setOptionalArg(n.isOptionalArg());
return newParam;
} | [
"public",
"Node",
"newParameterFromNode",
"(",
"Node",
"n",
")",
"{",
"Node",
"newParam",
"=",
"newParameter",
"(",
"n",
".",
"getJSType",
"(",
")",
")",
";",
"newParam",
".",
"setVarArgs",
"(",
"n",
".",
"isVarArgs",
"(",
")",
")",
";",
"newParam",
".",
"setOptionalArg",
"(",
"n",
".",
"isOptionalArg",
"(",
")",
")",
";",
"return",
"newParam",
";",
"}"
] | Copies the parameter specification from the given node. | [
"Copies",
"the",
"parameter",
"specification",
"from",
"the",
"given",
"node",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/rhino/jstype/FunctionParamBuilder.java#L106-L111 |
24,082 | google/closure-compiler | src/com/google/javascript/rhino/jstype/FunctionParamBuilder.java | FunctionParamBuilder.newOptionalParameterFromNode | public Node newOptionalParameterFromNode(Node n) {
Node newParam = newParameterFromNode(n);
if (!newParam.isVarArgs() && !newParam.isOptionalArg()) {
newParam.setOptionalArg(true);
}
return newParam;
} | java | public Node newOptionalParameterFromNode(Node n) {
Node newParam = newParameterFromNode(n);
if (!newParam.isVarArgs() && !newParam.isOptionalArg()) {
newParam.setOptionalArg(true);
}
return newParam;
} | [
"public",
"Node",
"newOptionalParameterFromNode",
"(",
"Node",
"n",
")",
"{",
"Node",
"newParam",
"=",
"newParameterFromNode",
"(",
"n",
")",
";",
"if",
"(",
"!",
"newParam",
".",
"isVarArgs",
"(",
")",
"&&",
"!",
"newParam",
".",
"isOptionalArg",
"(",
")",
")",
"{",
"newParam",
".",
"setOptionalArg",
"(",
"true",
")",
";",
"}",
"return",
"newParam",
";",
"}"
] | Copies the parameter specification from the given node,
but makes sure it's optional. | [
"Copies",
"the",
"parameter",
"specification",
"from",
"the",
"given",
"node",
"but",
"makes",
"sure",
"it",
"s",
"optional",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/rhino/jstype/FunctionParamBuilder.java#L117-L123 |
24,083 | google/closure-compiler | src/com/google/javascript/rhino/jstype/FunctionParamBuilder.java | FunctionParamBuilder.newParameter | private Node newParameter(JSType type) {
Node paramNode = Node.newString(Token.NAME, "");
paramNode.setJSType(type);
root.addChildToBack(paramNode);
return paramNode;
} | java | private Node newParameter(JSType type) {
Node paramNode = Node.newString(Token.NAME, "");
paramNode.setJSType(type);
root.addChildToBack(paramNode);
return paramNode;
} | [
"private",
"Node",
"newParameter",
"(",
"JSType",
"type",
")",
"{",
"Node",
"paramNode",
"=",
"Node",
".",
"newString",
"(",
"Token",
".",
"NAME",
",",
"\"\"",
")",
";",
"paramNode",
".",
"setJSType",
"(",
"type",
")",
";",
"root",
".",
"addChildToBack",
"(",
"paramNode",
")",
";",
"return",
"paramNode",
";",
"}"
] | Add a parameter to the list with the given type. | [
"Add",
"a",
"parameter",
"to",
"the",
"list",
"with",
"the",
"given",
"type",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/rhino/jstype/FunctionParamBuilder.java#L126-L131 |
24,084 | google/closure-compiler | src/com/google/javascript/jscomp/GatherGettersAndSetterProperties.java | GatherGettersAndSetterProperties.update | static void update(AbstractCompiler compiler, Node externs, Node root) {
compiler.setExternGetterAndSetterProperties(gather(compiler, externs));
compiler.setSourceGetterAndSetterProperties(gather(compiler, root));
} | java | static void update(AbstractCompiler compiler, Node externs, Node root) {
compiler.setExternGetterAndSetterProperties(gather(compiler, externs));
compiler.setSourceGetterAndSetterProperties(gather(compiler, root));
} | [
"static",
"void",
"update",
"(",
"AbstractCompiler",
"compiler",
",",
"Node",
"externs",
",",
"Node",
"root",
")",
"{",
"compiler",
".",
"setExternGetterAndSetterProperties",
"(",
"gather",
"(",
"compiler",
",",
"externs",
")",
")",
";",
"compiler",
".",
"setSourceGetterAndSetterProperties",
"(",
"gather",
"(",
"compiler",
",",
"root",
")",
")",
";",
"}"
] | Gathers all getters and setters in the AST. | [
"Gathers",
"all",
"getters",
"and",
"setters",
"in",
"the",
"AST",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/GatherGettersAndSetterProperties.java#L45-L48 |
24,085 | google/closure-compiler | src/com/google/javascript/jscomp/lint/CheckProvidesSorted.java | CheckProvidesSorted.formatProvide | private static String formatProvide(String namespace) {
StringBuilder sb = new StringBuilder();
sb.append("goog.provide('");
sb.append(namespace);
sb.append("');");
return sb.toString();
} | java | private static String formatProvide(String namespace) {
StringBuilder sb = new StringBuilder();
sb.append("goog.provide('");
sb.append(namespace);
sb.append("');");
return sb.toString();
} | [
"private",
"static",
"String",
"formatProvide",
"(",
"String",
"namespace",
")",
"{",
"StringBuilder",
"sb",
"=",
"new",
"StringBuilder",
"(",
")",
";",
"sb",
".",
"append",
"(",
"\"goog.provide('\"",
")",
";",
"sb",
".",
"append",
"(",
"namespace",
")",
";",
"sb",
".",
"append",
"(",
"\"');\"",
")",
";",
"return",
"sb",
".",
"toString",
"(",
")",
";",
"}"
] | Returns the code for a correctly formatted provide call. | [
"Returns",
"the",
"code",
"for",
"a",
"correctly",
"formatted",
"provide",
"call",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/lint/CheckProvidesSorted.java#L127-L135 |
24,086 | google/closure-compiler | src/com/google/javascript/jscomp/ExtractPrototypeMemberDeclarations.java | ExtractPrototypeMemberDeclarations.doExtraction | private void doExtraction(GatherExtractionInfo info) {
// Insert a global temp if we are using the USE_GLOBAL_TEMP pattern.
if (pattern == Pattern.USE_GLOBAL_TEMP) {
Node injectionPoint = compiler.getNodeForCodeInsertion(null);
Node var = NodeUtil.newVarNode(PROTOTYPE_ALIAS, null)
.useSourceInfoIfMissingFromForTree(injectionPoint);
injectionPoint.addChildToFront(var);
compiler.reportChangeToEnclosingScope(var);
}
// Go through all extraction instances and extract each of them.
for (ExtractionInstance instance : info.instances) {
extractInstance(instance);
}
} | java | private void doExtraction(GatherExtractionInfo info) {
// Insert a global temp if we are using the USE_GLOBAL_TEMP pattern.
if (pattern == Pattern.USE_GLOBAL_TEMP) {
Node injectionPoint = compiler.getNodeForCodeInsertion(null);
Node var = NodeUtil.newVarNode(PROTOTYPE_ALIAS, null)
.useSourceInfoIfMissingFromForTree(injectionPoint);
injectionPoint.addChildToFront(var);
compiler.reportChangeToEnclosingScope(var);
}
// Go through all extraction instances and extract each of them.
for (ExtractionInstance instance : info.instances) {
extractInstance(instance);
}
} | [
"private",
"void",
"doExtraction",
"(",
"GatherExtractionInfo",
"info",
")",
"{",
"// Insert a global temp if we are using the USE_GLOBAL_TEMP pattern.",
"if",
"(",
"pattern",
"==",
"Pattern",
".",
"USE_GLOBAL_TEMP",
")",
"{",
"Node",
"injectionPoint",
"=",
"compiler",
".",
"getNodeForCodeInsertion",
"(",
"null",
")",
";",
"Node",
"var",
"=",
"NodeUtil",
".",
"newVarNode",
"(",
"PROTOTYPE_ALIAS",
",",
"null",
")",
".",
"useSourceInfoIfMissingFromForTree",
"(",
"injectionPoint",
")",
";",
"injectionPoint",
".",
"addChildToFront",
"(",
"var",
")",
";",
"compiler",
".",
"reportChangeToEnclosingScope",
"(",
"var",
")",
";",
"}",
"// Go through all extraction instances and extract each of them.",
"for",
"(",
"ExtractionInstance",
"instance",
":",
"info",
".",
"instances",
")",
"{",
"extractInstance",
"(",
"instance",
")",
";",
"}",
"}"
] | Declares the temp variable to point to prototype objects and iterates
through all ExtractInstance and performs extraction there. | [
"Declares",
"the",
"temp",
"variable",
"to",
"point",
"to",
"prototype",
"objects",
"and",
"iterates",
"through",
"all",
"ExtractInstance",
"and",
"performs",
"extraction",
"there",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/ExtractPrototypeMemberDeclarations.java#L150-L165 |
24,087 | google/closure-compiler | src/com/google/javascript/jscomp/ExtractPrototypeMemberDeclarations.java | ExtractPrototypeMemberDeclarations.extractInstance | private void extractInstance(ExtractionInstance instance) {
PrototypeMemberDeclaration first = instance.declarations.get(0);
String className = first.qualifiedClassName;
if (pattern == Pattern.USE_GLOBAL_TEMP) {
// Use the temp variable to hold the prototype.
Node classNameNode = NodeUtil.newQName(compiler, className);
classNameNode.putBooleanProp(Node.IS_CONSTANT_NAME, first.constant);
Node stmt =
IR.exprResult(
IR.assign(
IR.name(PROTOTYPE_ALIAS),
IR.getprop(
classNameNode, IR.string("prototype"))))
.useSourceInfoIfMissingFromForTree(first.node);
instance.parent.addChildBefore(stmt, first.node);
compiler.reportChangeToEnclosingScope(stmt);
} else if (pattern == Pattern.USE_IIFE) {
Node block = IR.block();
Node func = IR.function(
IR.name(""),
IR.paramList(IR.name(PROTOTYPE_ALIAS)),
block);
Node call = IR.call(func,
NodeUtil.newQName(
compiler, className + ".prototype",
instance.parent, className + ".prototype"));
call.putIntProp(Node.FREE_CALL, 1);
Node stmt = IR.exprResult(call);
stmt.useSourceInfoIfMissingFromForTree(first.node);
instance.parent.addChildBefore(stmt, first.node);
compiler.reportChangeToEnclosingScope(stmt);
for (PrototypeMemberDeclaration declar : instance.declarations) {
compiler.reportChangeToEnclosingScope(declar.node);
block.addChildToBack(declar.node.detach());
}
}
// Go through each member declaration and replace it with an assignment
// to the prototype variable.
for (PrototypeMemberDeclaration declar : instance.declarations) {
replacePrototypeMemberDeclaration(declar);
}
} | java | private void extractInstance(ExtractionInstance instance) {
PrototypeMemberDeclaration first = instance.declarations.get(0);
String className = first.qualifiedClassName;
if (pattern == Pattern.USE_GLOBAL_TEMP) {
// Use the temp variable to hold the prototype.
Node classNameNode = NodeUtil.newQName(compiler, className);
classNameNode.putBooleanProp(Node.IS_CONSTANT_NAME, first.constant);
Node stmt =
IR.exprResult(
IR.assign(
IR.name(PROTOTYPE_ALIAS),
IR.getprop(
classNameNode, IR.string("prototype"))))
.useSourceInfoIfMissingFromForTree(first.node);
instance.parent.addChildBefore(stmt, first.node);
compiler.reportChangeToEnclosingScope(stmt);
} else if (pattern == Pattern.USE_IIFE) {
Node block = IR.block();
Node func = IR.function(
IR.name(""),
IR.paramList(IR.name(PROTOTYPE_ALIAS)),
block);
Node call = IR.call(func,
NodeUtil.newQName(
compiler, className + ".prototype",
instance.parent, className + ".prototype"));
call.putIntProp(Node.FREE_CALL, 1);
Node stmt = IR.exprResult(call);
stmt.useSourceInfoIfMissingFromForTree(first.node);
instance.parent.addChildBefore(stmt, first.node);
compiler.reportChangeToEnclosingScope(stmt);
for (PrototypeMemberDeclaration declar : instance.declarations) {
compiler.reportChangeToEnclosingScope(declar.node);
block.addChildToBack(declar.node.detach());
}
}
// Go through each member declaration and replace it with an assignment
// to the prototype variable.
for (PrototypeMemberDeclaration declar : instance.declarations) {
replacePrototypeMemberDeclaration(declar);
}
} | [
"private",
"void",
"extractInstance",
"(",
"ExtractionInstance",
"instance",
")",
"{",
"PrototypeMemberDeclaration",
"first",
"=",
"instance",
".",
"declarations",
".",
"get",
"(",
"0",
")",
";",
"String",
"className",
"=",
"first",
".",
"qualifiedClassName",
";",
"if",
"(",
"pattern",
"==",
"Pattern",
".",
"USE_GLOBAL_TEMP",
")",
"{",
"// Use the temp variable to hold the prototype.",
"Node",
"classNameNode",
"=",
"NodeUtil",
".",
"newQName",
"(",
"compiler",
",",
"className",
")",
";",
"classNameNode",
".",
"putBooleanProp",
"(",
"Node",
".",
"IS_CONSTANT_NAME",
",",
"first",
".",
"constant",
")",
";",
"Node",
"stmt",
"=",
"IR",
".",
"exprResult",
"(",
"IR",
".",
"assign",
"(",
"IR",
".",
"name",
"(",
"PROTOTYPE_ALIAS",
")",
",",
"IR",
".",
"getprop",
"(",
"classNameNode",
",",
"IR",
".",
"string",
"(",
"\"prototype\"",
")",
")",
")",
")",
".",
"useSourceInfoIfMissingFromForTree",
"(",
"first",
".",
"node",
")",
";",
"instance",
".",
"parent",
".",
"addChildBefore",
"(",
"stmt",
",",
"first",
".",
"node",
")",
";",
"compiler",
".",
"reportChangeToEnclosingScope",
"(",
"stmt",
")",
";",
"}",
"else",
"if",
"(",
"pattern",
"==",
"Pattern",
".",
"USE_IIFE",
")",
"{",
"Node",
"block",
"=",
"IR",
".",
"block",
"(",
")",
";",
"Node",
"func",
"=",
"IR",
".",
"function",
"(",
"IR",
".",
"name",
"(",
"\"\"",
")",
",",
"IR",
".",
"paramList",
"(",
"IR",
".",
"name",
"(",
"PROTOTYPE_ALIAS",
")",
")",
",",
"block",
")",
";",
"Node",
"call",
"=",
"IR",
".",
"call",
"(",
"func",
",",
"NodeUtil",
".",
"newQName",
"(",
"compiler",
",",
"className",
"+",
"\".prototype\"",
",",
"instance",
".",
"parent",
",",
"className",
"+",
"\".prototype\"",
")",
")",
";",
"call",
".",
"putIntProp",
"(",
"Node",
".",
"FREE_CALL",
",",
"1",
")",
";",
"Node",
"stmt",
"=",
"IR",
".",
"exprResult",
"(",
"call",
")",
";",
"stmt",
".",
"useSourceInfoIfMissingFromForTree",
"(",
"first",
".",
"node",
")",
";",
"instance",
".",
"parent",
".",
"addChildBefore",
"(",
"stmt",
",",
"first",
".",
"node",
")",
";",
"compiler",
".",
"reportChangeToEnclosingScope",
"(",
"stmt",
")",
";",
"for",
"(",
"PrototypeMemberDeclaration",
"declar",
":",
"instance",
".",
"declarations",
")",
"{",
"compiler",
".",
"reportChangeToEnclosingScope",
"(",
"declar",
".",
"node",
")",
";",
"block",
".",
"addChildToBack",
"(",
"declar",
".",
"node",
".",
"detach",
"(",
")",
")",
";",
"}",
"}",
"// Go through each member declaration and replace it with an assignment",
"// to the prototype variable.",
"for",
"(",
"PrototypeMemberDeclaration",
"declar",
":",
"instance",
".",
"declarations",
")",
"{",
"replacePrototypeMemberDeclaration",
"(",
"declar",
")",
";",
"}",
"}"
] | At a given ExtractionInstance, stores and prototype object in the temp
variable and rewrite each member declaration to assign to the temp variable
instead. | [
"At",
"a",
"given",
"ExtractionInstance",
"stores",
"and",
"prototype",
"object",
"in",
"the",
"temp",
"variable",
"and",
"rewrite",
"each",
"member",
"declaration",
"to",
"assign",
"to",
"the",
"temp",
"variable",
"instead",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/ExtractPrototypeMemberDeclarations.java#L172-L216 |
24,088 | google/closure-compiler | src/com/google/javascript/jscomp/ExtractPrototypeMemberDeclarations.java | ExtractPrototypeMemberDeclarations.replacePrototypeMemberDeclaration | private void replacePrototypeMemberDeclaration(PrototypeMemberDeclaration declar) {
// x.prototype.y = ... -> t.y = ...
Node assignment = declar.node.getFirstChild();
Node lhs = assignment.getFirstChild();
Node name = NodeUtil.newQName(
compiler,
PROTOTYPE_ALIAS + "." + declar.memberName, declar.node,
declar.memberName);
// Save the full prototype path on the left hand side of the assignment for debugging purposes.
// declar.lhs = x.prototype.y so first child of the first child is 'x'.
Node accessNode = declar.lhs.getFirstFirstChild();
String originalName = accessNode.getOriginalName();
String className = originalName != null ? originalName : "?";
name.getFirstChild().useSourceInfoFromForTree(lhs);
name.putBooleanProp(Node.IS_CONSTANT_NAME, lhs.getBooleanProp(Node.IS_CONSTANT_NAME));
name.getFirstChild().setOriginalName(className + ".prototype");
assignment.replaceChild(lhs, name);
compiler.reportChangeToEnclosingScope(name);
} | java | private void replacePrototypeMemberDeclaration(PrototypeMemberDeclaration declar) {
// x.prototype.y = ... -> t.y = ...
Node assignment = declar.node.getFirstChild();
Node lhs = assignment.getFirstChild();
Node name = NodeUtil.newQName(
compiler,
PROTOTYPE_ALIAS + "." + declar.memberName, declar.node,
declar.memberName);
// Save the full prototype path on the left hand side of the assignment for debugging purposes.
// declar.lhs = x.prototype.y so first child of the first child is 'x'.
Node accessNode = declar.lhs.getFirstFirstChild();
String originalName = accessNode.getOriginalName();
String className = originalName != null ? originalName : "?";
name.getFirstChild().useSourceInfoFromForTree(lhs);
name.putBooleanProp(Node.IS_CONSTANT_NAME, lhs.getBooleanProp(Node.IS_CONSTANT_NAME));
name.getFirstChild().setOriginalName(className + ".prototype");
assignment.replaceChild(lhs, name);
compiler.reportChangeToEnclosingScope(name);
} | [
"private",
"void",
"replacePrototypeMemberDeclaration",
"(",
"PrototypeMemberDeclaration",
"declar",
")",
"{",
"// x.prototype.y = ... -> t.y = ...",
"Node",
"assignment",
"=",
"declar",
".",
"node",
".",
"getFirstChild",
"(",
")",
";",
"Node",
"lhs",
"=",
"assignment",
".",
"getFirstChild",
"(",
")",
";",
"Node",
"name",
"=",
"NodeUtil",
".",
"newQName",
"(",
"compiler",
",",
"PROTOTYPE_ALIAS",
"+",
"\".\"",
"+",
"declar",
".",
"memberName",
",",
"declar",
".",
"node",
",",
"declar",
".",
"memberName",
")",
";",
"// Save the full prototype path on the left hand side of the assignment for debugging purposes.",
"// declar.lhs = x.prototype.y so first child of the first child is 'x'.",
"Node",
"accessNode",
"=",
"declar",
".",
"lhs",
".",
"getFirstFirstChild",
"(",
")",
";",
"String",
"originalName",
"=",
"accessNode",
".",
"getOriginalName",
"(",
")",
";",
"String",
"className",
"=",
"originalName",
"!=",
"null",
"?",
"originalName",
":",
"\"?\"",
";",
"name",
".",
"getFirstChild",
"(",
")",
".",
"useSourceInfoFromForTree",
"(",
"lhs",
")",
";",
"name",
".",
"putBooleanProp",
"(",
"Node",
".",
"IS_CONSTANT_NAME",
",",
"lhs",
".",
"getBooleanProp",
"(",
"Node",
".",
"IS_CONSTANT_NAME",
")",
")",
";",
"name",
".",
"getFirstChild",
"(",
")",
".",
"setOriginalName",
"(",
"className",
"+",
"\".prototype\"",
")",
";",
"assignment",
".",
"replaceChild",
"(",
"lhs",
",",
"name",
")",
";",
"compiler",
".",
"reportChangeToEnclosingScope",
"(",
"name",
")",
";",
"}"
] | Replaces a member declaration to an assignment to the temp prototype
object. | [
"Replaces",
"a",
"member",
"declaration",
"to",
"an",
"assignment",
"to",
"the",
"temp",
"prototype",
"object",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/ExtractPrototypeMemberDeclarations.java#L222-L242 |
24,089 | google/closure-compiler | src/com/google/javascript/jscomp/VariableVisibilityAnalysis.java | VariableVisibilityAnalysis.getVariableVisibility | public VariableVisibility getVariableVisibility(Node declaringNameNode) {
Node parent = declaringNameNode.getParent();
checkArgument(parent.isVar() || parent.isFunction() || parent.isParamList());
return visibilityByDeclaringNameNode.get(declaringNameNode);
} | java | public VariableVisibility getVariableVisibility(Node declaringNameNode) {
Node parent = declaringNameNode.getParent();
checkArgument(parent.isVar() || parent.isFunction() || parent.isParamList());
return visibilityByDeclaringNameNode.get(declaringNameNode);
} | [
"public",
"VariableVisibility",
"getVariableVisibility",
"(",
"Node",
"declaringNameNode",
")",
"{",
"Node",
"parent",
"=",
"declaringNameNode",
".",
"getParent",
"(",
")",
";",
"checkArgument",
"(",
"parent",
".",
"isVar",
"(",
")",
"||",
"parent",
".",
"isFunction",
"(",
")",
"||",
"parent",
".",
"isParamList",
"(",
")",
")",
";",
"return",
"visibilityByDeclaringNameNode",
".",
"get",
"(",
"declaringNameNode",
")",
";",
"}"
] | Returns the visibility of of a variable, given that variable's declaring
name node.
The name node's parent must be one of:
<pre>
Token.VAR (for a variable declaration)
Token.FUNCTION (for a function declaration)
Token.PARAM_LIST (for a function formal parameter)
</pre>
The returned visibility will be one of:
<pre>
LOCAL_VARIABLE : the variable is a local variable used only in its
declared scope
CAPTURED_LOCAL_VARIABLE : A local variable that is used in a capturing
closure
PARAMETER_VARIABLE : the variable is a formal parameter
GLOBAL_VARIABLE : the variable is declared in the global scope
</pre>
@param declaringNameNode The name node for a declaration. | [
"Returns",
"the",
"visibility",
"of",
"of",
"a",
"variable",
"given",
"that",
"variable",
"s",
"declaring",
"name",
"node",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/VariableVisibilityAnalysis.java#L92-L98 |
24,090 | google/closure-compiler | src/com/google/javascript/jscomp/VariableVisibilityAnalysis.java | VariableVisibilityAnalysis.process | @Override
public void process(Node externs, Node root) {
ReferenceCollectingCallback callback =
new ReferenceCollectingCallback(compiler,
ReferenceCollectingCallback.DO_NOTHING_BEHAVIOR, new Es6SyntacticScopeCreator(compiler));
callback.process(root);
for (Var variable : callback.getAllSymbols()) {
ReferenceCollection referenceCollection =
callback.getReferences(variable);
VariableVisibility visibility;
if (variableIsParameter(variable)) {
visibility = VariableVisibility.PARAMETER;
} else if (variable.isLocal()) {
if (referenceCollection.isEscaped()) {
visibility = VariableVisibility.CAPTURED_LOCAL;
} else {
visibility = VariableVisibility.LOCAL;
}
} else if (variable.isGlobal()) {
visibility = VariableVisibility.GLOBAL;
} else {
throw new IllegalStateException("Un-handled variable visibility for " + variable);
}
visibilityByDeclaringNameNode.put(variable.getNameNode(), visibility);
}
} | java | @Override
public void process(Node externs, Node root) {
ReferenceCollectingCallback callback =
new ReferenceCollectingCallback(compiler,
ReferenceCollectingCallback.DO_NOTHING_BEHAVIOR, new Es6SyntacticScopeCreator(compiler));
callback.process(root);
for (Var variable : callback.getAllSymbols()) {
ReferenceCollection referenceCollection =
callback.getReferences(variable);
VariableVisibility visibility;
if (variableIsParameter(variable)) {
visibility = VariableVisibility.PARAMETER;
} else if (variable.isLocal()) {
if (referenceCollection.isEscaped()) {
visibility = VariableVisibility.CAPTURED_LOCAL;
} else {
visibility = VariableVisibility.LOCAL;
}
} else if (variable.isGlobal()) {
visibility = VariableVisibility.GLOBAL;
} else {
throw new IllegalStateException("Un-handled variable visibility for " + variable);
}
visibilityByDeclaringNameNode.put(variable.getNameNode(), visibility);
}
} | [
"@",
"Override",
"public",
"void",
"process",
"(",
"Node",
"externs",
",",
"Node",
"root",
")",
"{",
"ReferenceCollectingCallback",
"callback",
"=",
"new",
"ReferenceCollectingCallback",
"(",
"compiler",
",",
"ReferenceCollectingCallback",
".",
"DO_NOTHING_BEHAVIOR",
",",
"new",
"Es6SyntacticScopeCreator",
"(",
"compiler",
")",
")",
";",
"callback",
".",
"process",
"(",
"root",
")",
";",
"for",
"(",
"Var",
"variable",
":",
"callback",
".",
"getAllSymbols",
"(",
")",
")",
"{",
"ReferenceCollection",
"referenceCollection",
"=",
"callback",
".",
"getReferences",
"(",
"variable",
")",
";",
"VariableVisibility",
"visibility",
";",
"if",
"(",
"variableIsParameter",
"(",
"variable",
")",
")",
"{",
"visibility",
"=",
"VariableVisibility",
".",
"PARAMETER",
";",
"}",
"else",
"if",
"(",
"variable",
".",
"isLocal",
"(",
")",
")",
"{",
"if",
"(",
"referenceCollection",
".",
"isEscaped",
"(",
")",
")",
"{",
"visibility",
"=",
"VariableVisibility",
".",
"CAPTURED_LOCAL",
";",
"}",
"else",
"{",
"visibility",
"=",
"VariableVisibility",
".",
"LOCAL",
";",
"}",
"}",
"else",
"if",
"(",
"variable",
".",
"isGlobal",
"(",
")",
")",
"{",
"visibility",
"=",
"VariableVisibility",
".",
"GLOBAL",
";",
"}",
"else",
"{",
"throw",
"new",
"IllegalStateException",
"(",
"\"Un-handled variable visibility for \"",
"+",
"variable",
")",
";",
"}",
"visibilityByDeclaringNameNode",
".",
"put",
"(",
"variable",
".",
"getNameNode",
"(",
")",
",",
"visibility",
")",
";",
"}",
"}"
] | Determines the visibility class for each variable in root. | [
"Determines",
"the",
"visibility",
"class",
"for",
"each",
"variable",
"in",
"root",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/VariableVisibilityAnalysis.java#L103-L133 |
24,091 | google/closure-compiler | src/com/google/javascript/jscomp/VariableVisibilityAnalysis.java | VariableVisibilityAnalysis.variableIsParameter | private static boolean variableIsParameter(Var variable) {
Node variableParent = variable.getParentNode();
return variableParent != null && variableParent.isParamList();
} | java | private static boolean variableIsParameter(Var variable) {
Node variableParent = variable.getParentNode();
return variableParent != null && variableParent.isParamList();
} | [
"private",
"static",
"boolean",
"variableIsParameter",
"(",
"Var",
"variable",
")",
"{",
"Node",
"variableParent",
"=",
"variable",
".",
"getParentNode",
"(",
")",
";",
"return",
"variableParent",
"!=",
"null",
"&&",
"variableParent",
".",
"isParamList",
"(",
")",
";",
"}"
] | Returns true if the variable is a formal parameter. | [
"Returns",
"true",
"if",
"the",
"variable",
"is",
"a",
"formal",
"parameter",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/VariableVisibilityAnalysis.java#L138-L142 |
24,092 | google/closure-compiler | src/com/google/javascript/jscomp/JSError.java | JSError.make | public static JSError make(DiagnosticType type, String... arguments) {
return new JSError(null, null, -1, -1, type, null, arguments);
} | java | public static JSError make(DiagnosticType type, String... arguments) {
return new JSError(null, null, -1, -1, type, null, arguments);
} | [
"public",
"static",
"JSError",
"make",
"(",
"DiagnosticType",
"type",
",",
"String",
"...",
"arguments",
")",
"{",
"return",
"new",
"JSError",
"(",
"null",
",",
"null",
",",
"-",
"1",
",",
"-",
"1",
",",
"type",
",",
"null",
",",
"arguments",
")",
";",
"}"
] | Creates a JSError with no source information
@param type The DiagnosticType
@param arguments Arguments to be incorporated into the message | [
"Creates",
"a",
"JSError",
"with",
"no",
"source",
"information"
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/JSError.java#L68-L70 |
24,093 | google/closure-compiler | src/com/google/javascript/jscomp/JSError.java | JSError.make | public static JSError make(CheckLevel level, DiagnosticType type, String... arguments) {
return new JSError(null, null, -1, -1, type, level, arguments);
} | java | public static JSError make(CheckLevel level, DiagnosticType type, String... arguments) {
return new JSError(null, null, -1, -1, type, level, arguments);
} | [
"public",
"static",
"JSError",
"make",
"(",
"CheckLevel",
"level",
",",
"DiagnosticType",
"type",
",",
"String",
"...",
"arguments",
")",
"{",
"return",
"new",
"JSError",
"(",
"null",
",",
"null",
",",
"-",
"1",
",",
"-",
"1",
",",
"type",
",",
"level",
",",
"arguments",
")",
";",
"}"
] | Creates a JSError with no source information and a non-default level.
@param level
@param type The DiagnosticType
@param arguments Arguments to be incorporated into the message | [
"Creates",
"a",
"JSError",
"with",
"no",
"source",
"information",
"and",
"a",
"non",
"-",
"default",
"level",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/JSError.java#L79-L81 |
24,094 | google/closure-compiler | src/com/google/javascript/jscomp/JSError.java | JSError.make | public static JSError make(String sourceName, int lineno, int charno,
DiagnosticType type, String... arguments) {
return new JSError(sourceName, null, lineno, charno, type, null, arguments);
} | java | public static JSError make(String sourceName, int lineno, int charno,
DiagnosticType type, String... arguments) {
return new JSError(sourceName, null, lineno, charno, type, null, arguments);
} | [
"public",
"static",
"JSError",
"make",
"(",
"String",
"sourceName",
",",
"int",
"lineno",
",",
"int",
"charno",
",",
"DiagnosticType",
"type",
",",
"String",
"...",
"arguments",
")",
"{",
"return",
"new",
"JSError",
"(",
"sourceName",
",",
"null",
",",
"lineno",
",",
"charno",
",",
"type",
",",
"null",
",",
"arguments",
")",
";",
"}"
] | Creates a JSError at a given source location
@param sourceName The source file name
@param lineno Line number with source file, or -1 if unknown
@param charno Column number within line, or -1 for whole line.
@param type The DiagnosticType
@param arguments Arguments to be incorporated into the message | [
"Creates",
"a",
"JSError",
"at",
"a",
"given",
"source",
"location"
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/JSError.java#L92-L95 |
24,095 | google/closure-compiler | src/com/google/javascript/jscomp/JSError.java | JSError.make | public static JSError make(Node n, DiagnosticType type, String... arguments) {
return new JSError(n.getSourceFileName(), n, type, arguments);
} | java | public static JSError make(Node n, DiagnosticType type, String... arguments) {
return new JSError(n.getSourceFileName(), n, type, arguments);
} | [
"public",
"static",
"JSError",
"make",
"(",
"Node",
"n",
",",
"DiagnosticType",
"type",
",",
"String",
"...",
"arguments",
")",
"{",
"return",
"new",
"JSError",
"(",
"n",
".",
"getSourceFileName",
"(",
")",
",",
"n",
",",
"type",
",",
"arguments",
")",
";",
"}"
] | Creates a JSError from a file and Node position.
@param n Determines the line and char position and source file name
@param type The DiagnosticType
@param arguments Arguments to be incorporated into the message | [
"Creates",
"a",
"JSError",
"from",
"a",
"file",
"and",
"Node",
"position",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/JSError.java#L119-L121 |
24,096 | google/closure-compiler | src/com/google/javascript/jscomp/JSError.java | JSError.format | public String format(CheckLevel level, MessageFormatter formatter) {
switch (level) {
case ERROR:
return formatter.formatError(this);
case WARNING:
return formatter.formatWarning(this);
default:
return null;
}
} | java | public String format(CheckLevel level, MessageFormatter formatter) {
switch (level) {
case ERROR:
return formatter.formatError(this);
case WARNING:
return formatter.formatWarning(this);
default:
return null;
}
} | [
"public",
"String",
"format",
"(",
"CheckLevel",
"level",
",",
"MessageFormatter",
"formatter",
")",
"{",
"switch",
"(",
"level",
")",
"{",
"case",
"ERROR",
":",
"return",
"formatter",
".",
"formatError",
"(",
"this",
")",
";",
"case",
"WARNING",
":",
"return",
"formatter",
".",
"formatWarning",
"(",
"this",
")",
";",
"default",
":",
"return",
"null",
";",
"}",
"}"
] | Format a message at the given level.
@return the formatted message or {@code null} | [
"Format",
"a",
"message",
"at",
"the",
"given",
"level",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/JSError.java#L170-L181 |
24,097 | google/closure-compiler | src/com/google/javascript/jscomp/deps/ModuleNames.java | ModuleNames.escapePath | static String escapePath(String input) {
// Handle special characters
String encodedInput = input.replace(':', '-')
.replace('\\', '/')
.replace(" ", "%20")
.replace("[", "%5B")
.replace("]", "%5D")
.replace("<", "%3C")
.replace(">", "%3E");
return canonicalizePath(encodedInput);
} | java | static String escapePath(String input) {
// Handle special characters
String encodedInput = input.replace(':', '-')
.replace('\\', '/')
.replace(" ", "%20")
.replace("[", "%5B")
.replace("]", "%5D")
.replace("<", "%3C")
.replace(">", "%3E");
return canonicalizePath(encodedInput);
} | [
"static",
"String",
"escapePath",
"(",
"String",
"input",
")",
"{",
"// Handle special characters",
"String",
"encodedInput",
"=",
"input",
".",
"replace",
"(",
"'",
"'",
",",
"'",
"'",
")",
".",
"replace",
"(",
"'",
"'",
",",
"'",
"'",
")",
".",
"replace",
"(",
"\" \"",
",",
"\"%20\"",
")",
".",
"replace",
"(",
"\"[\"",
",",
"\"%5B\"",
")",
".",
"replace",
"(",
"\"]\"",
",",
"\"%5D\"",
")",
".",
"replace",
"(",
"\"<\"",
",",
"\"%3C\"",
")",
".",
"replace",
"(",
"\">\"",
",",
"\"%3E\"",
")",
";",
"return",
"canonicalizePath",
"(",
"encodedInput",
")",
";",
"}"
] | Escapes the given input path. | [
"Escapes",
"the",
"given",
"input",
"path",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/deps/ModuleNames.java#L45-L56 |
24,098 | google/closure-compiler | src/com/google/javascript/jscomp/deps/ModuleNames.java | ModuleNames.canonicalizePath | static String canonicalizePath(String path) {
String[] parts = path.split(MODULE_SLASH);
String[] buffer = new String[parts.length];
int position = 0;
int available = 0;
boolean absolutePath = (parts.length > 1 && parts[0].isEmpty());
if (absolutePath) {
// If the path starts with "/" (so the left side, index zero, is empty), then the path will
// always remain absolute. Make the first segment unavailable to touch.
--available;
}
for (String part : parts) {
if (part.equals(".")) {
continue;
}
if (part.equals("..")) {
if (available > 0) {
// Consume the previous segment.
--position;
--available;
buffer[position] = null;
} else if (!absolutePath) {
// If this is a relative path, retain "..", as it can't be consumed on the left.
buffer[position] = part;
++position;
}
continue;
}
buffer[position] = part;
++position;
++available;
}
if (absolutePath && position == 1) {
return MODULE_SLASH; // special-case single absolute segment as joining [""] doesn't work
}
return MODULE_JOINER.join(Arrays.copyOf(buffer, position));
} | java | static String canonicalizePath(String path) {
String[] parts = path.split(MODULE_SLASH);
String[] buffer = new String[parts.length];
int position = 0;
int available = 0;
boolean absolutePath = (parts.length > 1 && parts[0].isEmpty());
if (absolutePath) {
// If the path starts with "/" (so the left side, index zero, is empty), then the path will
// always remain absolute. Make the first segment unavailable to touch.
--available;
}
for (String part : parts) {
if (part.equals(".")) {
continue;
}
if (part.equals("..")) {
if (available > 0) {
// Consume the previous segment.
--position;
--available;
buffer[position] = null;
} else if (!absolutePath) {
// If this is a relative path, retain "..", as it can't be consumed on the left.
buffer[position] = part;
++position;
}
continue;
}
buffer[position] = part;
++position;
++available;
}
if (absolutePath && position == 1) {
return MODULE_SLASH; // special-case single absolute segment as joining [""] doesn't work
}
return MODULE_JOINER.join(Arrays.copyOf(buffer, position));
} | [
"static",
"String",
"canonicalizePath",
"(",
"String",
"path",
")",
"{",
"String",
"[",
"]",
"parts",
"=",
"path",
".",
"split",
"(",
"MODULE_SLASH",
")",
";",
"String",
"[",
"]",
"buffer",
"=",
"new",
"String",
"[",
"parts",
".",
"length",
"]",
";",
"int",
"position",
"=",
"0",
";",
"int",
"available",
"=",
"0",
";",
"boolean",
"absolutePath",
"=",
"(",
"parts",
".",
"length",
">",
"1",
"&&",
"parts",
"[",
"0",
"]",
".",
"isEmpty",
"(",
")",
")",
";",
"if",
"(",
"absolutePath",
")",
"{",
"// If the path starts with \"/\" (so the left side, index zero, is empty), then the path will",
"// always remain absolute. Make the first segment unavailable to touch.",
"--",
"available",
";",
"}",
"for",
"(",
"String",
"part",
":",
"parts",
")",
"{",
"if",
"(",
"part",
".",
"equals",
"(",
"\".\"",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"part",
".",
"equals",
"(",
"\"..\"",
")",
")",
"{",
"if",
"(",
"available",
">",
"0",
")",
"{",
"// Consume the previous segment.",
"--",
"position",
";",
"--",
"available",
";",
"buffer",
"[",
"position",
"]",
"=",
"null",
";",
"}",
"else",
"if",
"(",
"!",
"absolutePath",
")",
"{",
"// If this is a relative path, retain \"..\", as it can't be consumed on the left.",
"buffer",
"[",
"position",
"]",
"=",
"part",
";",
"++",
"position",
";",
"}",
"continue",
";",
"}",
"buffer",
"[",
"position",
"]",
"=",
"part",
";",
"++",
"position",
";",
"++",
"available",
";",
"}",
"if",
"(",
"absolutePath",
"&&",
"position",
"==",
"1",
")",
"{",
"return",
"MODULE_SLASH",
";",
"// special-case single absolute segment as joining [\"\"] doesn't work",
"}",
"return",
"MODULE_JOINER",
".",
"join",
"(",
"Arrays",
".",
"copyOf",
"(",
"buffer",
",",
"position",
")",
")",
";",
"}"
] | Canonicalize a given path, removing segments containing "." and consuming segments for "..".
If no segment could be consumed for "..", retains the segment. | [
"Canonicalize",
"a",
"given",
"path",
"removing",
"segments",
"containing",
".",
"and",
"consuming",
"segments",
"for",
"..",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/deps/ModuleNames.java#L95-L136 |
24,099 | google/closure-compiler | src/com/google/javascript/rhino/jstype/FunctionType.java | FunctionType.makesStructs | public final boolean makesStructs() {
if (!hasInstanceType()) {
return false;
}
if (propAccess == PropAccess.STRUCT) {
return true;
}
FunctionType superc = getSuperClassConstructor();
if (superc != null && superc.makesStructs()) {
setStruct();
return true;
}
return false;
} | java | public final boolean makesStructs() {
if (!hasInstanceType()) {
return false;
}
if (propAccess == PropAccess.STRUCT) {
return true;
}
FunctionType superc = getSuperClassConstructor();
if (superc != null && superc.makesStructs()) {
setStruct();
return true;
}
return false;
} | [
"public",
"final",
"boolean",
"makesStructs",
"(",
")",
"{",
"if",
"(",
"!",
"hasInstanceType",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"propAccess",
"==",
"PropAccess",
".",
"STRUCT",
")",
"{",
"return",
"true",
";",
"}",
"FunctionType",
"superc",
"=",
"getSuperClassConstructor",
"(",
")",
";",
"if",
"(",
"superc",
"!=",
"null",
"&&",
"superc",
".",
"makesStructs",
"(",
")",
")",
"{",
"setStruct",
"(",
")",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | When a class B inherits from A and A is annotated as a struct, then B automatically gets the
annotation, even if B's constructor is not explicitly annotated. | [
"When",
"a",
"class",
"B",
"inherits",
"from",
"A",
"and",
"A",
"is",
"annotated",
"as",
"a",
"struct",
"then",
"B",
"automatically",
"gets",
"the",
"annotation",
"even",
"if",
"B",
"s",
"constructor",
"is",
"not",
"explicitly",
"annotated",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/rhino/jstype/FunctionType.java#L239-L252 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.